I have a couple of 12v LED lights on my bedhead. I think they’re designed for use in caravans or something. They have a switch on their bases so they are pretty easy to install/use. But lights by themselves like that are pretty boring. They are much more interesting/fun if they are computer controlled :-). They are 12v (or 24v) and only draw a couple of hundred mA so are pretty easy to switch with the likes of an Arduino with a relay or a MOSFET (or even a plain old transistor). That just leaves how you tell the Arduino to turn the light on or off. Only via smartphone is rather annoying when all you want to do is reach over and turn the light on. So my first thought was a box with buttons on it (didn’t want to alter the lights themselves). But where do you put it? And it’s a bit messy. Then, recently, I thought why don’t I use one those capacitive touch boards and turn the light itself into the switch. Since I had two lights I bought breakout board with 5 sensors on it. The board works pretty well, the issue being that the wire connecting the board to the light also becomes a touch sensor. To fix this issue I bought two single sensor boards instead. A short wire connects the board to the body of the light.
So for each light I put one of the sensor boards in a small box, mounted it on top of the board the light is mounted on to and ran a wire out of the bottom to the light body. The output of each board runs to an input on an Arduino.
In a box is an Arduino with some shields stacked on it:
- XBee Shield with a XBee wireless module
- Freetronics “N-Drive” shield – Used to switch the lights
- Power supply shield
The Arduino watches the inputs that the touch sensors are connected to. If the input activates and then deactivates in less than half a second then it toggles the light state and reports the new state over the XBee module. The maximum touch time to toggle is so you can move the light without toggling it. The Arduino also acts on commands received via the XBee module. At the other end of the XBee connection is a Python script that bridges between a number of XBee modules and MQTT. The two lights have been added to openHab as switches via MQTT so their state can be monitored and controlled via any openHab interface.