Posted on

#20: The $6 universal home automation button

The “Flic” Bluetooth button inspired me to create something similar for my home automation system. But instead of using BLE, I just connected a $6 remote control and matching receiver module to an Arduino-compatible board, so that whenever I press the button it publishes to MQTT.

That’s incredibly handy, because it means you can just stick a button anywhere you like and have it trigger arbitrary events in your home automation system. Make it turn off every light in the house, or order you a pizza, or whatever you like.

In this project, I combined it with the ambient tile display that I showed back in Episode #14 so that I would never forget to take out the rubbish bins.

Each week, the home automation system turns on one of the LEDs so that it reminds me to take out one of the bins. A red LED says it’s time to take out the bin with the red lid, and a blue LED means the bin with the blue lid.

Then, when I take out the bin, I just push the button attached to the bin and it tells the home automation system that I’ve done my job. The notification is cleared until next week, when it comes on again.

Posted on

#19: Husqvarna Automower basics

Why mow the lawn yourself, when you can have a robot do it for you?

Husqvarna have very kindly supplied me with an Automower 320, which is a mid-range robot lawnmower that’s suitable to mid to large size suburban gardens.

Normally I like to focus on low-cost, DIY home automation projects, but this is just too good to pass up! In this episode I explain how the Automower works, how it’s different to a traditional manual mower, and (most importantly!) how my pets react to it.

In future episodes I’m going to try some creative things with the Automower. I can’t go totally crazy because the mower is supplied by Husqvarna as part of a pilot program and I’m not allowed to open it or modify it (yet!) but there are still some fun things we can do without voiding the warranty or having it repossessed.

The Automower range is listed on the Australian Husqvarna site:

Disclosure: Husqvarna provided me with this mower as part of the Test Pilot program.

Posted on

#18: Installing the ANNKE 4-channel CCTV system

Over the years I’ve slowly added individual IP cameras, both inside and outside the house. However, I’ve run into limitations such as how to store footage from the cameras for security purposes, and how to display multiple cameras simultaneously. I’ve used workarounds for these problems but it’s time to try out a proper camera system, rather than a collection of separate cameras.

I installed an ANNKE system a DVR and cameras to replace 4 of my existing IP cameras, to test how well it works. I also installed long video cables and a wireless mouse so I could mount the DVR inside my ceiling and display the camera feed on a couple of LCD TVs, and tested BNC-to-UTP adapters to run Cat-5 cable to a distant camera.

Unfortunately I discovered that the DVR requires Windows for network access, because it relies on a plug-in that doesn’t work on Mac or Linux. That means I had to run long video cables to the TVs that I use to display the live feed from the cameras. The end result is great, but it’s not how I intended to set it up.

This is the particular ANNKE 4-camera system that I installed, which is the Australian version:

This is the US version of the system:

There are a bunch of other packages as well. The AUD price seems to vary: I think it’s generated by converting from USD at whatever the daily exchange rate is, so it’s different now to when I got mine.

Posted on

#17: Home automation control with Sonoff, Arduino, OpenHAB, and MQTT

The Sonoff from Itead Studio is a fantastic little mains-switching module with a built-in ESP8266 and WiFi. If you want an easy way to control mains devices such as lamps and fans, this could be it!

Sonoff modules are preloaded with firmware that allows them to be controlled by a phone app, so they’re very easy to get started. But that’s just the beginning: using a USB-serial converter and the Arduino IDE, you can load your own software on the Sonoff and make it do your bidding. I used the Arduino IDE to load a sketch with MQTT support and OTA (over the air) updates, allowing it to be controlled by OpenHAB.

Sonoff: (basic version)

Sonoff TH: (Temperature / Humidity version)

Slampher: (lamp holder version)

Start by adding ESP8266 support to the Arduino IDE by following the instructions at I used the simple “Boards Manager” method.

For OTA (over the air) update support you’ll also need to install Python 2.7.

You’ll also need a USB-serial converter with support for 3.3V I/O. I used the Freetronics USB-Serial Converter (of course!), which has a switch that lets you select 3.3V or 5V mode.

The “BasicOTABlink” example shown in the video can be found at

The “BasicOTARelay” example shown in the video can be found at

For more information, a fantastic resource is Pete Scargill’s blog post about Slampher and Sonoff.

If you want to upgrade the FLASH memory on your Sonoff, check out Pete Scargill’s blog post about upgrading ESP8266 memory.

Update 24 Sep 2016: fixed the example links.

Posted on

#16: Compiling Arduino sketches with Pocket C.H.I.P.

Do you ever find yourself inside your ceiling or under the floor working on your home automation system, and need to SSH to a remote machine or re-flash an Arduino?

Sure, you could drag your laptop under there with you, but I don’t want to have my expensive laptop lying around in the dirt or insulation.

I may have found the answer.

C.H.I.P. and Pocket C.H.I.P. will be available soon from

I used “arduino-mk” running on the Pocket C.H.I.P to compile and upload an Arduino sketch:

The following sequence got everything working for me. You may want to do things a little differently, for example by managing the python-serial extension using Pip or storing your sketches in a different location. That’s totally up to you, just make sure you alter the paths shown below as necessary.

Start by making sure your package list is up to date, and that you have the latest packaged Arduino and Python serial extension installed on your C.H.I.P.:

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install python-serial arduino arduino-mk

Create a directory inside your home directory to keep all your Arduino sketches organised:

mkdir ~/sketchbook

Now go into your sketchbook and copy an example project out of arduino-mk, so that it includes the example Makefile:

cd ~/sketchbook
cp -a /usr/share/doc/arduino-mk/examples/Blink .

Note the space and the dot at the end of that line!

Now go into the Blink project and see what files it contains:

cd Blink
ls -l

You’ll see that there’s both the sketch itself and a Make file:

-rw-r--r-- 1 chip chip 509 Jul 12 2014 Blink.ino
-rw-r--r-- 1 chip chip 61 Jul 12 2014 Makefile

There’s nothing unusual about the Blink sketch. It’s just standard Arduino code that you could compile with the regular IDE. The magic is invoked through the Make file.

Open the Make file in your favorite text editor, and you’ll see that it looks like this:

include ../../

The “BOARD_TAG” value specifies that you want to compile it for an Uno or compatible board. You can change this to match other boards found in the Arduino board hardware definition file, which is located at /usr/share/arduino/hardware/arduino/boards.txt. In that file you’ll find other handy board types that I’ll list at the end. For now, we’ll assume that you’re using an Uno and leave that unchanged.

The “ARDUINO_LIBS” value allows you to specify a path to your own custom libraries in case you need them linked during compilation. We’ll ignore that for now, so leave that line unchanged.

The “include” line is a problem. It assumes the project is still located in the shared location where it was installed by the package, but we’ve made a copy in our local sketchbook. To fix that, change the “include” line to read:

include /usr/share/arduino/

There are many other options you can add to the Make file to override the default settings within Arduino. For example, you can define the path to a specific version of AVRDUDE if you want to bypass the version that’s bundled with the Arduino environment.

But for a minimal example, you don’t need to change anything else.

Now you can compile the sketch, and upload it to your Arduino. To compile the sketch without attempting to upload it, just type:


That’s it! Can’t be much simpler. If there are any compilation errors, you’ll see them in the terminal.

To upload (and automatically compile if necessary) make sure your Arduino is plugged into your Pocket C.H.I.P. using a USB cable, and type:

make upload

You’re all done! Your sketch should now have been uploaded to your Arduino.

There are other commands available as well. Check out the Arduino-MK documentation for more information:

Alternative board types

These are all the board tags list in the standard /usr/share/arduino/hardware/arduino/boards.txt file:

uno: Arduino Uno
atmega328: Arduino Duemilanove w/ ATmega328
diecimila: Arduino Diecimila or Duemilanove w/ ATmega168
nano328: Arduino Nano w/ ATmega328
nano: Arduino Nano w/ ATmega168
mega2560: Arduino Mega 2560 or Mega ADK
mega: Arduino Mega (ATmega1280)
leonardo: Arduino Leonardo
esplora: Arduino Esplora
micro: Arduino Micro
mini328: Arduino Mini w/ ATmega328
mini: Arduino Mini w/ ATmega168
ethernet: Arduino Ethernet
fio: Arduino Fio
bt328: Arduino BT w/ ATmega328
bt: Arduino BT w/ ATmega168
LilyPadUSB: LilyPad Arduino USB
lilypad328: LilyPad Arduino w/ ATmega328
lilypad: LilyPad Arduino w/ ATmega168
pro5v328: Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
pro5v: Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168
pro328: Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328
pro: Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168
atmega168: Arduino NG or older w/ ATmega168
atmega8: Arduino NG or older w/ ATmega8
robotControl: Arduino Robot Control
robotMotor: Arduino Robot Motor

You can also use custom board profiles, but that’s beyond the scope of this post! Most common Arduino compatible boards match something on this list. For example, the Freetronics EtherMega operates just like an Arduino Mega with a 2560 processor, so you’d select “mega2560” as the BOARD_TAG in the Make file.

Update 6 Jan 2017: Quick Setup Script

My friend Alec has written a script to simplify the process of installing the packages I used in the video and also to fix a few things he doesn’t like about the default setup. His script installs the necessary packages, blocks root access to the terminal and SSH, locks the root account, changes the default password, changes the hostname, and forces public key authentication via SSH. Definitely worth a look:

Posted on

#15: Watchdog timers for Arduino home automation

A watchdog timer helps keep your embedded devices running, by making sure they are responding properly and automatically hitting reset or cycling the power if they die. I’ve added a simple hardware watchdog timer to an Arduino compatible board running inside my ceiling, where it’s difficult to access if I need to reset it manually.

View directly on YouTube:

Links for this episode:

Posted on

#14: Ambient tile using Arduino, ESP8266, and NeoPixel compatible LEDs

Ambient information displays allow a home automation system to provide you with subtle feedback embedded within your environment. Concealing RGB LEDs behind a wall tile allows them to display status information when they are turned on, but still be totally invisible when turned off.

View directly on YouTube:

Parts Required

Assemble Hardware

Because I installed the tile so many years ago, I used original Freetronics Addressable RGB LED Modules that came out before the term “NeoPixel” was invented and used the WS2801 driver IC. Newer modules use the WS2812B, which integrates the controller chip into the LED body itself.

Connect up as many LEDs as you need, and glue them in place behind the tile. It’s best to keep the controller somewhere accessible in case you need to replace or repair it, so just have the LEDs permanently fitted behind the tile. You don’t want to have to rip out tiles and then re-tile your wall just to plug in a USB cable and update the firmware!


I’ve published an example sketch that has two separate functions: firstly it subscribes to an MQTT topic and watches for messages telling it to change the colour of an LED, and secondly it reads periodically from a DHT-22 temperature and humidity sensor and publishes the readings to other MQTT topics.

You can see the example sketch at

Posted on

#13: Connecting security sensors to Arduino

Just wiring up some lights so you can control them from your phone isn’t real home automation: that’s just turning your house into a really big remote controlled toy, even if you can do it from the other side of the world. For real automation your house needs to change its behaviour based on sensor input, and security sensors are a great way to add simple inputs that allow your house to make decisions about things like turning lights on and off automatically.

In this episode I show a clever way to connect security sensors up so that intruders can’t tamper with the cables undetected.

View directly on YouTube:

Here’s an example Arduino sketch that can read End-of-Line sensors and publish the results to an MQTT server:

Posted on

#12: Building an Arduino home automation controller

Control physical devices using an Arduino based home automation controller that connects to your network and lets you switch things on and off using a web browser. This episode shows the construction sequence of a controller that combines an Arduino-compatible board, Power-over-Ethernet, and relay driver shields to create a self-contained controller that can serve up its own web interface so you can click buttons in your browser to turn devices on and off.

View directly on YouTube:

Parts Required

Assemble Hardware

As shown in the video, decide how your device will be mounted and where you want external connections such as the Ethernet cable to be located. Drill suitable holes in the case and mount your Arduino in place. It can be a good idea to use plastic screws as shown in the video to prevent any possibility of short circuits to the outside of the case.


There are many options for software to control the device. For example, you could have it subscribe to an MQTT broker (server) and update its outputs based on publications from other devices. Or you could provide a menu via the serial console to control it manually from a computer connected via USB.

For this example I’ve provided a sketch that runs as a web server via Ethernet, and serves up a web page that includes “on” and “off” buttons for each of 16 outputs. By loading the web page in your browser you can simply click the appropriate buttons to activate and deactivate devices connected to those outputs. This example uses two Relay 8 shields, but it works just fine with a single shield as well. There’s no harm having the extra buttons visible and nothing will be damaged if the Arduino tries to address outputs that don’t exist, but you can trim it down to only 8 outputs if you prefer. It can also be scaled up to 24, 32, etc outputs if required.

You can see the full source code for the sketch at There are plenty of comments in it to help explain how it works.

Posted on

#11: Processing and storing IP camera footage

Commonly available IP cameras are great if you just want something that lets you quickly view a live stream from your laptop or smartphone, but if you want to keep footage more permanently (such as for a security recording) you can do that too without too much trouble. In this episode I show you how to use an Ubuntu Linux machine on your network to run as an FTP server to accept snapshots from your cameras, process those snapshots to add timestamp watermarks on the images, and then periodically convert them into a time-lapse video to quickly see what happened over a period of time.

View directly on YouTube:

Parts Required

      • IP camera with FTP upload capability (eg: Foscam FS8918W)
      • Computer running Linux (I use Ubuntu in this demonstration)
      • ProFTPd (FTP server software)
      • Imagemagick (image processing software)
      • Mencoder (movie encoder software)

Setting Up An FTP Server

If you already have access to an FTP server you can skip this step, and go straight on to “Configuring Your IP Camera”. You can even use a third-party FTP server located off-site if you like, but my preference is to run a local server. This has a few advantages, including limiting use of the very insecure FTP to your local network, and giving you the opportunity to do some processing of the images on the server.

On Ubuntu, installing ProFTPd is as simple as opening a terminal and typing:

sudo apt-get install proftpd-basic

Ubuntu will install the FTP server and even start it for you automatically.

However, there’s one extra step you can take to increase security just a little. By default, ProFTPd does not jail users within a specific directory: that means anyone logging into your FTP server can see the whole filesystem. Let’s lock that down a bit.

Using a text editor, open the following file:


Around line 34 you’ll find the following entry:

#DefaultRoot    ~

Remove the leading crosshatch to enable that option, so the line shows:

DefaultRoot    ~

Save the file, then restart ProFTPd so it will see the changes:

sudo /etc/init.d/proftpd restart

Now users who connect by FTP will be jailed inside their home directories.

I prefer to create separate users for each camera so they all end up compartmentalised, but that’s totally up to you. If you want to create a new user for a camera, you can enter the following:

sudo adduser camera41

Of course you can substitute your own username convention to suit your requirements. In the example shown in the video I set up a user for camera 41, so I just made that the username for convenience.

Configuring Your IP Camera

Configuration options may vary depending on your particular model of camera and firmware version, but look for a section titled “FTP Service Settings” or similar.

You’ll need to enter the address of your FTP server: usually the IP address of the Linux machine if you’re running your own server, otherwise it may be the hostname if it’s set up in DNS.

You’ll also need to enter the FTP username and password you just configured a moment ago, and optionally specify a target directory name if you want uploaded images to be put into a specific location. Some cameras create the target directory automatically if they find it there, otherwise you may need to create it yourself on the server.

In the case of Foscam cameras, you can’t test the setup or configure an upload rate until you save the settings. Click the submit button, tick the “Upload image now” checkbox, and enter a sensible value for the upload interval. In my example I set the upload interval to 1 second.

Watermarking Images With Timestamp

Most cameras upload snapshot images with the filename set to something useful such as the timestamp. In the case of Foscam cameras, the filename is the camera identifier, then the timestamp, then a sequence number. That’s useful information so I like to place the filename as a watermark in the image itself.

You can process a collection of images using ImageMagick. If you don’t have it installed on your Ubuntu Linux box already, open a terminal and enter:

sudo apt-get install imagemagick

​This will give you the “convert” program which can be used to place text on images.

In a terminal, go to the directory containing uploaded images and enter:

for name in *.jpg; do convert "$name" -font courier -pointsize 20 -draw "gravity south fill black text 0,12 '$name' fill white text 1,11 '$name'" "$name"; echo $name; done

That command can all be entered as one line, although it’s wrapped here in the browser.

This is a “for” loop that will step through all the files with names matching “*.jpg”, and write the filename into them near the bottom center first in black and then in white. This helps the text stand out whether the background is light or dark.

If you open the images after running that command you should see text added to the bottom that shows the filename. Here’s one from the example shown in the video:


Converting Images To A Time-Lapse Movie

Now that you have a collection of watermarked images taken at whatever interval you configured in your camera, you can process them periodically into a time-lapse movie so you can quickly scan through what happened while the camera was recording.

There are a variety of tools for doing this, but one that’s easy to use is mencoder. If you don’t have it installed, open a terminal on your Ubuntu Linux machine and type:

sudo apt-get install mencoder

​Now you can go into the directory containing the watermarked images are run the following command:

mencoder mf://*.jpg -mf w=640:h=480:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

Once again that’s all one line.

This tells mencoder to operate on multi-file (mf) input, that it’s processing images of type JPG at 640×480, setting the output video codec (ovc) to libavcodec, setting mpeg4 compression, and writing the output file to “output.avi”.

Here’s the example video I created for the demo:

Wrapping It All Up

Of course you probably don’t want to run those commands manually all the time, so you could combine them into a shell script and execute it periodically using cron. You’ll probably also want to include a sequence number or (better still) timestamp in the name of the output file, so that you can come back later and easily see what period is covered by each movie.