Wednesday, March 10, 2010

Driving Mrs. Ademco



The siren on my current security system is made by Ademco.


It needs a half an amp at 12 volts to sound 106 decibels.  This is a problem since the output on the Arduino is around 5 volts max. Since I decided to use as much of my current system as I can I need to figure out how to drive the siren with what I have.  Fortunately my current system also has a 12 Volt sealed lead acid rechargeable battery for backup.


To get these three things working together I am going to need something called a driver.  A driver is basically a switch except the switch is flipped by a small positive input current.  Drivers are used a lot for doing the same thing with motors.

My driver is actually a pretty simple circuit.  The Arduino is connected to the base of a transistor (TIP31) through a resistor (10K). The Vcc of the 12 V battery goes to the siren. The siren goes to the collector of the transistor.  The emitter of the transistor is connected to the ground of the battery and the ground on the Arduino.



The only difference between driving a motor and a siren is that I don't think that I need to worry about feedback with a siren.  With a motor, when you turn the circuit off, you sometimes get a jolt of feedback from the motor.  Simple motor drivers just bridge between the collector and emitter with a diode to give the jolt somewhere to drain to.  I haven't seen any feed back from my circuit so hopefully this isn't going to be a problem.  I probably could do it anyway, it is just a diode, but what I have works.

Another thing that I need is a charger for the battery.  The charger on my current system is built into the board of the system so I can't use it and I don't know much about building a charger so I will probably just buy one.  The place where I am getting all of my sensors, www.homesecuritystore.com, has them starting at 14 bucks and going to 130. This is a little confusing because they seem to be similar systems.  Why the difference in prices?  I am not going to worry about that until I buy the sensors.

It seems that I can also use the battery to run my Arduino when the power goes south.  I was a little worried about it being too much for the regulator on the Arduino but a guy name Mike Cook at www.thebox.myzen.co.uk did the calculations and they look right, so I am going to trust him.  This seems to be working out pretty good.

Now I need to get rid of the code to make the siren sound in my current Arduino code and replace it with a simple cause the output to go high.

Next thing to think about is a keypad and display.

Monday, March 1, 2010

Mux

So having a security system that has only 6 analog inputs is kind of a bummer.  Of course the Arduino has 15 digital inputs along with the 6 analog but the way that I wanted to do the sensors was analog.

There are a couple of things that I could do to get more inputs.

One would be to upgrade to the Arduino Mega which has 16 analog and 54 digital.  This is better than my 6 and 16 and I probably could use the digital inputs for some of the sensors.  The Mega also has a lot more memory which would be cool but really don't need it (yet).  The big problem with this solution is that the Mega is about 60 bucks.

Since I already have a Arduino I am a little hesitant to go buy another even if it is bigger and better.  Fortunately you can make a few IOs into a bunch more IOs using a multiplexer ( mux for short ).  Look at the wikipedia link to see what a mux really is but basically it allows me to scrunch a bunch of input down to one or a few.  The circuit is more complicated than just reading a value on a wire but not too much so.

I went out looking for a mux.  There aren't a lot of places you can get these ICs on the web but I was able to find them for under a couple of bucks before shipping.  Add to that shipping and then I also need a board or shield to put it on with the pin connectors and I am up to at least 15 bucks.  It seemed like a big pain.

Then I came upon the Mux Shield from Mayhew Labs.  20 bucks for a shield that turns 4 digital and 3 analog IOs into 48.  It is designed to work with the Arduino and the only assembly is soldering a few headers on.

About 4 days later I got it in the mail.  The Mayhew Labs site has some example code on their site but it is so simple to use that I just took a line or two from their stuff and ripped out something a little more compact to test the board with.  Very cool, very easy.  Now I have gone from having to worry about "how I am going to access all of the sensors that I am planning" to "what can I do with all of these IOs".  I think that I will have to play with some other home automation after I finish the security system.

The code below reads inputs 16 and 17.  These are the 0th and 1st IOs on M1 which is the middle multiplexer.  Plug a couple potentiometers into these headers.  One row of headers is ground, one is Vcc and the bottom is the one that will be read.

void setup() { 
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT); 
  
  Serial.begin(9600);
}

void loop() { 
  int val = getSensorValue(16);
  Serial.print( "16:" );
  Serial.println( val );
  val = getSensorValue(17);
  Serial.print( "17:" );
  Serial.println( val );
  delay(200);
}

int getSensorValue( int sensor ) { 
  int muxId = sensor >> 4;
  int inputId = sensor % 16;
  
  digitalWrite(5, (inputId&15)>>3); 
  digitalWrite(4, (inputId&7)>>2);  
  digitalWrite(3, (inputId&3)>>1);  
  digitalWrite(2, (inputId&1));
  
  return analogRead(muxId);
}


I don't know if this is the best code but it works great.  I will post the security system code change for the new shield next post along with the change with for the real siren. 

I had to think about how to plug the sensors into the mux shield in a more secure way.  If I just plug the wires into the header like I would when I am prototyping they will probably fall out.  I probably should have ordered the mux shield without the headers on and soldered in male headers instead of the female headers. I will have to find out if he sells them that way.  Then I found some 4 pin female connectors to put on the ends of my sensor wires.  That will probably stay pretty secure.  UPDATE:  The mux shield without headers is what I was thinking it was.  If I were starting this from the beginning I might have just bought it and then soldered on the male headers.  Maybe Mark will offer a "Production Version" of his mux shield already assembled like this.

Pics of the mux shield on the Arduino, breakaway male headers and headers in the shield with a connector plugged in to input 17 or the input 1 on M1.