Putting the "automation" in home automation with Arduino

Whether my kids or myself are to blame, it drives me crazy to see large electricity bills from cooling and heating the house when nobody’s actually in the house.

Looking for a solution to the problem and driven by “stream” technology, I decided to build my own smart home IoT system to collect and monitor temperature, humidity, and motion in my house. As a platform, I chose the Arduino Uno board, and in less than a few days, I had a running system to collect the sensor data and visualize it in realtime.

However, visualizing the data was not enough. I needed a system that would track the data, understand normal patterns, and notify me when abnormal patterns emerged. For example, if there was no motion in the room, but the A/C was left on, the temperature and humidity would drop abnormally.

To solve this problem, I built on top of my existing IoT system and implemented two additional services:

  • PubNub: a realtime data stream network to stream sensor data
  • Anodot: a smart platform to collect and automatically analyze data and alert when abnormal patterns are detected

Why Anodot and PubNub?

PubNub’s network provides a two-way data stream to my sensors (so later I can control devices in my home) and it has supported SDKs for Arduino and Node.js. PubNub also provides reliability, availability, and efficiency guarantees, so I don’t have to worry about data not being sent or received.

Anodot’s platform provides everything that I need for data visualization, analytics, and automated alerting based on its machine learning algorithms that automatically find abnormal patterns in my sensors’ data.

Here’s a block diagram of the system:

In action

The example below shows an anomaly that Anodot discovered. The temperature, motion level, humidity and barometric pressure from the living room are graphed in my Anodot dashboard.

The shaded area around each graph is the normal range Anodot’s algorithms learned. There is an anomaly in the temperature, humidity, and motion sensors happening at the same time – with the temperature in the room dropping significantly lower, while there is minimal motion in the living room. This is a clear indication of an A/C working without anyone around.

Besides being alerted on sensor data sent, Anodot also provides the ability to create new signals that are functions of existing ones. For example, the dew point can be approximated using the temperature and relative humidity: DP = T – (100-RH)/5.

The graph below shows the dew point for my living room, calculated using Anodot’s analytics. Once defined, I can get anomalies on this new signal, and all without having to add an additional sensor or writing more code.

Making it all work

For the data collection system, I chose to use the Arduino board. The Arduino includes a wide variety of sensors and content, and the whole package is very affordable. Here’s a schematic of the design:

For the base model, I used the Arduino Uno with the Ethernet shield. (Later I plan to replace it with Arduino Nano and the low cost ENC28J60 Ethernet adapter.)

To this base system, I connected the following sensors:

  • DHT11 temperature and humidity sensor
  • BMP180 for barometric pressure and temperature
  • HC-SR501 passive infrared motion sensor

I used the open-source DHT11 and Adafruit sensor libraries to read information from the BMP180 sensor and the DHT sensor.

The motion sensor is connected to an interrupt trigger that runs an attached function whenever it senses motion. This function sets a software flag to true.

As you can see in the code below, every 20 seconds the device reads the temperature, humidity, barometric pressure and the motion status flag. It packs this information into a JSON object and publishes it to my PubNub channel by using the PubNub Arduino library.

Client Side: Receiving and displaying the data

On the other side, I built two different clients that subscribe to the data channel. One is reading the information sent via PubNub and displaying it on a web UI in realtime. The other is a Node.js script that runs on Heroku, reads the information and sends it to Anodot.

Both scripts are using PubNub supplied libraries for their respective platforms (PubNub has more than 70 SDKs for every platform).

Here is the web interface:

What’s next?

Smart home systems like the one I built, which collect and automatically analyze data, is a proof of concept demonstrating that the possibilities are endless with the technology that exists today. For example, the system can alert when home electricity deviates from normal patterns compared to others in a specific area. It could help understand if A/C is (or is becoming) inefficient compared to others so maintenance and improvements can be ordered. We can monitor motion and send alerts for possible home intrusions.

Eli Mordechai is Chief Architect & Technology Evangelist Service/Network/Environment Virtualization at HP.