Thoughts of a (mad) computer scientist

Monthly Archives: April 2013

I intentionally waited several weeks after the Steve Jobs patented Post-iPhone-Purchase-Euphoria™ wore off to post this.

In short, I really like the iPhone 5 and realized immediately why these devices are so popular (yeah, yeah, 5 years behind everyone else). They just work.

What I like: The speed of the device, the simplicity of the interface, iMessage (I no longer ignore group messages that used to come in as separate MMS on my Android), Facetime.

To be fair, I came from an older model Android phone and I know the platform has improved greatly since then. I carried a Droid Incredible 2 with CyanogenMod 7 installed. While not it’s not an app, CyanogenMod received the CeBIT 2013 “Best Open Source Mobile App for Inclusion and Accessibility”. It adds a lot of custom functionality that allows you to tweak the heck out of your Android phone – exactly the opposite of the iPhone. However, I’ve found that the benefits and performance of the iPhone hardware and software outweigh those things that I miss about my old Android.

What I miss: The back button – no matter what app or menu I was in, the Android back button would take me…well, back to where I was! I miss the top status bar with icons waiting to be acted upon – the iPhone requires you to pull down the top status bar for this same type of functionality, so it’s not usable “at a glance.” I miss having the centralized panel in Android to turn on/off my Wifi, airplane mode, etc. The iPhone requires you to go into settings to do these things. The Android’s default alarm clock would pop up a notification “Alarm is set 45 minutes from now.” This was helpful as an additional safeguard to make sure that you didn’t mix up AM/PM when you set the alarm – the default iPhone alarm doesn’t have that. Maybe I’m doing this wrong, but I can’t seem to “dismiss” a meeting like I could in Android. That or the meeting doesn’t reflect what I’ve already chosen in my Outlook client like Android did. It wants me to send another acceptance even though I’ve already responded to the meeting request.

All in all, I’m a satisfied iPhone 5 owner, but I’m glad I’ve tried phones on both sides of the Google/Apple chasm.

Once it was all hooked up, it was time to write the code to run the security system!

I noticed that when a door or window was opened, the analog input was typically reporting a reading of less than 1000. However, these values seemed pretty unstable and would sometimes fluctuate wildly. I’m not sure if this was due to my wiring job, the wiring inside the walls, or some kind of interference.

In an attempt to solve this, I tried hooking the shared lead from the sensors to the Arduino’s ground port. The readings seemed to be more stable – when there was no alarm condition, the analog inputs reported readings less than 20 and around 30-100 when a sensor was tripped. To be honest, I’m not exactly sure why this works, but I suspect the sensors are inducing a very small voltage in the line when they’re tripped.

My code samples the Arduino’s analog inputs once every 100 milliseconds and looks for a reading above the threshold (currently 20). If it finds a high reading, it increments a “breach” counter. Once the threshold is breached 10 times, the alarm is activated and I receive a text message. This is done via a call by the Arduino to a webpage where I’ve set up a PHP script to send the text notification. If the alarm condition disappears (i.e. the sensor reading drops back below 20), the breach count is decremented until it reaches 0. At that point, another text is sent out indicating that the alarm has been cleared. Here’s a sample of the logic (this one is for the analog input #4 which is connected to the door sensor):

Here’s the full Arduino code, as well as the PHP code that sends the proper alert. The code doesn’t yet have error checking and all the security features implemented yet, but it’s a work in progress. Enjoy!

Security sensors are usually wired with 22 gauge solid-conductor wire but the Home Depot near me didn’t have any in stock. I grabbed 50′ of Category 3 instead. Cat 3 wire is meant for phone installations, has twisted pairs, and is 24 gauge, so I figured that would be good enough to get me started and I could upgrade the wiring later.

My first test was to hook up the door sensor only and see if I could get a reading on the Arduino.

I hooked one lead of the door sensor to one of the Arduino’s analog inputs and the other lead to the board’s 5V output. The analog input produces a reading between 0 and 1023 depending on the voltage. When the door was closed, I got a reading of 1023 and, when it was opened, the reading dropped down into the 900 range. Success!

I chose to place the Arduino near my cable modem and router and plug it in to my UPS so that in the event of a power outage the security system would still work. To get all of the alarm leads over to where the Arduino would be placed, I used a breadboard and the Cat 3 cable to extend the wiring from the main security system panel. The sensors share a common wire that goes to the 5V output so that is also extended to the Arduino. Not the most elegant wiring job but I plan to make it more permanent later:

The different sensor leads go into the different analog inputs, and the Arduino’s USB port hooks to an old USB phone charger to provide power. The Ethernet cable is not shown in this picture:

I just moved into a new apartment that was pre-wired for a standard home security system. There’s a motion sensor in the living room and open-sensors on the front door and on each window. The building owner doesn’t pay for monitoring and the system was just sitting there unplugged.

After doing some quick research online, I decided that I could hook up an Arduino to the leads from the different sensors, add an Arduino Ethernet Shield, have the system monitor each sensor, and take action if there was a security breach. This is only Part 1 but I’ll go ahead and spill the beans – it worked (and still works)!

My goals for the project:

1. Have fun
2. Learn how to program the Arduino since I’ve never worked with one before
3. Spend < $100 for an end product that performs reasonably well
My first step was to learn how everything was wired up. I hooked up the power to the existing system and grabbed a multimeter. I touched the leads to the door sensor while the door was closed, and the reading was 0 volts. When I opened the door, the reading immediately jumped to ~5 volts.

This told me that my sensors were likely wired as “Normally Open” (NO) rather than “Normally Closed” (NC). This means that the circuit is open and not completed (i.e. 0 volts) unless the sensor is tripped. With an NO sensor, there are two possible reasons for the circuit to be closed: either by the door/window being opened or by someone cutting the wire.

Door sensor:

Main panel wiring:

The main panel has inputs for 6 different sensors, but it appeared that only 5 were connected. A note in the control panel showed that the installer had skipped zone #6 and put the door sensor as #7:

Removing the control panel:

I soon found out that the door sensor was wired straight to the control panel near the doorway which is then connected to the main panel:

After removing the control panel from the wall I found that the other 5 sensor inputs shared a single lead back to the negative power terminal on the control panel. The various sensor connections all terminated in the wall behind the control panel and rode a single 8-wire cable over to the main panel.