Arduino and Infrared … (Part 3)

Arduino, IR and X10

That post is due for a long time. I’ll continue with the infrared project and add control of X10 devices in your house. Don’t know what X10 is? Click here to learn more.

The code in this post is not much different than the code presented on part 2 of this series. In addition to controlling red, green and yellow LEDs, we will control your home appliances. To do so, you will need two new parts, the X10 transmitter and an X10 appliance receiver. Simply Google “X10 devices” to find stores selling these in your area.

You connect to the X10 transmitter using a standard telephone cable. Make sure you use a 4 wires cable. Many phones are sold with two wire cables. Keep one connector to connect to the transmitter and strip the wires on the other end to connect to your circuit.

Telephone cable
Telephone cable

In our example, the match between the colors of the telephone cable wires and the modem pin numbers is the following:

#1 => Black
#2 => Red
#3 => Green
#4 => Yellow=4

X10 Modem connector
X10 Modem connector

The complete circuit should be wired as following. The black wire (pin #1) should be connected to a pull-up 10K resistor and the red wire (pin #2) to the ground. The yellow wire (pin #4) must be connected to the output signal pin of the Arduino board. Finally, the green wire (pin #3) of the modem is not connected.

Arduino, IR and X1 Circuit
Arduino, IR and X1 Circuit

Additions to this project code are the calls to the X10 library. Following are the differences with the code of the previous project. You can download the complete project on my Github account: https://github.com/pchretien/ir_x10

#include <x10.h>
#include <x10constants.h>

...

#define ZC_PIN 2
#define DATA_PIN 3
#define X10_REPEAT 3

...

x10 myHouse = x10(ZC_PIN, DATA_PIN);

...

void setup()
{
  ...
  // X10 Controller
  myHouse.write(A, ALL_UNITS_OFF,3);
}

...

void loop()
{
    // POWER BUTTON 279939191
    // Toggle red LED and X10 device when POWER button command is received
    if( code == 279939191 && bit_position > 0)
    {
      myHouse.write(A, UNIT_1, X10_REPEAT);    

      red_led_state ^= 1;
      if(red_led_state)
      {
        myHouse.write(A, ON, X10_REPEAT);
        digitalWrite(RED_LED, HIGH);
      }
      else
      {
        myHouse.write(A, OFF, X10_REPEAT);
        digitalWrite(RED_LED, LOW);
      }
    }
}

...

You can download the X10 library at the following location:
http://www.arduino.cc/en/Tutorial/X10

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top