Learning   Examples | Foundations | Hacking | Links

X10 Library

This library enables you to send and receive X10 commands from an Arduino module. X10 is a synchronous serial protocol that travels over AC power lines, sending a bit every time the AC power crosses zero volts. It's used in home automation. You can find X10 controllers and devices at http://www.x10.com, http://www.smarthome.com, and more.

This library has been tested using the PL513 one-way X10 controller, and the TW523 two-way X10 controller. Both of these are essentially X10 modems, converting the 5V output of the Arduino into AC signals on the zero crossing.

To connect an Arduino to one of these modules, get a phone cable with an RJ-11 connector, and cut one end off. Then wire the pins as follows:

Download the library from GitHub

To use, unzip it and copy the resulting folder, called X10, into the libraries directory of your sketch folder (you may have to create the libraries directory if you've never installed a library before). Then re-start the Arduino application.

As of version 0.4, here's what you can do:

x10.begin(rxPin, txPin, zeroCrossingPin) - initialize an instance of the X10 library on three digital pins. e.g.

x10 myHouse = x10.begin(8, 9, 10); // initializes X10 on pins 9 (zero crossing pin) and 10 (data pin)

Note: rxPin is declared for future use, when receive is implemented. As of now, you can use any value, and it won't reserve a pin. In the example above, 8 is just a placeholder until I get time to write the receive functions

void write(byte houseCode, byte numberCode, int numRepeats) - Send an X10 message, e.g.

myHouse.write(A, ALL_LIGHTS_ON, 1);     // Turns on all lights in house code A

There are a number of constants added to make X10 easier. They are as follows:

  • A through F: house code values.
  • UNIT_1 through UNIT_16: unit code values
  • ALL_UNITS_OFF
  • ALL_LIGHTS_ON
  • ON
  • OFF
  • DIM
  • BRIGHT
  • ALL_LIGHTS_OFF
  • EXTENDED_CODE
  • HAIL_REQUEST
  • HAIL_ACKNOWLEDGE
  • PRE_SET_DIM
  • EXTENDED_DATA
  • STATUS_ON
  • STATUS_OFF
  • STATUS_REQUEST

Version 0.4 is compatible with Arduino 1.0.3.

NOTE: I have no plans to develop this library further at this time. If you're looking for further developments, check out Doug Clinton's fork of creatrope's version.

For a full explanation of X10 and these codes, see this technote


Share