Around the same time as companies began releasing "home automation" devices, I wanted to create a bank of LEDs, and control it without having to cut through walls to bring wiring to the switch on the wall.  Of course, there were already plenty of products on the market that already did this, but it was a fun experiment.

I downloaded the APIs for the XBee framework, did a ton of research, bought the wireless radios, and a couple Arduino boards.  This project never really got past the prototyping phase because of life.  

You might also be interested in the other Arduino projects on here.  Feel free to poke around other articles.

 

Here’s the code & a video to make it work:

Video of two controllers with one switch and an LED on the remote board:

 

Code for single switch with xbees (note you still need the receiver code to receive the signal & turn on the LED):

int BUTTON1 = 8; //input of button
int BUTTON2 = 10; //input of button

void setup() {
  pinMode(BUTTON1, INPUT);      // sets the digital pin 5 as input
  pinMode(BUTTON2, INPUT);      // sets the digital pin 5 as input
  Serial.begin(9600);
}

void loop() {
  if (digitalRead(BUTTON1) == HIGH) {
    Serial.print('A');
    delay(1000);
  } else {
    Serial.print('L');
    delay(1000);
  }
  if (digitalRead(BUTTON2) == HIGH) {
    Serial.print('B');
    delay(1000);
  } else {
    Serial.print('M');
    delay(1000);
  }

}

 

Video of two controllers with two switches and LEDs (I love this one because it's like a 3-way switch but with none of the traditional components):

 

xBee transmitter:

int SWITCH1=8;
//int SWITCH2=11;

void setup() {
  pinMode(SWITCH1,INPUT);
//  pinMode(SWITCH2,INPUT);
  Serial.begin(9600);
}

void loop() {
  if (digitalRead(SWITCH1) == HIGH) {
//    Serial.println("switch1 is high");
    Serial.print('A');
    delay(1000);
  } else {
//    Serial.println("switch1 is low");
    Serial.print('F');
    delay(1000);
  }
/*  if (digitalRead(SWITCH2) == HIGH) {
    Serial.println("switch2 is high");
    Serial.print('C');
    delay(100);
  }
  if (digitalRead(SWITCH2) == LOW) {
    Serial.println("switch2 is low");
    Serial.print('D');
    delay(100);
  }
  */

}

 

xBee receiver:

//int LSWITCH = 5;
int LED1 = 8;
//int LED2 = 10;

void setup() {
//  pinMode(LSWITCH,INPUT);
  pinMode(LED1,OUTPUT);
//  pinMode(LED2,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
//    Serial.println("serial is available");
//    if (digitalRead(LSWITCH) == LOW) { //read off the wire to see if the LEDs
        //should be on/off
//    Serial.println(Serial.read());    
      if (Serial.read() == 'A') {
        Serial.print("received: ");
        Serial.print(Serial.read());
        digitalWrite(LED1, HIGH);
      } else {
        Serial.println(Serial.read());    
      }  
      if (Serial.read() == 'F') {
//        Serial.println("received S1L signal");
        digitalWrite(LED1, LOW);
      } 
/*      if (Serial.read() == 'C') {
        Serial.println("received S2H signal");
        digitalWrite(LED2, HIGH);
      } 
      if (Serial.read() == 'D') {
        Serial.println("received S2L signal");
        digitalWrite(LED2, LOW);
      } */
//    } else { //turn off both LEDs
//        digitalWrite(LED1, HIGH);
//        digitalWrite(LED2, LOW);      
//    }
  }
}