How to use XBEE module on Relay Shield for Arduino V2.1?

I’m looking to use the XBee module on the DFRobot’s Relay Shield for Arduino V2.1. However i am unable to make it work.

If anyone could point me to a tutorial/or code for basic serial in out to another xbee from the shield, I will greatly appreciate it.

Did you try the link to the Sample code on the link you provided?

The DFRobot Relay Shield for Arduino is used differently than most shields. To get power to it you need to:

  1. Unplug your USB cable used to upload your program and provide an external power source. I used 7.4v LiPo or 11.1v LiPo plogged into the power jack.
  2. To communicate with your XBEE or bluetooth module the shield uses the serial port so don’t use pins for TX and RX, simply use Serial.read() and Serial.print()
  3. After you upload your program, remove the USB cable and the “prog” switch to “Run” mode. Back to “Prog” when uploading a new program…and so-forth.
    Here is a simple LED on off to test it. I used a smartphone bluetooth app to send the data.

#include //Software Serial Port

#define Sketch_Name “BTC_XBEE_Relay_Slave_Led_2017_3_18”
//#define RxD 4
//#define TxD 5

#define PINLED 13

#define LEDON() digitalWrite(PINLED, HIGH)
#define LEDOFF() digitalWrite(PINLED, LOW)

#define DEBUG_ENABLED 1

//SoftwareSerial blueToothSerial(RxD, TxD);

void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(PINLED, OUTPUT);
LEDOFF();
Serial.print("Sketch: ");
Serial.println(Sketch_Name);

}

void loop()
{
char recvChar;

while (1)
{
if (Serial.available())
{ //check if there’s any data sent from the remote bluetooth shield
recvChar = Serial.read();
Serial.print("Command = ");
Serial.print(recvChar);

  if (recvChar == '1')
  {
    LEDON();
    Serial.println("; LED is ON");
    
  }
  else if (recvChar == '0')
  {
    LEDOFF();
    Serial.println("; LED is OFF");
    
  }
}

}
}

1 Like