Thoughts of a geek

25 May 2019

Fairy light controller

Filed under: Computers, Electronics — Tags: , , , , , — qwandor @ 12:34 pm

One of my housemates has a lot of fairy lights. Most of them were battery powered, each by a little pack of 3 AA batteries, which seemed somewhat wasteful. They are great for parties, but turning them all on and off individually is kind of a pain too, so I wanted to make them mains powered, and controlled from Google Home. And as I mentioned in a previous post, I’ve been playing with ESP8266s recently, so I built a controller based on the D1 mini board.

The first version I prototyped with a dual H-bridge board I had sitting around, using each half-H separately so it could control 4 strings of fairy lights, just twisting some wires around the battery terminals. It was a bit messy though:

First prototype, fairy light controller V1

So next I made a somewhat neater version on some stripboard, using a dual H-bridge chip I had sitting around, but with a pair of screw terminals per output rather than just a single ground connection to make it easier to use. I also added some header sockets that could be used to put a resistor in series with the output easily. This meant that rather than being quite so hacky with wires twisted around the battery terminals I could cut the battery box off entirely, unsolder the resistor from there and put it into the socket on my board, and then just connect the wires from the lights themselves to the screw terminals. This made things a bit neater:

Fairy light controller V2, H-bridge chip on stripboard

I also happened to have a bunch of power darlington transistors sitting around, so I made an open-collector output version with them. This let me add the option of using a separate power supply for driving higher voltage loads, rather than just using the same 5V USB power supply as the D1 mini. It was also a bit smaller. (The white terminal block on the left is the power supply input, and the jumper next to it connects it to the 5V from the USB power supply instead.)

Fairy light controller V3, open-collector outputs and an optional separate power supply.

This worked well and was certainly an improvement, but stripboard is still a bit messy, so I decided to make a proper PCB for it. I also found a handy chip with 7 darlington drivers, so I used that. 4 channels still seemed enough so I hooked 3 pairs up together in parallel for higher current capacity. I designed the board on EasyEDA (link at the end if you want to order some for yourself) and ordered 10 copies from JLPCB in China (PCB prototyping services are amazingly cheap these days!) along with the parts, and a few weeks later they showed up.

Fairy light controller V4, all soldered up neatly.

It was indeed neater, so I think this will be the final version. It works well, controlling the fairy lights in the living room.

On the software side, I was able to share a bunch of common code (for the web admin interface and so on) with my previous smart button project. For integration with Google Assistant and Google Home I went via Sinric, which provides a server that the board can connect to, and then can connect to the Google Smart Home API. It’s still a wee bit of a hack at the moment unfortunately, as the Sinric Google Home integration isn’t properly launched so you can only use it in developer testing mode, but other than that it works well. You can track the status of the Sinric launch on GitHub.

If you’d like to make one for yourself, you can find the schematic and PCB design here on EasyEDA ready to print, and the source code and setup instructions here on Gitlab. (See the ‘Smart switch’ / qSwitch section.) And there are a few more photos here. Let me know how you get on!

[edit] Oh, and if I know you / you live in London, I have 9 spare boards and most of the parts available, so if you’d like one let me know. You’ll just have to get your own D1 mini and terminal blocks. Happy to help get it working too.

Advertisements

24 December 2018

Smart homes and ESP8266s

Filed under: Computers, Electronics — Tags: , , , — qwandor @ 11:42 pm

I’ve recently been playing with a bunch of smart home stuff, based around the Google Home ecosystem. I have a Google Home, Google Home Hub and JBL Link View in various rooms, a Chromecast and Chromecast Audio, a Nest thermostat, a bunch of cheap smart light bulbs, and some Sonoff switches for the ceiling lights. It’s pretty cool: I can control the lights and music all around the house by voice, from the smart displays, or from my phone.

But there are a few things missing. As cool as voice control is, sometimes I just want to press a button and have it run some preset action, like turning all the living room lights off late at night when I’m heading up to bed (without waking up my housemates), or turning on all the fairy lights for a party (when the background noise is too loud for voice control to work reliably, and it’s a bit awkward anyway).

Happily, AliExpress has lots of ESP8266 dev boards from as little as £1.70. The ESP8266 is a little microcontroller with a WiFi stack and fairly low power requirements that makes creating WiFi-attached gadgets pretty easy. It can be programmed (among other options) in C++ with with the Arduino libraries. For a nicer development than the standard Arduino IDE I used PlatformIO, which adds a proper IDE and dependency management.

My first approach was a stand-alone button. This can be battery powered, and stays in a low-power standby state (or entirely off, with a little extra support circuitry) until it is reset, at which point it starts up, connects to WiFi, sends a command, and goes back into standby (or powers down). This works well, though I didn’t get as far as finding a nice way to package it up. Without making custom hardware it’s a little bulky, with the battery and everything.

An ESP8266 dev board connected to a Li-ion battery.
An ESP8266 dev board connected to a rechargable battery.

So I tried a different approach. The Sonoff RF Bridge is widely available on AliExpress and elsewhere for under £10. It contains an ESP8285 (basically the same as the ESP8266 but with built-in flash) and a 433MHz remote transmitter and receiver controlled by a separate microcontroller, connected over the serial port with a documented protocol. With the stock firmware it can clone your existing remotes to control whatever devices you may have controlled by 433 MHz remotes, which was not very useful to me. However, the firmware can easily be replaced by simply opening the case (4 screws) and soldering on a 4 pin serial header to the labelled row of holes on the PCB. AliExpress also has lots of nice wall-mounted 433MHz RF buttons that look like normal light switches and can last a long time on a small battery.

With that in mind, I built some replacement firmware for the Sonoff RF Bridge, that lets you pair it with many such buttons, and associate each one with a different command to send. This works really well! I have the RF bridge sitting plugged into USB power somewhere out of the way, connected to my WiFi, and waiting for signals from the buttons I now have mounted around the house to send commands.

A Sonoff RF Bridge connected to USB power.
My RF Bridge glowing happily in the corner.

What I haven’t mentioned so far is how I send commands. Google Home doesn’t yet have a proper API to connect buttons like this, but what there is an API for is sending Google Assistant commands from other devices. These can be either voice or text; of course in this case I went with text. So when one of the buttons is pressed, I can send an arbitrary Google Assistant command, like “turn off the living room lights”. It takes a couple of seconds to respond, but otherwise works pretty well.

If you’d like to try either of the above, you can get the source code here, along with some more documentation of how to set it up. Once you’ve flashed it onto your device there’s a web interface which should make it easy to connect to your WiFi, authenticate your Google account and set up whatever commands you want.

If you do try it, please let me know if it’s useful! Or if you have any trouble getting it working or find any bugs, let me know too.

Next up (and in the same repository above, if you can’t wait), how I control lots of fairy lights. Until then, have fun, and Merry Christmas!

Create a free website or blog at WordPress.com.