XBee to XBee
Overview
XBee to XBee communication allows for some interesting setups, and is useful for its ability to allow for serial communication between two Arduinos. Everything you need to accomplish this is below.
Parts
-2x Arduino microcontroller and carrier board
-2x LiPo battery
-2x XBees
-1x momentary switch, button, or toggle switch
-1x 10k ohm resistor
-hook up wire
Prepare the breadboard on Sender
Connect a wire from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10 KOhms) to ground. The other leg of the button connects to the 5 volt supply.
Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that the pin reads as HIGH, or 1.
Sender
Receiver
Program the Sending Microcontroller
/**
* @file: XBee to XBee SENDER
* @author Daniela Faas (dfaas@mit.edu)
* @date: 8/2/2011
*
* @section DESCRIPTION
* communcation between 2 XBees.
* adapted from:
* http://lab.guilhermemartins.net/2008/12/24/serial-comunication-between-arduinos-with-wire-wireless/
*
*/
#define LED 13
#define BUTTON 2
//--- Function: Setup ()
void setup()
{
Serial.begin(9600); // Serial port enable
pinMode(LED, OUTPUT); // setup LED
pinMode(BUTTON, INPUT); // setup button press
Serial.println("Sender Ready!");
}
//--- Function: Loop ()
void loop()
{
int sensorValue = digitalRead(BUTTON); // read digital pin BUTTON
Serial.println(sensorValue, DEC); // send the value to the serial port
digitalWrite(LED, sensorValue); // send the value to the LED
delay(500);
}
Program the Receiving Microcontroller
/**
* @file: XBee to XBee RECEIVER
* @author Daniela Faas (dfaas@mit.edu)
* @date: 8/2/2011
*
* @section DESCRIPTION
* communcation between 2 XBees.
* adapted from:
* http://lab.guilhermemartins.net/2008/12/24/serial-comunication-between-arduinos-with-wire-wireless/
*
*/
#define LED 13
#define incomingByte 0 // This will hold one byte of the serial message
int value = 0; // high or low value for LED
//--- Function: Setup ()
void setup()
{
Serial.begin(9600); // Serial port enable
pinMode (LED, OUTPUT); // declare as output, this is the LED
Serial.println("Receiver Ready!");
}
//--- Function: Loop ()
void loop()
{
// if there is bytes available coming from the serial port
if (Serial.available()>0)
{
incomingByte = Serial.read(); // set the values to the ‘incomingByte’ variable
if (incomingByte == '0')
value = LOW;
if (incomingByte == '1')
value = HIGH;
}
digitalWrite(LED, value); // write the value to the pin LED
Serial.print(" Receiver:");
Serial.println(incomingByte, DEC);
}