DIY Alarm System

Serial ports are very useful things. It’s too bad that they seem to be disappearing from the standard desktop PC. It’s a good thing that there are a number of vendors selling USB devices that provide an RS232 serial port interface. You would not be crazy to say “Who uses RS232 anymore?”. Well that is a good question and the answer would be not to many people. What we are going to do with a serial port today has less to do with what it was originally designed for and more to do with the associated control signals.

What follows are instructions and java code that you can use to create you own home alarm system.

Java and many other third generation languages have very useful plugins and libraries that allow programmers to access serial ports. The package for Java on Linux is called RXTX.

The package to use when programming java serial ports is called RXTXComm.jar Include:

import gnu.io.*;
To install RXTXcomm you need to copy the file “librxtxSerial.so to your jre’s amd64 directory.
cp librxtxSerial.so /apps/jdk1.6.0_26/jre/lib/amd64

Then you need to copy the jar file to the ext directory.

cp RXTXcomm.jar /apps/jdk1.6.0_26/jre/lib/ext

Note that there are different libraries for 32 bit OS’s. As well, the easiest way to add JARs to a VM is to place them in the “/jre/lib/ext” directory.

Once the files are in place you can access the java objects that allow you to monitor the serial port control leads. You will need to connect wires to the comm port to act as your alarm loops.

Purple 7 RTS --------+
                     |
Green  4 CD  -- S ---+
                     |
Blue   8 CTS -- S ---+ 
                     |
Orange 6 DTR -- S ---+
                     |
Grey   9 RI  -- S ---+

Note that pin 7 delivers +12V so devices like motion sensors and door switches can be inserted between the 12 volt feed and the other four control leads. When a switch opens and closes the java objects will be notified. You can have four alarm loops per serial port.

The following java code implements the alarm loop handler object:

JavaAlarm

This entry was posted in General and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *