[EDIT] I created a forum to collaborate on gateway code.
A few years ago, I became a dog owner for the first time. I didn’t like leaving Cody in the kennel alone all day. I had a webcam on him, but I couldn’t watch it all day long. What if he was in some kind of distress? What if there was a emergency at the house, like a fire?
I wanted some way of getting an immediate email notification when he barks, or when something bad happens. So reading lead to tinkering, and tinkering eventually lead to making this full blown home automation system based on open source hardware (Arduino) and open source software (OpenHAB). I know I know, yet another “Arduino Home Automation” project, right? But I promise I’m not going to turn on a light from a smart phone. I’m more focused on extensive networked sensors, timely alerts, and aesthetically appealing presentation of events.
Here’s the basic idea. With Arduino, it’s really easy to connect boatloads of cheap sensors. Using this setup, that boatload of cheap sensors can now be on the internets. They can email you when things get too hot, too cold, too smokie, too gassy, or too bright. And your dog can email you by barking. You can also view the status of sensors on your smart phone. These sensor nodes are wireless, so you’re not constrained by the location of ethernet ports.
Here’s how it’s put together.
This Instructable will be a tutorial for how to build a variety of long range wireless sensors, and how to integrate these sensors into a sophisticated open source home automation server. Aside from looking at a mobile app to see what’s happening, you’ll also receive timely email and audio notifications. This is a long Instructable, but you can jump to the sensor you’re interested in building.
These elements are the focus of the design:
- Low Cost. Each sensor node costs less than $20 to make, so you can inexpensively scale up.
- Flexibility. Arduino based nodes allow anyone to extend the system to their particular sensing needs. You’re not tied to only the examples I’m providing, even though I strive to provide many examples.
- Very good reliability, up-time, and wireless sensor range.
- I’m providing both a battery powered and wall-power sensor node design
So, here’s the list of sensors in this Instructable. I want to provide a home with the full range of human senses. Your home should be smart and sensitive.
Dog Bark (Any Loud Noise) Sensor
Get email notifications of loud noise. I use it to get an email if my dog barks in the kennel, so that I can open up my kennel webcam and see why he barked. There is also a counter to try to quantify how much he has been barking.
Get an audio reminder when washer/dryer cycle completes – something like a “Washer Complete” announcement in the living room. No more forgetting laundry in the washer or wondering if it’s done yet. Use the smart phone app to check if the cycle is complete or if the load has been picked up.
Detect whether the light got left on or not. Displays the status of light on the smart phone app.
Area Intrusion Monitor
A PIR sensor monitors a room and sets off audio alarm / email notification when it senses a moving body.
Get notified if your dog runs away, track he’s GPS location on google maps, and also map where he poops.
Although this should not be the primary fire alarm, it can be used to send an email notification to you when the sensor senses smoke, fire, or LP gas commonly used in gas-powered stoves.
Temperature / Humidity Sensor
Temperature and humidity is reported to the mobile app. Optionally, you can enable email notifications when temperature dips below/above some preset value. Helpful for detecting furnace or air conditioner failures. You can also view a historical chart of temperature data using OpenHAB.
Water Leak Sensor
Get an email notification and audio alarm when a water leak is detected.
Just kidding, I got nothing for taste. I just like that picture. A couple more sensors that don’t fit in neat categories.
Security – Door / Window / Drawer / Mailbox sensor
A battery powered reed-switch sensor that can set off an audible alarm, or send an email notification to your smart phone. Can be used to monitor doors, windows, mailboxes, or drawers. It also logs the time the event happened, as well as the remaining battery capacity on the sensor.
Garage Door Monitor
This is handy if you can’t see your garage door from the house. Use a smart phone to check whether your garage door is opened or closed. You can also set it to play an audio reminder at, say 10PM, if the garage door is still opened.
With these sensors, everything from your dog to your washer & dryer can be part of the Internet of Things in a practical and useful way.
If there is any other home sensing thing you’d like an example of, add a comment and I’ll try to get a sensor for it or use an existing sensor to fill the need. I’m trying to make a collection of sensors for most situations. It’s only in the aggregate that this system makes sense – a bunch of one-off sensors don’t really create a coherent home automation project.
Thanks for visiting my Instructable!
- 1. Basics
- 2. Parts List & Prep
- 3. Gateway Setup & OpenHAB Install
- 4. Garage Door Monitor
- 5. Reed Switch Sensor for Mailbox & Security
- 6. Uber Sensor – General Build
- 7. Uber Sensor – Presence Detection
- 8. Uber Sensor – Dog Bark / Noise Sensor
- 9. Uber Sensor – Light Sensor
- 10. Uber Sensor – Temperature & Humidity
- 11. Uber Sensor – Flame Sensor
- 12. Uber Sensor – Smoke & Gas Sensor
- 13. Laundry Room Sensor
- 14. Charts
- 15. Dog Tracker
- 16. Uber or Not?
- 17. What is Home Automation?
- 18. Conclusion
Step 1: Usage & Explaination
I’ll start off with some videos explaining how this system works and how it can be used. If this is still interesting, the rest of the steps detail how to build it. You’ll see these videos repeated on the steps for the individual sensors. The home automation and “IoT” space is so fragmented right now that there’s a lot of cynicism about whether or not the smart home can work or is actually useful. Besides showing you how the system works, the videos help lend some credibility to the project.
1. Detailed Video Explaination
2. Wireless Laundry Room Sensor
3. Wireless Garage Door Monitor
4. Wireless Uber Sensor
5. Security – Wireless Door Sensor or Mailbox Sensor
There are a lot of “Arduino Home Automation” projects out there. My project is unique for the following reasons:
- Cheap – each sensor node is less than $20, including the wireless transceiver.
- Flexible – I’m providing the design for wall-powered sensors as well as energy efficient battery powered sensors that can run for a year on 4xAA batteries.
- Best wireless solution – the RFM69HW in this project is energy efficient and has great range. Many other wireless solutions make compromises. Bluetooth is energy efficient, but poor range. Wifi has ok range, but can’t be battery powered for a year.
- Attractive and secure user interface – the OpenHAB UI is available as a mobile app (Android and iPhone), but is also accessible through any web browser. And the communication between the display device and the Raspberry Pi is done using encryption and authentication. So your home automation system stays private. It’s also pretty easy to use considering the sophistication and features.
- Controls commercial products: If you happen to have Sonos speakers, Insteon lights/plugs, or z-wave at home, you can use OpenHAB to control those devices too. OpenHAB isn’t just for this Arduino project.
- Allows you to integrate any sensor to your automation needs. Commercial home automation system might not provide the niche sensing “thing” for which you have a need, maybe because your needs are unique.
The heat map below shows the range of the RFM69HW wireless transceiver used in this project. I produced the map using a GPS module connected to an Arduino with a RFM69HW transmitting the coordinate. I walked around outside with this GPS Arduino while another Arduino sitting inside my house received the GPS coordinate every few seconds. I then mapped the GPS points. I’m able to send data 7 houses away, through many walls. Zigbee, bluetooth, Z-wave, and wifi can’t do this for just $4. The 915MHz frequency used by the RFM69 has better range and wall penetration than 2.4GHz wireless modules. This is one of the reasons I’m using it instead of the nRF24L01+ transceiver that is popular in the Arduino community.
This is an example page from the OpenHAB user interface.
This project doesn’t require hugely expensive equipment. The technical challenges are surmountable. And the results are pretty cool.
Step 2: Parts List and Initial Prep
I’ll try to point you to the cheapest versions of the components I used, so most of these links will be to good old ebay.
- [3 x] Arduino Clone with 3.3V option. $9
- [1 x] Arduino W5100 ethernet shield. $9…shop around on this one.
- [1 x] Raspberry Pi OR your own PC
- [2 x] 10k Ohm resistors
- [1 x] Prototype Shield for as many sensor nodes as you want to build [$4]
- [2 x] RFM69HW wireless transceiver [$4]
- DH11 Temperature sensor 
- Ultrasonic distance sensor [$2]
- Reed switch [$1]
- PIR presence sensor [$3]
- Flame sensor [$3]
- Sound sensor [$2]
- MQ2 gas/smoke sensor [$2]
- Photo resistor [$2]
- GPS module [$14]
- current transformer [$7]
- Magnetometer [$2]
- Servo motor [$3]
- Male-Female Dupont cables [$4]
- 22 gauge hook-up wire
Once you get the parts, you’re pretty much ready to start building. The only mandatory soldering step is for the RFM69HW transceiver. They arrive as a bare chip, and require that you solder 22-gauge hookup wire to the pads. Follow this wiring diagram to solder wires to the RFM69HW and you should get something that looks like the following series of pictures.
Step 3: Create Arduino Gateway and OpenHAB
Once you have at least two RFM69 chips soldered with wires, we need to make the wireless gateway and setup the Raspberry Pi with OpenHAB. It’s basically two Arduinos connected together using I2C. See the wiring diagram above and the instructions below. The communications path looks like this.
The wireless data is sent from the sensor node to the RFM gateway in the form of a struct. The struct data is then passed from the RFM gateway to the ethernet gateway using I2C (those two pairs of wires on pins A4 & A5). The ethernet gateway takes each individual piece of data from the structure and post it to the MQTT broker. The MQTT broker (Mosquitto) on the Raspberry Pi picks up this sensor data, and sends it to the OpenHAB program also sitting on the same Raspberry Pi.
Here’s what the gateway looks like when you’ve got 22 gauge hookup wires connecting the two Arduinos. You can see the RFM Gateway Arduino on the bottom. It has the wireless transceiver mounted on it. On the top is the Ethernet Gateway with the ethernet cable connected.
Create Arduino Gateways
- Two Arduino Uno Clones with 3.3V/5V switch set to 3.3V.
- One Wiznet 5100 ethernet shield
- One RFM69HW w/ wires soldered on
One Arduino will be designated the “RFM Gateway” and the other is the “Ethernet Gateway”. On the RFM Gateway Arduino, wire up the RFM69HW like you see in the wiring diagram at the top of this step.
RFM69HW To Arduino
- NSS to Pin 10
- MOSI to Pin 11
- MISO to Pin 12
- SCK to Pin 13
- GND to Ground
- 3.3V to the 3.3V header
- DI00 to Pin 2 (interrupt)
Plug the ethernet shield on the “Ethernet Gateway”. Hook together these two gateway Arduinos for I2C using male-male dupont cables, or just hookup wire if you have some around:
- Ground to Ground
- Analog Pin 4 to Analog Pin 4
- Analog Pin 5 to Analog Pin 5
Download the two gateway Arduino sketches above.
Prepare The Host Computer
Next, we need to install OpenHAB on the host computer. The host computer in my case is a Raspberry Pi. It’s nice to use the Pi or similar single board computer because of the low power consumption. But if you’d rather use a Windows or Apple computer, that’s fine too. OpenHAB works on all of those machines.
Follow the wiki article on the OpenHAB site to install it on a Raspberry Pi or PC/Mac.
And the final thing we need on the host computer is to install the MQTT broker called “Mosquitto”. If using Raspberry Pi running Raspbian, use apt-get like this:
sudo apt-get install mosquitto mosquitto-clients python-mosquitto
If you’re not using a Raspberry Pi as the server, download the Mosquitto install for a Windows or Mac. It’s very easy to say in a tutorial “install this”. But let’s face it, for new Linux users, there will be problems that aren’t covered in the tutorials. Just being honest here. Things like permissions (sudo), start up issues (chmod on the init.d file), or just transferring files to the Raspberry Pi (“mount” USB drive). Just don’t expect to be able to finish the installation quickly if you’re new to Linux, and be prepare to google. Feel free to ask questions in the comments, I know how frustrating Linux can be. If all else fails, there’s always the option of using the Windows version of OpenHAB and Mosquitto. The great thing about OpenHAB is that the operating system doesn’t matter – you can start on Windows and move to Linux at a later date and all the configuration files can just be moved over and it’ll work.
Once you’ve gotten this far, you can move on to creating the individual sensors. Each of the next steps of the tutorial covers a single sensor, so you can jump around to the sensor you want to build.
Step 4: Garage Door Monitor
Use this ultrasonic sensor setup to do things like tell if a garage door is closed, or if there is a car in a spot. Basically, anything you can sense with a distance sensor. The sensor is reading the distance from the sensor to the object in front of the sensor. It then sends that distance data wirelessly to the gateway and that data is processed by OpenHAB to evaluate to “open” or “closed”.
The ultrasonic distance sensors can be found on ebay for about $3 each. Hook it up according to the wiring diagram above. See youtube video for how it works.
Install it above the garage door when the door is opened. My installation looks like this.
The two files attached to this step are the Arduino sketch for the garage door monitor and the OpenHAB configuration file. The Arduino sketch includes code for a temperature/humidity as well as a light sensor, but you don’t have to use it if you don’t want to. The sketch will work without the sensor. More details on the light sensor and temperature/humidity sensor later on in the Uber sensor section.
Step 5: Battery Powered Reed Switch – Door / Window / Drawer / Mailbox Sensor
This battery-powered wireless Arduino sensor can be used in a number of ways – pretty much anywhere a magnet could be attached to a moving part. It can be used as a security sensor by enabling the audio alarming and email notification, or maybe you simply want to see the window/door status on your smart phone.
Here’s the basics of how this battery powered unit works. You can mount it under your mailbox to get notification when the mailbox gets opened.
You can also mount it on top of a door or window like this. This one has been mounted on the side door to my garage for a while.
Here’s two youtube videos that show you how this can be used for notification and security. The first one shows how to use this to be notified when a door is opened/closed. I neglected to include in the video a clip of the Raspberry Pi playing an alarm sound. But any event can be associated with a unique MP3 file, so you can play a loud audio alarm as a deterrent, just like a real burglar system.
This video was from a previous Instructable I made of a mailbox notifier. It’s here only for completeness and to show how flexible the system is.
To build this sensor, follow this stripboard wiring diagram.
(1) A blank ATMEGA328P-PU
(1) HopeRF RFM69HW 915MHz transceiver (North America) Use this 868MHz version for Europe / Asia
(1) screw terminalfor battery connection
(2) 1MOhm resistor for voltage divider and pull down resistor on reed switch
(3) 0.1uF ceramic capacitor for voltage divider , and supply capacitors
(1) 10uF tantalum capacitor(for output)
(1) Oscillator: 8MHz oscillator preferred
(2) 22pF capacitors for oscillator
(1) one LED, I used red
(1) 220 ohm resistor for current limiting LED
(1) 10k ohm pull-up resistor for reset line
(1) Reed switch
(1) strip board about 3×6 inch
(1) 28 Pin socket to mount the ATMEGA328 on
(1) AA battery box, could be 3xAA or 4xAA
If you’re new to Arduino, I recommend some research on how to make a bread-board Arduino, since this is what it is. Do a search on putting Arduino onto a bare bones ATMEGA328P-PU. Notice that the Arduino is running on the Pro/Mini 8MHz bootloader in my build. You can use either 8MHz or 16MHz, but 8MHz conforms to the Atmel specification for 3.3V operation.
The two files attached are the mailbox Arduino sketch and the OpenHAB configuration file. You’ll have to download the Arduino sketch onto the ATMega microcontroller. Follow along with the OpenHAB configuration file to make the necessary changes on the Raspberry Pi (or PC/Mac if you’re using a computer instead).
On the Raspberry Pi (or PC/Mac), place the MP3 file for the audio under the folder for any audio alert you want to play. Look for this code snippet in the configuration file.
rule "send email and talk" when Item itm_mailbox changed from OFF to ON then playSound("aolmail.mp3") sendMail("[email protected]", "subject line here" , "email body text") end
I had a hard time measuring the battery current consumption. My general use Radio Shack multimeter might not be able to measure small amounts of current very reliably. I think it consumes about 0.1mA in sleep mode. Since the microcontroller sleeps most of the time and only wakes up to transmit when the door opens or closes, I estimate a 4xAA battery pack will last 1.5 years. The one I have mounted over the side door to the garage has been there for about a month, so time will tell.
Step 6: Uber Sensor – General Build Instructions
Here’s a video demonstration of each element in the Uber Sensor. I’m not great with youtube, so please excuse the amateur effort here. Hopefully it’s enough to show you what the setup is capable of.
I combined several sensors into this wireless Uber Sensor node. This sensor is powered via USB adapter, but it communicates wirelessly to the gateway, so you can place this where ever it has access to a power outlet. And you don’t have to build the whole thing, you can pick and choose which sensors you actually want.
- Bark / Noise Sensor: Pretty sensitive when pointed in the right direction, and includes a sensitivity pot for adjustment. I’m using it to notify me if the dog barks. The system emails me when sound sensor goes off, as well as turning on an indicator on the OpenHAB display.
- Temperature / Humidity: Displays the temperature and humidity on the smart phone interface.
- PIR Presence Sensor: Used as a security sensor to email you when movement is detected.
- Smoke / Gas: Detects explosive gas (propane, methane, natural gas), as well as smoke. Sends an email notification when these are present.
- Flame Sensor: Detects a flame, and sends email notification.
- Light Sensor: For detecting if a room light is left on
This single sensor node covers about half of the home automation sensors I set out at the beginning.
The OpenHAB user interface looks like this. You use your smartphone to access the user interface, where you can enable email notifications and alarming for the sensors you want. Once the alarm is enabled, you’ll get an email the moment that sensor detects something.
Let’s say you had the dog bark alarm enabled, and your dog barks. You’ll get ONE email notification of that event, and the alarm status for “bark” will light up. You will not receive more email if your dog keeps barking. You can use your smart phone to acknowledge the alarm by hitting the “off” button next to the alarm status. It’s only if your dog barks again after this manual acknowledgment that you’ll receive an additional email notification for barking.
You can use whatever container you want for the sensor. I used a cheap food container and poked holes through it for the sensors.
The next six steps of the Instructable cover the hardware wiring of each of these sensors and some tips for using each sensor.
The two files attached above are the OpenHAB configuration file and the Arduino sketch for the Uber sensor. For the Arduino sketch, you can use the code as is even if you don’t use all the sensors. You just won’t get valid data for the sensors you don’t wire up.
Step 7: Uber Sensor – Security / Area Presence Sensor
This Arduino sensor can be used as a security sensor for detecting intrusion, or as part of the home automation system to sense when a room is occupied. The idea is to use your smart phone to enable the alarm notification when you’re out of the house. Then, if the sensor gets tripped, you’ll get an email, as well as an indicator on your OpenHAB smart phone app.
The PIR (passive infrared) sensor costs less than $3 each from everyone’s favorite online sensor store, ebay. Just do a search for PIR sensor and look for something that resembles the pictures here. Note that the sensors have a sensitivity pot and a hold-time pot. The hold time isn’t very important for our use, but you should adjust the sensitivity to something reasonable. You can set the sensor to ignore a dog in a kennel for example, but still catch an intruder. If you have a free-range dog or cat, i
t’s a bit trickier to set the sensitivity. You can use black electrical tape to cover up part of the globe if you want to narrow down the monitoring area.
Like the rest of the Uber sensors, the programming (Arduino sketch and OpenHAB config) is in Step 6.
Read more: Uber Home Automation w/ Arduino & Pi