I have a simple network created using XBee Series 2 devices.

My network is very simple, my end-device with Arduino Uno read a temperature and Lightning, display this value into LCD and send using XBee to a coordinator. It is setting for sleep and wake up using PIN hibernation.

It is setting like End-Device AT mode.

I try to send a Remote AT command with XCTU from coordinator to my end device and it parse this command and response.

What I try to do is parse received packet into my Arduino code and decide what response (for example discharge it).

It is possible to do using only one Serial? The Arduino Uno and XBee are connected with an XBee shield.

I have try using this code but the Arduino don't display the packet received from the Coordinator.

This is my code:

#include <avr/sleep.h>
#define XBEE_sleepPin 7
#include <LiquidCrystal.h>

//Sensor variable
int sensorPin = 0;
int fotoResistenzaPin = A1;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String data = "";
String name = "Arduino1";

//Time Variable
unsigned long seconds = 1000L;
unsigned long minutes = seconds * 60;
unsigned long hours = minutes * 60;

void setup() {
  pinMode(fotoResistenzaPin, INPUT);
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.setCursor(0, 1);

void xbeesleep() {
  delay (300);
  pinMode (XBEE_sleepPin, OUTPUT);   // put XBee to sleep
  digitalWrite(XBEE_sleepPin, HIGH); // Setting this pin to LOW turns off the pull up resistor, thus saving precious current
  //delay(10 * minutes);
  delay(5 * seconds);

void xbeewake() {
  pinMode(XBEE_sleepPin, OUTPUT);  // Set the "wake-up pin" to output
  digitalWrite(XBEE_sleepPin, LOW); // wake-up XBee
  delay(10 * seconds); //make sure that XBee is ready, time to connect to Xbee Coordinator


void loop() {
 //wait message 
  if (Serial.available()>0) {

    //see if it is a Xbee packet
    if (Serial.read() == 0x7E) {

      for (int i = 0; i < 15; i++) {
        byte skip = Serial.read();

        //check if it is a Remote AT commnad
        if (skip == 0x17) {

            //do something when i find the Remote AT command packet
          lcd.setCursor(0, 0);
          lcd.print("Remote AT command ");

  int reading = analogRead(sensorPin);
  int val = analogRead(fotoResistenzaPin);
  float voltage = reading * 5.0;
  voltage /= 1024.0;

  float temperatureC = (voltage - 0.5) * 100 ;
  data = name + ',' + temperatureC + ',' + val;
  if (Serial) {
    lcd.setCursor(0, 0);
    lcd.print("Temp: ");
    lcd.print(" C");
    lcd.setCursor(0, 1);
    lcd.print("Lightning: ");
  else {
    lcd.setCursor(0, 0);
    lcd.print("Serial Error ");
    lcd.setCursor(0, 1);
    lcd.print("Stop Trasmission");



1 Answer 1


I'm not sure about this, but similar to any other serial communication modules used on the Arduino, you need to setup a software serial pins which act as Tx and Rx between the Arduino and the module, XBee in this case. Look at software serial. this should solve your problem. Then you can use the "Serial" object to debug your communication between the two. I have worked with both a GSM and a Wifi module and the method was the same as I have explained above.

  • That not correct for all Arduinos, some have multiple serial ports (Mega), but for the Uno (which it looks like this is) then its the right way of doing things. Commented Jun 29, 2017 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.