Question

I am interested in making a Bluetooth powered Arduino light switch that senses when I enter my office (via my iPhone) and automatically turns on the lights. My understanding is that the safest way (that is, not playing with the 220 V light switch power supplies) to do this is to use the X10 remote control / powerline system to flip on the light switch.

The library for connecting X10 to Arduino can be found in X10 Library.

The box that connects to the Arduino (requires soldering) can be found in Connecting Arduino to Lightswitch via X10.

I am having trouble figuring out how to use the X10 libraries and how to code it so that it turns the light switch on. I've got the part where once the Bluetooth is paired, it sends the X10 command. The problem is that I don't know which X10 command to send.

Was it helpful?

Solution

The examples included in the Arduino X10 ZIP library are very helpful. Basically, you just need to include these lines:

// Initialize and create an X10 instance
x10 myHouse =  x10(zcPin, dataPin);  // Where these pins are what you connected the X10 transmitter to.

All X10 devices have two identifying attributes: a house code and unit code. The idea is that you could control all the outlets in your house, with a house code associated to each room and the unit for each device. Practically, in this experiment you just have one device set to house code 'A'. You don't really need the fine control of addressing just one device from multiple devices within a house code. Just sending the command "everything on house code 'A' turn on (or off)" what works fine. It's not going to send multiple commands, just the single ON command format like a wildcard address. Assuming your switch is set to house code 'A' and unit '1', then turn it on with:

 myHouse.write(A, ALL_LIGHTS_ON, 3);  // The 3 means send the same command three times to overcome any potential noise in the circuit. 

And off is obviously:

myHouse.write(A, ALL_LIGHTS_OFF, 3);

Another FYI when using X10, is that the signal transmitted over power lines is pretty fragile. Most modern circuits - like using power surge protectors and multiple circuit breakers - can filter out the single between one side of the house to the other. So for best results, have the X10 transmitter and X10 device on the same circuit, or as close as possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top