We regularly talk about how the Raspberry Pi is the perfect little computer to have around the house doing work that requires just enough computing power to keep it running. It’s not the purpose of the device, but it is just really good at it. File servers, media centres, etc – its size and flexibility make it an often surprisingly powerful tool.
And we can always go a step further. Instead of handling idle computing tasks around the house, what if we had it control the house? Through modern home automation and a bit of fancy coding, you can easily make the Raspberry Pi do a little bit more and control many aspects of your home. In this feature, we’re going to run you through not only setting up the controllable lights and thermostats and such, but also how to go about controlling them. Snarky voice interface not required.
Your smart home setup
Remote control sockets
Energy saving and green houses are a big thing right now, and you can buy power strips that will shut down every socket based on the draw from a single socket. This isn’t always accurate, though, and being able to manually control the socket is not always easy if it’s hidden away or part of a power strip. With the use of remote control sockets, you can control the power of anything from the Pi and a web interface, enabling better control and less use of device standby modes.
A classic home automation function is controlling the lights in the house depending on the time of day or how dark it is. There are many ways you can do this: the popular method right now is Wi-Fi enabled bulbs, allowing for direct control, but you can also use the remote control sockets or use strips of LEDs that can easily light a room and are much easier to manually interface with. With all of these methods separate from the automated control, you can also remotely control the lights to switch on and off as you please. It’s not a good idea to try and spook house guests, though.
Technologies like Nest are becoming extremely popular, but connected thermostats have been around for a long time – longer for those with a soldering iron. While we’re not going to be quite creating a thermostat that ‘learns’, using it for external control and monitoring is easy enough when you have the right equipment. We’ll be concentrating on the monitoring part in this tutorial, using a thermistor and a bit of calibration to figure out the temperature.
It’s surprisingly easy to get one of these home security systems set up. Using technology created for security cameras and streaming, you can create a live feed using the Raspberry Pi that can be displayed wherever you want. This can be done quite simply on the Pi using a webcam or even the Pi camera itself, and you can even try and hook it into the doorbell if you want a really cool party trick.
Build your own automated system
Remote control sockets
We are going to use a 433MHz receiver and transmitter module (these can be found for a couple of pounds on eBay – simply search for ‘433MHz’ and you’ll find what you’re looking for) connected to an Arduino to switch a pack of remote control sockets. We used a pack of four remote control sockets from Energenie (£17 on Amazon). Remote control sockets are ideal for items such as floor-standing lamps, and anything else without an on/off switch. In our expert’s case, he has an audio mixer that doesn’t have an on/off switch.
Once you have the sockets set up to work with the remote, you can use the 433MHz receiver and a simple piece of Arduino software to capture the message sent by the remote so it can be sent later using the transmitter module. The modules have very simple wiring: 5V, Ground and Data. The receiver has two pins for the data line but you only need to connect the Arduino to one of them. The beauty of sniffing remote control codes is that it can be used for anything you like that works at 433MHz – remote control garage doors or light switches are likely to use 433MHz.
LED light strips
LED light strips are great. They are very easy to find on Amazon and cost about £15 for a length of five metres with a 12V power supply and remote. They have adhesive on the back so they can be stuck to a surface. Alternatively, you can just leave it on the reel as that will still give off a lot of light.
Each LED on the strip has an individual red, green and blue colour component. These colours can be set to any brightness level between 0 and 100% using pulse width modulation. This is where the signal for each colour is a square wave that is on a certain amount of the time. For example: if the Red signal had a 50% duty cycle then it would be on for 50% of the time, resulting in reduced brightness. The strip has four connectors on it: +12, Red, Green and Blue. The colour connectors are the ground pins for each colour. When the pin for a colour is connected to ground, the circuit is completed, allowing 12V to flow through the strip and to ground. We will use a high current transistor for each colour to control the connection. Note that the ground from the Arudino and power supply should be connected together on the breadboard. The 12V supply for the LEDs should not connect to the Arduino – only to the LED strip – or the Arduino will get damaged.
We used a TIP120 NPN transistor, which is capable of switching 5 amps – this is plenty for our application (the power supply that comes with the strip only supplies 2.5 amps, and we can switch 15 amps because there is a 5 amp transistor for each colour). This transistor would also be good for controlling the speed of a fan or other kinds of motors.
The pins of the TIP120 are Base, Collector and Emitter, from left to right. The base is connected to the PWM signal from the Arduino via a 220-ohm resistor. The collector is connected to one of the colour pins of the LED strip, and the emitter is connected to ground. Note that when passing high amounts of current, these chips get hot. Also, it is wise to use solid core wire from the emitter-to-ground and collector-to-LED strip wires because they can safely handle more current than breadboard jumper wires. You need to ensure that none of the wires connected to the strip can short, otherwise you could damage the LEDs in the strip. Our setup here is only temporary – it could be worth moving the circuit onto veroboard so that it is more stable once you have tested that it works on a breadboard.
The TMP36 is a very simple IC. It has three pins: 5V supply, ground and a voltage out from 0-2V to represent temperature. This variable voltage can be read with the analogue in pins of an Arduino. The formula is: Temp in °C = [(Vout in mV) – 500] / 10, so a voltage of 0.7V would be 20°C.
You can either use a USB webcam or Raspberry Pi camera for the video stream. The Raspberry Pi camera should be connected with the blue plastic facing the Ethernet connector, and the exposed traces of the ribbon cable facing towards the HDMI connector.