Amazon Store

Tuesday 24 March 2015

How to Interface XBEE with Arduino

In earlier days the application of the wireless technology was limited mostly to simple point to point communication only replacing the cable based communication systems. The entire communication system itself became complex after the introduction of the computer and communication system based on computers. Several complex networked communication systems like LAN, WAN, PAN etc. came into use. To replace the cable based network communication system with wireless technology demands the design of complex wireless devices and wireless network protocols.

The ZigBee is the name of a wireless protocol maintained by the IEEE 802.15 standard. This is a protocol specified for wireless Personal Area Network (PAN) using low powered wireless transceivers. There are already wireless transmitter and receiver modules which can do point to point communication. The Xbee is the brand name a wireless transceiver device introduced by the Digi international which works on the ZigBee protocol and can form PAN networks. They have an approximate range of 10 to 100 meters and are used in industries, scientific fields, medical fields etc.  

The Xbee module even though uses complex packet data based Zigbee protocol for communicating with each other, they can communicate with other devices using simplest serial communication protocol and hence they are widely used in microcontroller base boards. This tutorial demonstrates how to interface an Xbee module with the Arduino board and perform simple transmission and reception. This is a very basic experiment with the Xbee using only two Xbee modules in which one of them transmit the data and another one receives data but cont

How To Interface XBEE With Arduino

Circuit 



The Arduino board is built around an AVR microcontroller and it has all the required circuitary to get the built-in AVR microcontroller running. The Arduino can communicate with the other devices using its digital I/O, serial port, I2C port, SPI port etc. Any AVR microcontroller based board which follows the standard Arduino schematic and is flashed with the Arduino bootloader can be called an Arduino board. The Arduino IDE is so simple to use that anyone who has basic knowledge of c programming can quickly get started with it. The project on Getting started with Arduino  explains the steps required to get start with an Arduino board.

The Arduino board used in this project is the Arduino pro-mini board and the IDE version of the Arduino is 1.0.3 for windows. The image of the Arduino pro-mini board and the Arduino IDE are shown below;

Arduino

 

Arduino

Since the arduino pro-mini board has no circuitary for interfacing it with the serial port or the USB port of the PC, an external USB to TTL converter board is required to connect it with the PC. This hardware helps in programming the Arduino board and also helps in the serial communication with the USB port of the PC.

The image of the Xbee S1 series module used in this project is shown in the following image. Since the pitch of the pins of the modules are not breadboard compatible one can use the Xbee based design boards which comes with breadboard compatible pins.

XBee

Since the Xbee modules communicate using serial communication protocol with the interfacing devices they can be connected to a microcontroller using a minimum of four pins, Power supply, and Ground, UART Data Out, and UART Data In pins. The Xbee modules have several digital and analog I/O pins apart from these pins and the pin out of an Xbee module is shown in the following table;

 

PIN

DESCRIPTION

1

Power Supply

2

UART Data Out

3

UART Data In

4

Digital Output 8 (not supported as of 2/28/09)

5

Module Reset (reset pulse must be at least 200 ns)

6

PWM Output 0 / RX Signal Strength Indicator

7

PWM Output 1

8

Do not connect

9

DTR / Pin Sleep Control Line or Digital Input 8

10

Ground

11

Analog Input 4 or Digital I/O 4

12

Clear-to-Send Flow Control or Digital I/O 7

13

Module Status Indicator

14

Voltage Reference for A/D Inputs

15

Associated Indicator, Analog Input 5 or Digital I/O 5

16

Request-to-Send Flow Control, Analog Input 6 or Digital I/O 6

17

Analog Input 3 or Digital I/O 3

18

Analog Input 2 or Digital I/O 2

19

Analog Input 1 or Digital I/O 1

20

Analog Input 0 or Digital I/O 0

The pin number 2, UART Data Out is connected to the RX1 pin of the Arduino pro mini board and pin number 3 UART Data In is connected to the TX0 pin. The code written for this project communicates with the Xbee using the serial communication functions provided by the Arduino library. The functions like Serial.begin() which helps to initialize the serial port with a given baud rate, Serial.write() to send a data to the serial port, Serial.available() and Serial.read() functions to read data from the serial port are used in this project and they are already discussed in previous projects on how to do serial communication with the Arduinohow to send and receive serial data using arduino and how to do serial debugging with the Arduino.

When the coding is finished one can verify and upload the code to the Arduino board as explained in the project how to get started with the Arduino. As soon as the board is powered up the Xbee in the Arduino board automatically establishes communication with another Xbee which is connected to the serial port of a PC. Once the power is on the Arduino board continuously sends a string to the Xbee module with a small delay and the same string appears in the serial monitor window of the PC where the other Xbee module is connected. The second Xbee board can be connected to the PC using the same USB to TTL converter board which has been used to program the Arduino board. The string can be read using any serial monitoring software or using the Arduino IDE's serial monitoring software itself as explained in the project how to do serial debugging with the Arduino.

Code:

/*============================ EG LABS ===================================//
 
 Demonstration on how to use PS2 MOUSE with an arduino board
 
 The circuit:
 LCD:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 7
 * LCD D5 pin to digital pin 6
 * LCD D6 pin to digital pin 5
 * LCD D7 pin to digital pin 4
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD pin 3
 * LED anode attached to digital output 9
 * LED cathode attached to ground through a 1K resistor
 
 XBEE:
 RX PIN OF XBEE TO TX0 PIN OF ARDUINO
 SHORT THE GROUND PINS OF ARDUINO AND XBEE
 
============================== EG LABS ===================================*/
 
#include <LiquidCrystal.h>
 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
 
// give the pin a name:
int led = 9;
 
void setup()
{
  // set up the lcd's number of columns and rows: 
  lcd.begin(16, 2);
  lcd.print("ENGINEERS GARAGE");
  lcd.setCursor(0, 1);
  lcd.print(" XBEE INTERFACE ");
  
  // initialize the led pin as an output.
  pinMode(led, OUTPUT);  
  // start serial port at 9600 bps
  Serial.begin(9600);
  // wait for a while till the serial port is ready
  delay(100);
 
// send the initial data once //    
  Serial.print('\n');
  Serial.print("    EG LABS   ");
  Serial.print('\n');
  Serial.print('\r');
  Serial.print("  XBEE Demo");
  Serial.print('\n');
  Serial.print('\r');
  Serial.print('\n');
}
void loop()
{
  // send this string continuously to another Xbee //
    Serial.println("hello world"); 
    
    // blink the LED once //    
    digitalWrite(led, HIGH);       
    delay(1000);                  
    digitalWrite(led, LOW);       
    delay(1000);                

}







No comments:

Post a Comment