After nearly two years in the ‘Arduino Business’ (its more like the ‘Arduno Hobby’ actually), I finally got my self a pair of XBees! Kept in a box for a month, but this weekend I’ve unpacked the hive and put them to make some honey.
This weekend me and a friend (Ian Gallina) set up the XBees as ‘Coordinator’ and ‘Router’ and put the ‘router’ on a shield with a pack of sensors (temperature, light and presence) collecting data from my living room and sending it over the air to my laptop. The idea was to save the data in a database so that It can be used to make graphs or publish it in a website showing the environment status for the room. Anyway, I probably won’t do it, for I need my Arduino for other hacks.
Photo gallery
Parts used:
- 1x Arduino Duemilanove
- 2x XBee 2mW – Series 2.5
- 1x XBee Wireless Shield – Sparkfun
- 1x XBee Explorer Dongle
- 1x TMP36 – Temperature Sensor
- 1x Photoresistor
- 1x PIR Motion Sensor
Setting up the XBees
Setting up the XBees was the most difficult part, since I had no idea how to do it or how it worked. After spending about 5 hours on it I got it all figured out.
I used this tutorial for setting up the XBees.
Basically, you have to set one as the ‘Coordinator’ and the others as ‘Router’. The coordinator is a ‘FFD – Fully Function Device’ and can communicate with every device on the network (hence ‘Coordinator’). The cost: it spends more energy; the router on the other hand is more economic, since it operates as a ‘RFD – Reduced Function Device’. It can only communicate with the coordinator.
Protoboard
Comming soon…
Code
const int tmpSensorPin = 0;
const int lgtSensorPin = 1;
const int prsSensorPin = 2;
const int prsLedPin = 13;
const int period = 2500;
const int aref = 3300;
void setup() {
Serial.begin(9600);
analogReference(EXTERNAL);
}
void loop() {
int temperature = readTemperature();
int light = readLight();
int presence = readPresence();
Serial.print("{");
printKeyValue("tmp", temperature);
printKeyValue("lgt", light);
printKeyValue("prs", presence);
Serial.println("}");
delay(period);
}
/*
* Read the temperature in oC
*/
int readTemperature() {
// read the value from the sensor:
int sensorValue = analogRead(tmpSensorPin);
int voltageInMilli = sensorValue * (aref/1024);
int celsius = (voltageInMilli - 500) / 10;
return celsius;
}
/*
* Read the light in lux, from 1 (moon light) to 10.000 (full day)
*/
int readLight() {
// read the value from the sensor:
int sensorValue = analogRead(lgtSensorPin);
int voltageInMilli = sensorValue * (5000 / 1024);
int lux = map(voltageInMilli, 0, 4500, 1, 10000);
return lux;
}
/*
* Read the presence
*/
int readPresence() {
// read the value from the sensor:
int sensorValue = analogRead(prsSensorPin);
if(sensorValue == LOW) {
digitalWrite(prsLedPin, HIGH);
return HIGH;
} else {
digitalWrite(prsLedPin, LOW);
return LOW;
}
}
void printKeyValue(char key[], int value) {
Serial.print(key);
Serial.print("=");
Serial.print(value);
Serial.print(";");
}





Hi Lucas,
Thanks for sharing this info. I have also struggled to get two series 2 XBee radio’s setup. Coincidentally, I am doing something similar to your project: monitoring environment data in a greenhouse. That data will then be sent wirelessly to another arduino with XBee shield and Ethernet shield, which will put it in a database. Currently, I have setup a prototype that tweets its data via Pachube, but it is not wirelessly via the Xbee’s yet.
Another funny coincidence: your site and mine both use the same WordPress theme
Good luck on the projects and thanks a lot for sharing your info!
Kind regards,
Arno
Lucas,
Estou deixando este comentário pra dizer que fiz uma referencia ao seu projeto no meu blog.
Did you simply use the Explorer Dongle to upload the firmwares to the XBee modules? And btw, do all the XBee Series 2.5 modules use the ZNet 2.5 firmwares?
Vanessa, I didn’t change the XBees firmware. I used the default to implement a wireless comunication between a PC and an Arduino (www.arduino.cc).
It would be nice if you add another Arduino (with Router/End Device XBee) which senses other part of the house and sends data to the computer.
I am looking for a literature, a tutorial like this which demonstrates wireless communication between 3 XBees (1 coordinator and 2 end device). I just want to make sure that data and packets are not mixed up during transmission.
One Arduino (with End Device XBee) should send an ID along with the data like:
Serial.print(“{“); // packet marker
Serial.print(“mote1=”); // identifier
Serial.print(value); // data
Serial.print(“}); // packet marker
and the other Arduino can have an identifer of “mote2″
so that in the display, it will be known which Arduino is the source of data.
Did you happen to find any literature like this?
There is a library for serial communication that sends an identifier along with the message. Check it out and see if it solves your problem: http://www.arduino.cc/playground/Code/SerialControl
Regards,
LF