XBee Environment Data Collector

XBee Environment Data Collector

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:

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.


Comming soon…


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() {


void loop() {
  int temperature = readTemperature();
  int light = readLight();
  int presence = readPresence();

  printKeyValue("tmp", temperature);
  printKeyValue("lgt", light);
  printKeyValue("prs", presence);


 * 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 Capture