Send information from xbee end device to coordinator

125 views
Skip to first unread message

Diego Turcios

unread,
May 9, 2013, 1:10:40 PM5/9/13
to xbee...@googlegroups.com
Hi
I am working in a small project. Right now I can send information to my end device to turn on a lightbulb. 
I am building a web site for turning the light of my house. I want as feedback to know when the lightbulb is turn on. (Sometimes I will turn on the light manually, and I will like to know that)

What changes I have to make to my code in arduino?

This is my arduino code

/*
*@joiedufranco
*23APR2012
*rxOnOff
*Recieves packet from remote Coordinator
*Turns LED On or Off
*/

int LED = 11;                //Turn this LED on or off, depending on packet rx'd
int debugLED = 13;           //Flash light to indicate rx
int packet=-1;                 //Packet will be two bytes in length
int analogValue;
int PIN=12;
int RELAY=10;

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(PIN, INPUT);
  pinMode(RELAY, INPUT);
  pinMode(debugLED, OUTPUT);
  Serial.begin(9600);

}

void loop() {
  
 if(Serial.available() >= 16){        //<--Changing the value from 21 to 16 fixed the problem! 
    
   if(Serial.read() == 0x7E){         //Look for starting byte
    
     digitalWrite(debugLED, HIGH);    //Flash Arduino LED (not the one on digital pin 11)
     delay(1000);                          //to indicate rx'ing data
     digitalWrite(debugLED, LOW);
     
     for(int i = 0; i <15; i++){      //Discard unused data (see XBee API protocol for more info)
       byte discard = Serial.read();
     }
     packet = Serial.read();          //This should be the first byte of "meat" data
   }
 }


if(digitalRead(PIN)==LOW){
 if(packet == 0x01){                  //If a '1' is pressed on keyboard side
   if(digitalRead(PIN)==LOW){
     digitalWrite(LED, HIGH);              //turn on red LED
     packet=-1;
   }
 }
}


if(digitalRead(PIN) == HIGH){  
  if(packet == 0x00){
    if(digitalRead(PIN)==HIGH)
    {
      digitalWrite(LED, LOW);
      packet=-1;
    }
  }
}


if(packet == 0x00){                  //If a '1' is pressed on keyboard side
   if(digitalRead(PIN)==LOW){
     digitalWrite(LED, HIGH);              //turn on red LED
     packet=-1;
   }
 }  
  
 if(packet == 0x01){
    if(digitalRead(PIN)==HIGH)
    {
      digitalWrite(LED, LOW);
      packet=-1;
    }
  }
   
}

Thanks

andrew

unread,
May 13, 2013, 9:04:01 AM5/13/13
to xbee...@googlegroups.com
You can use the XBees I/O change detection feature to capture these sort of events. I do this with my garage door controller. You can find a description of the project and code here. http://rapplogic.blogspot.com/2011/10/xbeegoogle-talk-garage-door.html Disregard the google talk stuff 

Diego Turcios

unread,
May 24, 2013, 7:15:55 PM5/24/13
to xbee...@googlegroups.com

Diego Turcios

unread,
May 24, 2013, 7:19:40 PM5/24/13
to xbee...@googlegroups.com


El jueves, 9 de mayo de 2013 11:10:40 UTC-6, Diego Turcios escribió:
Reply all
Reply to author
Forward
0 new messages