Push button XBEE code


//Push button example transmitter XBEE
#include
NewSoftSerial xbeeSerial(4, 5);
int buttonState = 0;

void setup() {
Serial.begin(9600);
xbeeSerial.begin(9600);

pinMode(2, INPUT);  // initialize the pushbutton pin as an input
   
}
void loop() {

buttonState = digitalRead(2);     // Read the pin 2 value, a 1 or 0
Serial.print(buttonState);        // print button value to screen
Serial.print("\n");               // line break
xbeeSerial.print(buttonState);    // print value to xbee (serial port)

delay(100);                       // stop the program for some time
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Push button example receiver XBEE
#include
#include
NewSoftSerial xbeeSerial(4, 5);

void setup() {
Serial.begin (9600);
xbeeSerial.begin(9600);
pinMode(13, OUTPUT);
}

void loop() {

  while(xbeeSerial.available())
  { 
    char getData = xbeeSerial.read();
    Serial.print (getData);
    Serial.print ("\n");
       
      if (getData == '1') {     
    // turn LED on:    
    digitalWrite(13, HIGH);  
     } 
     else {
    // turn LED off:
    digitalWrite(13, LOW); 
     }
     
  }
    delay(100); // stop the program for some time
}

1 comment:

  1. What's this newsoftserial error when verifying? im using arduino mega and uno

    ReplyDelete