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.
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.
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.
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:
Remove the leading crosshatch to enable that option, so the line shows:
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:
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.
In 2007 there was a lot of argument about putting RFID tags into Australian passports, and many people were saying we were destined for a future where everyone was implanted with RFID so they could be tracked by the government and large corporations. I wanted to understand the technology and the risks involved, so I did the only logical thing: I implanted an RFID chip in myself!
I’ve shown use of my implanted RFID chip in previous SuperHouseTV episodes, but this is the first time I’ve shown the footage of me actually implanting the chip in myself.
Now that I’ve modified the Lockwood Nexion door lock on my workshop for Arduino control, the next step is to add an RFID reader near the door so that I can scan the RFID chip implanted in my arm to unlock the door.
Note that I deliberately did not go into any detail of the RFID implantation in this episode, so it’s safe to watch even if you don’t want to see me doing home surgery on myself! I’ll cover that in a separate episode so anyone who doesn’t want to see it can avoid it.
Door locks are one of the most useful things to control from your home automation system. Using electronic locks you can give your house central locking just like your car, control them from your phone or via the Internet, or even control them using an RFID tag or implant.
I modified a Lockwood Nexion keyless lock to allow it to be controlled by an Arduino, and linked it to my home automation system.
Electrical conduit allows you to run cables outside, underground, and in other nasty places. Sometimes though you have to get cable into places that look impossible, such as under an existing concrete path or driveway that you can’t rip up. It’s not as hard as you may think. I used a technique called “water boring” to install a conduit under a concrete footpath in just a few minutes, without having to dig up the path.
One of the little time-saving tricks I use in my home automation system is setting the Ethernet MAC address automatically on each device. This saves having to set the address manually in the sketch of every device.
I’ve written it up in a tutorial on the Freetronics site:
I’ve found that the second-hand Ethernet switches I use in my home automation system have annoyingly loud fans, so I modified them to run the fans more slowly and connect to my Arduino-based environmental monitoring system.