Facebook Twitter Pin It Reddit

DIY: Introduction to Alarms

Jameco Builds logo By Ryan Winters
Jameco Product Manager

Description: Introduction to Alarms
Skill Level: Intermediate
Assembly Time: 1 hour

Alarm Sensors are in everything from cars and phones to coffee pots and handheld games, but if they're not watching your windows and doors, how do you know if your things are safe? You could pay $100 a month or more for a home security service. Granted, they can provide critical response services like police or fire in an emergency, but perhaps you don't want the additional service or bill. Maybe you do subscribe to a service, but you want to experiment with a few detection methods of your own.

This introduction to alarms covers magnetic proximity sensors (Hall Effect), laser break-beam sensing and touch sensing. The status of the alarm will be output to a sweet RGB backlit 2x20 LCD display.

All of these sensors are going to be mounted on a breadboard to keep things simple, but these can be mounted in actual locations you want to monitor – although you'll probably need a ton of wire to connect everything.

Click here to buy DIY alarm kit

Qty.
Part Description Manufacturer Part Number
1
Arduino Uno R3, DIP version A000066
1
830 Point Breadboard, 6.5" x 2.125" WBU-202-R
10
Transistor, PN2222A, NPN PN2222A
1
Force Sensing Resistor, 0.5" circle 1696
1
Laser Pointer Pen, red 4012
1
Photocell, 90mW, 150VPK, 16KΩ CDS001-8003
10
Radial Capacitor, 1µF, 50V R1/50
10
10kΩ Resistor, 1/4 watt CF1/4W103JRC
10
1kΩ Resistor, 1/4 watt CF1/4W102JRC
10
120Ω Resistor, 1/4 watt CF1/4W121JRC
1
20 x 2 LCD Display, RGB Backlight, I2C NHD-C0220BIZ-FS(RGB)-FBW
1
Wire Jumper Kit, 22 AWG, 70 pcs WJW-70B-5
1
USB Cable, A to B, 6', Black 10U2-02206-BK-R

The magnetic proximity sensor is a two piece switch where each piece is a particular pole of a magnet. The contacts can be either normally open and closed in the presence of a magnetic field, or normally closed and open when a magnetic field is present. The sample code for the magnetic sensor will allow you to use the serial monitor in the Arduino IDE to view the state of the sensor when the magnetic field is applied and removed. The Arduino will display a high or low and will be the deciding logic used in the alarm program later.

Magnetic Sensor and Loose Magnet
Magnetic Sensor and Loose Magnet

Laser Diode Module
Laser Diode Module

A laser break-beam sensor is something you've probably encountered at a convenience store or seen in a movie protecting a bank vault from multiple angles. In this example, a laser diode module provides the laser beam and a CdS photocell will measure the brightness of the laser. Because the photocell can be influenced by ambient light, a small piece of paper rolled into a tube can serve to allow only light from the laser to enter the sensor.

In a practical application, a hole can be drilled into a door frame to bury the photocell and try to isolate the stray light. The sample code will display the analog reading of the photocell. You can use the serial monitor to see how the value changes when the beam is blocked versus not being blocked. The change from a higher to lower reading can be the trigger for the alarm.

Touch sensing is accomplished with a force sensitive resistor. These polymer thick film devices exhibit a decrease in resistance when an increase in force is applied to the surface. Because the sensor reacts to forces applied, it can be placed under a panel to detect a pressure change.

Laser Beam Shining on to CdS PhotocellLaser Beam Shining on to CdS Photocell

Force Sensing Resistor; Touch SensorForce Sensing Resistor; "Touch Sensor"

Another way it could be used is to monitor the presence of an object. If you know the value measured when a known object is resting on the sensor, if the object is moved or removed, the alarm can react to the change in force applied. The sample code provided will display the reading to the serial monitor so you can decide how you want the sensor to react in the alarm application.

Follow the diagrams and notes below for wiring the sensors to the breadboard and connecting the Arduino. (A larger file called Schematic can be found on the product page.) Luckily, everything can run from the five volts supplied from the Arduino. If you are powering the Arduino with the USB cable, you can tap 5V to the breadboard via the VIN pin. If you are using a 9V wall adapter, tap power from the 5V pin.

LCD Display with RGB BacklightForce LCD Display with RGB Backlight

The schematic diagram below is representative of the included 2x20 display. There are eight pins at the bottom of the display for data connection and four pins at the side for the RGB LED backlight. When looking down at the top side of the display, the pin assignment from left to right is pin 8 to pin 1. A green backlight will indicate a safe condition while a red backlight will indicate a fault has been detected at one of the sensors. Be sure to use the 3.3V supply for the display at pin 5. The 2mm pin spacing on the display is not breadboard friendly. Use mini clip test leads or solder some solid jumper wire to the pins to complete the connections.

You can use the same 3.3V supply to power the common anode of the backlight. Green and blue operate at 3.3V, but red will use a 120Ω current limiting resistor because the forward voltage requirement for red is 2.2V. The two PN2222 transistors will switch the red and green backlights on or off independently. The backlight is shown as a single RGB LED on the schematic layout. For it to function properly, you will also need the library for the display. You can find it in the additional files archive or in a link on the product page for the display.

Image layout created with FritzingImage layout created with Fritzing

After you have run the sample codes for each sensor and determined the value you want to trigger the alarm, you will need to input those values into the primary test condition. There is an IF statement in the main loop that checks all sensors and gives the "all clear." If one test fails, individual routines are run that will report the triggered sensor. You may need to modify the equations that test the conditions to get the desired operation. The messages can also be modified, but you're limited to 20 characters per line.

The main program - called sensor Sample - is configured to give the all clear message when all three sensors satisfy the following conditions: 1) the magnet is in proximity of the sensor, 2) the CdS photocell is receiving an unobstructed beam from the laser and 3) the touch sensor has no force applied. As long as these conditions are true, the LCD will glow green and output the message "All Clear," as well as output the ambient temperature of the display. If one sensor is tripped, the LCD backlight will immediately change to red and also display the current fault.

Message Displayed for Laser SensorMessage Displayed for
Laser Sensor

Message Displayed for Touch SensorMessage Displayed for
Touch Sensor

Message Displayed for Magnetic Proximity SensorMessage Displayed for Magnetic Proximity Sensor

This covers the basic operation, but you may want to add additional outputs like a buzzer or alarm. Other useful features could be adding a delay between the readings when two sensors are triggered at the same time. Another useful idea would be for the alarm to continue sounding until a button or code was pressed to reset the alarm back to a clear condition. There are many more ways this alarm system can be expanded with the addition of more sensors or by adding Ethernet or WiFi modules to enable remote monitoring or notification. Years ago, I never would have imagined that building a home alarm system could be so DIY friendly.

Try building one and protect your prized possessions. What do you have to lose?

Ryan Winters is a Product Manager at Jameco Electronics and a Bay Area native. He is mostly self-taught and his hobbies include working on cars and computers, fiddling with electronic gadgets and experimenting with robotics.