Remote Control Light Switch

IMG-20120411-00396

Motivation

You’re watching a movie at your desk, have the headphones on, and in a comfy position and you realize you left the light on. You have to get up. Tired of doing this, I wanted the ability to control my bedroom light remotely. I made a circuit that allows me to do precisely that. I can control my light with any device that can load a webpage and is on my home WiFi.

I still wanted to be able to control the light manually, so I bought a metallic face-plate and turned it into a capacitive touch sensor. The slightest touch anywhere on the plate is enough to toggle the light. I had to electrically insulate the metal screws from it because they screw into a grounded switch box.

IMG-20120411-00408

Function

I have a Raspberry Pi ($35 computer) on my home network that runs a web server. When you connect to it in your web browser, a page loads with buttons to turn the light on or off. When you press a button, the PHP interpreter executes a command that sends a message over Bluetooth to the light switch. The Bluetooth module in the wall receives this message and forwards it to the microcontroller, an MSP430G2553 from TI, which processes it and toggles the relay. The relay (white box) is the actual switch which is connecting and disconnecting the light from power. The whole circuit is also powered from mains by an AC-DC converter (black box).

painting1_large

Engineering

I decided to use a Raspberry Pi and Bluetooth because it was what I had on hand at the time. I also plan on expanding this and the Raspberry Pi will be a control hub that talks to many Bluetooth slaves in order to automate more aspects of my life. The Bluetooth module is attached to the protoboard via a ribbon cable, which allows it to sit outside of the metal switch box in order to get a better signal.

I ran into some bugs along the way while designing this. The Bluetooth module communicates serially over UART, so I used my Saleae Logic Analyzer in order to make sure that the module was communicating correctly with the microcontroller. This also helped me with some timing in the state-machine which controls the handshaking to configure the Bluetooth module to receive connections.

Another problem is that the baseline capacitance (which I constantly measure) of the button slowly changes with time due to changes in the environment. This has led to my lights randomly flickering on and off rapidly at night. To solve this, instead of adding hysteresis, I very gradually change the baseline capacitance value. I do this slow enough that touching the button slowly will still send the measurements above the threshold.