Comunicação IoT entre dois dispositivos através do protocolo Zigbee: IoT Parte 37

IoT communication between two devices via Zigbee protocol: IoT Part 37

In the previous tutorial, communication between two PCs was configured via the Zigbee protocol using Xbee modules and XCTU software. In this tutorial, two Xbee module based IoT devices will be designed and configured to communicate with each other via the Zigbee protocol. One of these devices in the Zigbee network will be a Coordinator device and the other will be a Router device. The coordinator device will control the LED connected to the router device.
The Zigbee protocol is one of the most popular standards for wireless sensor networks. Zigbee is commonly used in industrial IoT applications.
Xbee devices communicate with each other wirelessly over the air. They do not have any microcontroller or processor of their own, so they cannot manage the data received or sent. They can simply transfer the information they receive. But they can be interconnected with other microcontrollers and processors such as Arduino, Raspberry Pi or PC via serial interface.
So basically, Xbee modules are capable of two types of communication – wireless communication and serial communication. Wireless communication occurs between Xbee devices so that the devices act as radio frequency (RF) devices. For data to be transmitted and received from one Xbee module to another, both devices must be on the same network. Data between two devices is transmitted wirelessly. Through serial communication (UART), Xbee modules can communicate with microcontrollers and processors.
A microcontroller, processor or PC can send data through the serial interface to the Xbee module (transmitter) and the Xbee module transmits the data wirelessly to another Xbee module (receiver). The Xbee receiver module transmits data via the serial interface to the controller, processor or PC it is connected to. The controller connected to the Xbee module processes the information received by the Xbee devices. This way, controllers can monitor and control remote devices by sending messages through local Xbee modules.
Xbee modules communicate with each other in two modes – Transparent mode and API (Application Peripheral Interface) mode. This project is based on Transparent mode. In transparent mode, Xbee modules act as a substitute for the serial line. All data received via the serial input is immediately transmitted over the air. When another Xbee module receives data wirelessly, it sends it exactly as it receives it via the serial interface and vice versa. Unlike this, in API mode, data is transmitted with some additional information.
In this project, two Xbee modules will be interconnected with Arduino boards. They will be configured to communicate data between each other in transparent mode. One of the Arduino devices will be interfaced with an LED and will be configured as a Zigbee router. The other Arduino device will be configured as a Zigbee Coordinator. The Coordinator device will control the LED connected to the Router device, passing messages via the Zigbee protocol. The Xbee modules interconnected on both devices will be configured as a coordinator or router using the XCTU software.
Required component –
Lista de componentes necessários para comunicação IoT de dispositivo para dispositivo baseada em Zigbee
Fig. 1: List of components required for Zigbee-based device-to-device IoT communication
Required software –
• XCTU (6.3.1 or later) or legacy XCTU
• Arduino IDE
Block diagram –
Diagrama de blocos de comunicação IoT de dispositivo para dispositivo baseado em Zigbee
Fig. 2: Block diagram of Zigbee-based device-to-device IoT communication
Circuit Connections –
Xbee Series 2 modules will be used in this project. The X-Bee module is a 20-pin module with the following pin configuration –
Tabela de listagem de configuração de pinos do módulo Xbee Série 2
Tabela de listagem de conexões de circuito entre Arduino e módulo Xbee Série 2

Fig. 3: Table listing the Xbee Series 2 module pin configuration

To connect the module to the PC for configuration, first place the Xbee on the Xbee Shield and connect the module to an Arduino. The Arduino UNO or Arduino Mega acts as a USB converter for Xbee modules. Before using the Arduino UNO with Xbee modules, a minimum sketch must be loaded into it or the Atmega microcontroller must be removed from the board. The Xbee module can be powered by an external power supply or by Arduino. The Xbee module and the Arduino board must communicate serially. The Xbee module must be connected to the Arduino according to the following table –
Tabela de listagem de parâmetros de configuração do módulo Xbee
Fig. 4: Table listing circuit connections between Arduino and Series 2 Xbee Module
Now Arduino can be connected to PC using a USB cable.
After connecting the module to the computer, perform the following steps –
1) Open the XCTU software. Make sure the software is in configuration work mode.
2) Click on “Discover Radio Modules”.
3) Click on the desired COM port to which the module is connected.
4) Click next, in the 'Set Port Parameters' window, change the values ​​as per the requirements and click finish.
5) As XCTU finds the radio modules after full scan, select the radio modules by clicking 'Add Selected Devices'. The selected radio modules should now appear in the radio module window.
To transmit or receive data on Xbee modules, they must be properly configured on the same network. According to the Zigbee protocol, one device needs to be in coordinator mode and the rest can be routers or end devices. In this case, one device is the coordinator and the other is the router.
Now, restore the default configuration of all Xbee modules with the 'Load Default Firmware Configuration' button at the top of the radio configuration section and use XCTU to configure the following parameter –
Fig. 5: Table listing the Xbee Module configuration parameters
Keep the rest of the values ​​as default and write the configurations of all Xbee modules with the 'write radio modules' button at the top of the radio configuration. Once configuration is complete, click the discover radio modules on the same network as any radio module button. Radio modules for the same network can now be found.
Now Xbee modules can be connected to Arduino-based IoT devices.
One of these devices will act as a Zigbee Coordinator. Connect the Xbee module configured as a coordinator in your circuit. The Xbee module can communicate with Arduino through serial communication. The Arduino software serial is used to read data from the Xbee and the hardware serial is used to read the controller serial data. Since Xbee operates at CMOS logic level and Arduino operates at TTL logic level, there is a need for a logic level converter. A 5V to 3.3V IIC I2C logic level interface level converter module for Arduino is used as the logic level converter. The Xbee module can be powered by an external source or by Arduino. For serial communication between the Arduino board and the Xbee module, the RX pin of the Xbee is connected to the TX of the Arduino and the TX pin of the Xbee is connected to the RX of the Arduino. The ground pin is connected to common ground.
The other device works as a Zigbee router. Connect the Xbee module configured as a router to your circuit. The Xbee module is connected to the Arduino in a similar way. An LED interfaces to the Arduino at its PD2 pin (pin 4) via a 220 ohm pull up resistor.
The following precautions should be taken while interfacing Xbee modules –
1) Xbee modules operate at 3V3 with a current of 40 mA to transmit and receive data. Do not supply 5V from Arduino.
2) Xbee modules have 3V3 signal level tolerance. To provide communication between Arduino and Xbee, use CMOS to TTL (bidirectional) logic level converter.
3) Sometimes while trying to discover Xbee, an error may occur like – 'Could not find any device on COM6 port >For input string: “ERROR” or error initializing device parameter = connection timeout or device parameter' could not be found, then the error may be due to incorrect baud rate.
To do this, connect the modem using FTDI cable to the PC, open XCTU, select the COM port and various baud rates like 9600, 115200, 57600 and search for the radio module and possibly there the radio module can be found. But if it is not found, open the legacy XCTU (old version), select the possible baud rate and in the modem configuration window select the correct modem firmware/feature set, enable 'always update firmware' and select record. After that, when the information (action required) box appears, restart the Xbee by connecting RST to GND or simply take out the Xbee and place it back on the seat. Now the information box will disappear. Then the radio modules will flash again automatically.
4) If the baud rate difference error occurs, the error may be that the PC and radio module are not operating at the same baud rate. In this case, try changing the PC and updating the firmware with another PC. The Xbee module can also be recovered this way.
5) Issue commands correctly when working in AT mode.
Protótipo de coordenador e roteador Zigbee baseado em Xbee e Arduino
Fig. 6: Zigbee coordinator and router prototype based on Xbee and Arduino

How the circuit works –

The Xbee coordinator controls the LED on the Xbee router. Xbee modules interface with Arduino boards that are programmed to communicate specific messages. First, the coordinator bee continuously listens for any serial messages. The Arduino board in the Xbee Coordinator issues 0 or 1 commands via the serial monitor to the Xbee coordinator. The Xbee router continuously listens for any wireless radio messages. The Xbee coordinator passes the same information (0 or 1) to the Xbee router in wireless mode. Now the Xbee router serially passes the same information, without additional data, to the Arduino board connected to it.
The Arduino serial checks whether the information received is 0 or 1. If it is 1, it means that the LED connected to the board should light up, setting the LED's connected pin to HIGH. If it is 0, it means that the LED connected to the board should stop glowing, setting the connected pin of the LED to LOW.
The following code in the Arduino receiver controls the LED according to the message received via the Zigbee protocol.
if(xbee_s2c.available >0) //did Xbee receive anything?
{
input = Serial.write(xbee_s2c.read ); //send to Arduino serial
if (input == '0')
{digitalWrite(2, HIGH);}
if (input == '1')
{digitalWrite(2, DOWN); }
}
Check out the Arduino sketches to see how they communicate with the Xbee modules using serial software, transmit and receive specific messages (encoded in the firmware), and control the LED in communicating specific messages to each other. This is a simple demonstration of IoT communication between two devices via the Zigbee protocol.
In the next tutorial, learn how to design an LED light controller over Zigbee using Xbee modules.

Project source code

 ###



 //Program to


 /*

 @Application: Arduino_sends_data_to_xbee


 @Hardware used:

 Arduino UNO

 Xbee mermaids 2 module

 External Power supply


 @Connection:

 Xbee VCC- External power supply 3v3

 Xbee GND- EXternal power supply GND

 Xbee TX- Arduino digital pin 11

 Xbee RX- Arduino digital pin 10

 External power supply GND - Arduino GND


 @Brief Introduction:

 Transmitter side:

 The Arduino serial sends the data to Xbee serial.
 
And if xbee receives some data wirelessly from other xbee

 then it sends to arduino serial

 For more detail, Refer our Article!

 */


 //include software serial to communicate with Xbee

 #include


 //Create an instance for serial software

 SoftwareSerial xbee(10,11); //Digital pin 10- Xbee RX, Digital pin 11- Xbee TX


 void setup {

 // Initialize serial communication,

 //we configured our XBEE devices for 9600 bps.

 Serial.begin(9600);

 xbee.begin(9600);

 }


 void loop {

 //Check whether serial has something to send or not

 if(Serial.available >0)

 {

 //If serial has data to write, then pass that data to Xbee

 xbee.write(Serial.read );

 }


 //Check whether Xbee received something or not on software serial port.

 else if (xbee.available >0)

 {

 //If it received something, pass it to Arduino serial

 Serial.write(xbee.read );

 }


 }


 ###

Circuit diagrams

Circuit Diagram-IoT-Communication-Between-Two-Devices-Zigbee-IOT-Protocol-Part-37

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.