My Cart

How to Send Sensor Data Using XBee Connectivity Kit

Difficulty Level: Intermediate -

1. Introduction

This tutorial allows the user to measure the amount light in a room and print it in a graph. This data is sent to a XBee gateway.

Ingredients:

    - 1 x XBee Connectivity Kit:
    • 1x Platform
    • 2x XBee
    • 1x XBee Shield
    • 1x XBee gateway
    • 1x LDR sensor
    • 1x 220Ω resistors
    • 1x Breadboard
    • 1x Programming cable
    • Jumper Wires

Preparation Time: 30 minutes

Buy now
NOTE: Depending on the platform chosen to develop the project, the ingredients and the schematics shown in this tutorial can vary.

This project can be developed with Arduino or Intel Galileo. It is also compatible with Raspberry Pi using the Raspberry Pi to Arduino shields connection bridge.

For further information about the XBee Shield, consult the main tutorial.

Step 1: Connection

Connect the XBee shield to Arduino and then connect XBee module or you can connect it directly to Raspberry Pi connection bridge. Connect the LDR with a resistor in the breadboard as you can see in the next diagram.

Connect two wires, red and black, to the two long rows on the side of the breadboard to provide access to the 5 volt supply and ground.

Connect the left leg of the light sensor to GND and the right to the first pin at bottom left of the shield (Analog 0) and also to a 220 Ohm resistor.Finally connect the other leg of the resistor to 5 volt. This structure is called "voltage divider".

On the other hand you must connect a gateway with a XBee module to a PC.

Step 2: The Code

Arduino:

Code:
/*  
 *  XBEE Module 
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Marcos MartĂ­nez
 */
 
int LDR;

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

}

void loop() {

  LDR = analogRead(A0);
  printwave(LDR);
  delay(100);

}

void printwave(int LDR)
{
  for (int i=0; i < (LDR / 30) ; i ++) {  
    Serial.print("*");  
  }

  Serial.print("*");
  Serial.print("\n");
  delay(25);
}

        

Raspberry Pi:

Code:
/*  
 *  XBEE Module 
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Marcos MartĂ­nez
 */
 
//Include arduPi library
#include "arduPi.h"

void printwave(int LDR);

int LDR;

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

}

void loop() {

  LDR = analogRead(0);
  printwave(LDR);
  delay(100);

}

void printwave(int LDR)
{
  for (int i=0; i < (LDR / 30) ; i ++) {  
    Serial.print("*");  
    printf("*");
  }

  Serial.print("*");
  Serial.print("\n");
  printf("*\n");
  delay(25);
}

int main (){
    setup();
    while(1){
        loop();
    }
    return (0);
}


        

Intel Galileo:

Code:
/*  
 *  XBEE Module 
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  a
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Jorge Casanova, Luis MartĂ­n
 */	

int LDR;

void setup() {
  Serial1.begin(9600);

}

void loop() {

  LDR = analogRead(A0);
  printwave(LDR);
  delay(100);

}

void printwave(int LDR)
{
  for (int i=0; i < (LDR / 30) ; i ++) {  
    Serial1.print("*");    
  }

  Serial1.print("*");
  Serial1.print("\n");
  delay(25);
}