Home alarm system using existing parts

I am thinking about re-fitting my home alarm system with something based off of an Arduino. I was thinking of using the keypads that are already installed, DSC-PC1500RK. I have already figured out how to interface with the keypads using code I found online, but now I need to figure out if it is possible to also monitor the sensors (6 zones, NC switches) with the same Arduino that is monitoring the keypads, or if I should have a separate Arduino for monitoring the sensors and controlling the keypads.

Also, my dad suggested to me that I use interrupts on my mega, so that it would only need a single Arduino in the project, but I have no idea how I would do that. I tried looking up interrupts on the playground, but it just confused me more.

If it is also possible, I was wanting to have the Arduino send an SMS on an alarm event using either my Raspberry Pi, Twilio, an ethernet shield or some combination of all of those.

I appreciate any help I get.

Code for the keypads:

/*
        The code is to interface a DSC PC1500RK alarm keypad.  
        It has 15 keys, 11 LEDs, and a Beeper that can be controlled.  
        This code cycles through all the LEDs in a top-down fashion.  
        The beeper is used to acknowledge that a key has been pressed.  
        If the key was pressed successfully, its character is output on the serial line, at 9600 bps.
 
        I was originally communicating at 115200, but due to the read speed, and also the tendency to
        quickly overfill the read buffer if lots of commands are sent at once, I slowed it down to 9600.
        It is still possible to overfill the buffer, but that is mainly if you sends tons of flag
        altering commands, or if you send a bunch of beep/delay commands all at once.  
        The general thing, is Hurry up and wait. :).
                (In other words, maintain a slower pace whenever possible.)
 
        The fastest that this keypad can be read out, is ~30 times a second.  I tried doing 500
        microsecond delays between clock cycles, and things started becoming unresponsive.
       
        Wiring is simple.  Red is Vcc, hooked to 12V
        Black is Gnd.
        Yellow is the Clock line. In this configuration, it is on Digital Pin 3.
        Green is Data, and is on Digital Pin 2.
       
        Beeper          0x0001
        unknown         0x0002
        unknown         0x0004
        Trouble LED     0x0008
        By-Pass LED     0x0010
        Memory LED      0x0020
        Armed LED       0x0040
        Ready LED       0x0080
        unknown         0x0100
        unknown         0x0200
        Zone 6 LED      0x0400
        Zone 5 LED      0x0800
        Zone 4 LED      0x1000
        Zone 3 LED      0x2000
        Zone 2 LED      0x4000
        Zone 1 LED      0x8000
         
        Matrix output is in the format of RCCCRRRR.
        Matrix Output   Key             Output ^ 0xFF
        11111111        -Nothing        0x00
        10111110        1               0x41
        11011110        2               0x21
        11101110        3               0x11
        10111101        4               0x42
        11011101        5               0x22
        11101101        6               0x12
        10111011        7               0x44
        11011011        8               0x24
        11101011        9               0x14
        10110111        *               0x48
        11010111        0               0x28
        11100111        #               0x18
        00111111        F               0xC0
        01011111        E               0xA0
        01101111        P               0x90
*/
 
#define CLOCKPIN 3
#define DATAPIN 2
 
#define NO_FLAGS 0x0000
#define BUZZER 0x0001
#define TROUBLE 0x0008
#define BYPASS 0x0010
#define MEMORY 0x0020
#define ARMED 0x0040
#define READY 0x0080
#define ZONE_1 0x8000
#define ZONE_2 0x4000
#define ZONE_3 0x2000
#define ZONE_4 0x1000
#define ZONE_5 0x0800
#define ZONE_6 0x0400
 
#define NO_KEY_PRESSED 0
 
 
void setup() {
  //Pin 2 is Data, and is bidirectional.
  //Pin 3 is Clock, and is an output.
  pinMode(DATAPIN, OUTPUT);
  pinMode(CLOCKPIN, OUTPUT);
  Serial.begin(9600);    //Any faster, and we run the risk of doing hurry up and wait.
}
 
int readdata(int control)
{
 
  int i,j=0,k=control;
  int bitcount=0;
 
  for(i=0;i<8;i++)
  {
    j<<=1;
    digitalWrite(DATAPIN,HIGH);
    digitalWrite(CLOCKPIN,LOW);
    delayMicroseconds(625);
    //delay(1);
    if(digitalRead(DATAPIN)==LOW)
      j|=1;
    digitalWrite(CLOCKPIN,HIGH);
    delayMicroseconds(625);
    //delay(1);
  }
  for(i=0;i<16;i++)
  {
    if(k&0x8000)
      digitalWrite(DATAPIN,HIGH);
    else
      digitalWrite(DATAPIN,LOW);
    digitalWrite(CLOCKPIN,LOW);
    delayMicroseconds(625);
    //delay(1);
    digitalWrite(CLOCKPIN,HIGH);
    delayMicroseconds(625);
    //delay(1);
    k<<=1;
  }
  if(j==0x41) return '1';
  if(j==0x42) return '4';
  if(j==0x44) return '7';
  if(j==0x48) return '*';
  if(j==0x21) return '2';
  if(j==0x22) return '5';
  if(j==0x24) return '8';
  if(j==0x28) return '0';
  if(j==0x11) return '3';
  if(j==0x12) return '6';
  if(j==0x14) return '9';
  if(j==0x18) return '#';
  if(j==0x90) return 'P';
  if(j==0xA0) return 'A';
  if(j==0xC0) return 'F';
  return 0;
}
 
void loop() {
  int i;
 
 
  static int last_key_pressed=0,key_just_pressed;
  static unsigned int flags=0x80;
  static unsigned int buzzer_counter=0;
  int breakloop=0;
 
  while(Serial.available() && (breakloop==0))
  {
    i=Serial.read();
    if((i>='1')&&(i<='6'))
      flags ^= (ZONE_1 >> (i-'1'));
     
    if((i=='r')||(i=='R'))
      flags ^= READY;
    if((i=='a')||(i=='A'))
      flags ^= ARMED;
    if((i=='m')||(i=='M'))
      flags ^= MEMORY;
    if((i=='b')||(i=='B'))
      flags ^= BYPASS;
    if((i=='t')||(i=='T'))
      flags ^= TROUBLE;
    if(i=='S')
    {
      flags |= BUZZER;
      buzzer_counter+=16;
      break;
    }
    if(i=='s')
    {
      flags |= BUZZER;
      buzzer_counter++;
      break;
    }
    if(i==' ')
      break;
  }
  if(buzzer_counter)
    buzzer_counter--;
  else
    flags &= ~BUZZER;
 
  i=readdata(flags ^ key_just_pressed);
 
 
  if(last_key_pressed==NO_KEY_PRESSED)
  {
    if(i != NO_KEY_PRESSED)
      Serial.println((char)(i));
  }
  if((last_key_pressed!=i)&&(last_key_pressed==NO_KEY_PRESSED))
    key_just_pressed=BUZZER;
  else
    key_just_pressed=NO_FLAGS;
  last_key_pressed=i;
 
  delayMicroseconds(3333);
}

Youtube video where I saw the code http://youtu.be/uVkr_SiPJ_0

Try doing it one step at a time. Is the code you posted working? First try to get the keypad working.

Next try to get the sensors working.

For sending an sms you can use a GSM shield or a module like Sim900.

How many arduinos are needed depends on the number of pins used by the sensors and keypad(s)

I don't think interrupts are used for multiplexing. they are used for immediately ruining code when a pin state changes or rises or falls. Search for Jeremy blumm's tutorial on interrupts in YouTube.

I'm interested in your project. can you post some pictures.

Ufoguy:
Try doing it one step at a time. Is the code you posted working? First try to get the keypad working.

The code that I posted for the keypad is working, and is nice, since the keypads are serial and only use 4 pins for both of the keypads combined - VCC, GND, CLK, DAT. I have the two keypads hooked together like on the original system, so that seems acceptable. Now just need to figure out if I could combine the sensor code with the keypad code, or if I should keep them on separate arudinos.

Ufoguy:
Next try to get the sensors working.

I just finished writing a starting off point for monitoring the sensors. I’m attaching the project file since the code is kinda messy (repetitive). I’ll probably clean things up into subroutines after I make sure it’s working.

Ufoguy:
For sending an sms you can use a GSM shield or a module like Sim900.

I was thinking of doing something like that, but I don’t like the price of the GSM shields. I do have some spare rs232 GSM modems from my dad’s work that are controlled using AT commands. Would be using the Twilio API be possible either? I want to try to keep everything contained, but I have used Twilio before, and they’re pretty easy and nice to use, not to mention free to some extent.

Ufoguy:
How many arduinos are needed depends on the number of pins used by the sensors and keypad(s)

I was thinking of using an Uno for the keypads, an Uno for the sensors and a Mega to control the other two. Or I could have the two Unos connected to my RasPi with i2c, and a script running on there.

Ufoguy:
I’m interested in your project. can you post some pictures.

I’ll take some pictures tomorrow for all to see.

AlarmSensors.ino (3.5 KB)

The code that I posted for the keypad is working, and is nice, since the keypads are serial and only use 4 pins for both of the keypads combined - VCC, GND, CLK, DAT. I have the two keypads hooked together like on the original system, so that seems acceptable. Now just need to figure out if I could combine the sensor code with the keypad code, or if I should keep them on separate arudinos.

Good. I think you can do it all with one arduino.

I just finished writing a starting off point for monitoring the sensors. I’m attaching the project file since the code is kinda messy (repetitive). I’ll probably clean things up into subroutines after I make sure it’s working.

From what I see in the code the sensors are simple ones which give a HIGH signal when triggred. So, it should be simple.

I was thinking of doing something like that, but I don’t like the price of the GSM shields. I do have some spare rs232 GSM modems from my dad’s work that are controlled using AT commands. Would be using the Twilio API be possible either? I want to try to keep everything contained, but I have used Twilio before, and they’re pretty easy and nice to use, not to mention free to some extent.

The price is really a con. Check to see if the RS232 modems have option for TTL serial connection, or you could get a RS232 to TTL converter to do it. I heard the mothly prices for having a GSM sim are very high in some countries (unlike mine) so, its not a surprising to know that you’re looking for an alternative. I don’t know much about Twilio but I guess you could use it :stuck_out_tongue:

I was thinking of using an Uno for the keypads, an Uno for the sensors and a Mega to control the other two. Or I could have the two Unos connected to my RasPi with i2c, and a script running on there.

I think that if you use many micro-controllers many problems will arise. If one fails or a cable gets disconnected the complete system fails. Why use so many when you can just do with one. But you somehow need to get rid of the delays in the keypad code.

I’ll take some pictures tomorrow for all to see.

Thank you.

You should be able to do all that with a Uno, or certainly a single Mega.

You seem to need 2 pins for the keypad (plus Vcc and Gnd of course) plus 6 inputs for the zones. Plenty of available inputs on a Uno (you have 20 in total).

You could use interrupts, however for a low-response application polling should be OK. If you want to read about interrupts:

http://www.gammon.com.au/interrupts

You might want to do a bit of searching about how to protect your inputs. Personally I wouldn’t connect wires that had run a long distance into my Arduino, because of possible static or other issues. Some diodes/resistors to absorb high-voltage pulses might make the whole thing last longer. See this, for example:

http://www.kevinmfodor.com/home/My-Blog/microcontrollerinputprotectiontechniques

I was thinking of using an Uno for the keypads, an Uno for the sensors and a Mega to control the other two.

Too much complexity. Just stick with one processor.

In your situation I would be looking to avoid false positives. For example a brief change to an input could just be static or something. After all a burglar isn’t going to open a window, and get in, and close it again, in a microsecond.

You could consider adding a thermal printer like this one:

https://www.sparkfun.com/products/10438

Then you could log things like when the alarm is activated/deactivated, when certain sensors trip, etc. Could be interesting. For example, if you come home and find the family jewels missing, and check the log, you might find you forgot to activate the alarm.

You could also consider adding some temperature sensors and detect fires (eg. in the roof space).

You might want to do a bit of searching about how to protect your inputs. Personally I wouldn't connect wires that had run a long distance into my Arduino, because of possible static or other issues. Some diodes/resistors to absorb high-voltage pulses might make the whole thing last longer. See this, for example:

Might this be a good application for a Schottky hex inverter/buffer (or the like)? Possibly used in series with one of the simpler suggestions from the link provided?

I would make a potential divider for each of the 6 zones, using two 470 ohm resistors, with the NC switches connected in series with one of the resistors. Apply 5V to the potential divider. Connect the junction to a 1M resistor, and connect the other end of the resistor to an Arduino analog input pin. Also connect a 1uF ceramic capacitor between the pin and ground. Then poll the analog inputs along with the keypad, looking for inputs that return below 400 or above 624 from the analogRead call.

Using the potential divider means that you can detect short circuits to ground (or Vcc) as well as switches being open. The 1M resistor in conjunction with the mcu pin protection diodes protects the mcu against excessive voltage. The capacitors suppress interference and transients, as well as overcoming crosstalk between the pins which you would otherwise get using a 1M source resistance.

Use the watchdog timer to guard against the system locking up.

I have no doubt that this can be made to work with an Arduino -and perhaps even work better than the original.

BUT ... I doubt if any insurer would give lower premiums for a home-made alarm system or would acknowledge that there had been an alarm system in use (even if it was switched on) if there was a claim for burglary.

If you just want a system that will wake you up at night when someone tries to force entry to your home - fine.

A fancy box high on an outside front wall with a small flashing led (see Blink without delay) would probably provide as much protection against real burglars - especially if your neighbour hasn't got one.

...R

A fancy box high on an outside front wall with a small flashing led (see Blink without delay) would probably provide as much protection against real burglars - especially if your neighbour hasn’t got one.

:stuck_out_tongue_closed_eyes:

http://www.kevinmfodor.com/home/My-Blog/microcontrollerinputprotectiontechniques

This was really useful.

It's no skin off my nose but ...

If you think the idea of a fancy box with a flashing light is just a joke then you are not giving as much thought to what problem you should be trying to solve as you are giving to the method for solving a problem that may not really exist.

Think about it like this ...

Do you want to prevent EVERY burglar from entering your house? Then use steel bars on the windows and steel doors and appropriate burglar proof locks. And live with the risk of being trapped inside if a fire starts.

Maybe you just want milder protection so burglars are discouraged and may only actually enter your house once every 2 or 3 years. Then the fancy box is probably enough. If the burglar sees what looks like a house with an alarm he will either go somewhere else or decide that he will be safe for 20 or 30 minutes even if the alarm goes off. In that case it doesn't matter whether the alarm system is real or fake. Most times neighbours ignore alarms (just get peed off with the noise) and the police usually assume it's a false alarm (which it usually is). If you spend money on a £5k or £20k alarm system the burglar may just leave you with a bigger repair bill.

If you would just like to help the police prosecute a burglar then install some secure video recording system that the burglar can't override (have the recording device at another location). Maybe a prominent notice saying you have that system would deter some burglars - and warn others to wear face masks.

Or... Move to a less burglar prone neighborhood. Live in a run-down house that doesn't look like it has any valuables. Contribute to local drug rehab programs. Etc etc etc.

...R

Robin2:
A fancy box high on an outside front wall with a small flashing led (see Blink without delay)

No need even for an Arduino. A 555 would do the job a whole lot cheaper.

Or he could buy a dog.

Seriously though, it sounds like a learning exercise for the Arduino. Buying dogs and 555 chips won't help there. :)

The price is really a con. Check to see if the RS232 modems have option for TTL serial connection, or you could get a RS232 to TTL converter to do it. I heard the mothly prices for having a GSM sim are very high in some countries (unlike mine) so, its not a surprising to know that you’re looking for an alternative. I don’t know much about Twilio but I guess you could use it :stuck_out_tongue:

Sim cards aren’t too expensive in Texas, just GSM devices. I found an old siemens board in my closet that supports I2c that i’m thinking of using.

You might want to do a bit of searching about how to protect your inputs. Personally I wouldn’t connect wires that had run a long distance into my Arduino, because of possible static or other issues. Some diodes/resistors to absorb high-voltage pulses might make the whole thing last longer. See this, for example:

That definitely seems like a very important topic for me to address. Would something like a ruggeduino that has built in protection work?

You could consider adding a thermal printer

That’s a great idea. I should try to work that in.

BUT … I doubt if any insurer would give lower premiums for a home-made alarm system or would acknowledge that there had been an alarm system in use (even if it was switched on) if there was a claim for burglary.

Our current alarm system isn’t monitored, and the dialer camps on the phone line so it was disconnected long ago. It’s an old DSC-PC1550 that was installed some time around '95.

If you would just like to help the police prosecute a burglar then install some secure video recording system that the burglar can’t override (have the recording device at another location). Maybe a prominent notice saying you have that system would deter some burglars - and warn others to wear face masks.

Or… Move to a less burglar prone neighborhood. Live in a run-down house that doesn’t look like it has any valuables. Contribute to local drug rehab programs. Etc etc etc.

We have security cameras that we installed not too long ago, and the sign for the alarm system and monitoring company is still out in the yard. Replacing the alarm system isn’t something that we were doing because of burglaries - we just want to upgrade the functionality of our current system to notify us if a sensor (like a window) is opened, or a door opens while we’re out.

Here are the pictures of some of the components in the alarm system, and some of the parts I was thinking of using.
Keypad.

Control Panel.

Siemens DB75 - supports I2c, USB, and rs232.

An Enfora rs232 GSM modem

Late response, sorry. Spent most of the day building a camera slider out of skate wheels, angleirons and flatstock. Turns out when you cut and weld steel with time for it to cool between, it’ll harden up and break drill bits not designed specifically for metal.

CFarrell99: That definitely seems like a very important topic for me to address. Would something like a ruggeduino that has built in protection work?

That should certainly help. The designers of that seem to have addressed most (if not all) of the common issues. In fact I think their web page is where I found the link about ways of protecting your inputs.

Quick update, I recently got my code working with the panels and it is back up to the function of the old alarm system. Now I just need to start building in functions.

Quick question though, how should I hook up the alarm wires to the Arduino? I’ve seen things like screw shields, but I want to know if theres an easier way to do it.

Alarm_6.ino (8.65 KB)

CFarrell99: Quick update, I recently got my code working with the panels and it is back up to the function of the old alarm system. Now I just need to start building in functions.

Quick question though, how should I hook up the alarm wires to the Arduino? I've seen things like screw shields, but I want to know if theres an easier way to do it.

Screw shields are your best bet as far as I know.

For the best reliability, put the microcontroller and all the other components on a PCB, and use PCB-mounting screw terminals to connect the external wiring. If you are using few components other than the Arduino, display and keypad, then a screw terminal shield is also a good solution.

Any update on this? I have the exact same system collecting dust in my house and was thinking of was to integrate it with various home automation.