Neutrino
Published © CC BY

Xbee/Zigbee Setup with Arduino and NodeMCU

Basics on how to set up Zigbee using XCTU.

BeginnerProtip2 hours5
Xbee/Zigbee Setup with Arduino and NodeMCU

Things used in this project

Hardware components

SparkFun XBee Explorer Dongle
SparkFun XBee Explorer Dongle
×1
Arduino UNO
Arduino UNO
×1
Arduino Nano R3
Arduino Nano R3
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1

Software apps and online services

xctu
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter

Story

Read more

Schematics

Transmitter

transmitter circuit diagram

Receiver

receiver circuit diagram

Code

Transmitter code

Arduino
Upload this code to Arduino nano
#include "SoftwareSerial.h"

SoftwareSerial XBee(2,3);

int BUTTON = 5;
boolean toggle = false; //this variable keeps track of alternative click of the button

void setup()
{
    Serial.begin(9600);<br>
    pinMode(BUTTON, INPUT_PULLUP);<br>
    XBee.begin(9600);
}

void loop()
{
    //When button is pressed (GPIO pulled low) send 1

    if (digitalRead(BUTTON) == LOW && toggle)
    {
        Serial.println("Turn on LED");
        toggle = false;
        XBee.write('1');
        delay(1000);
    }

    //When button is pressed second time (GPIO pulled low) send 0
    else if (digitalRead(BUTTON) == LOW && !toggle)
    {
        Serial.println("Turn off LED");
        toggle = true;
        XBee.write('0');
        delay(1000);
    }
}

Receiver Code

Arduino
use this code for NodeMCU
#include<SoftwareSerial.h>

int led = 2;
int received = 0;
int i;

//For communicating with zigbee
SoftwareSerial zigbee(13,12);

void setup()
{
    Serial.begin(9600);
    zigbee.begin(9600);
    pinMode(led, OUTPUT);

}

void loop()
{
    //check if the data is received 
    if (zigbee.available() > 0)
    {
        received = zigbee.read();
        //if the data is 0, turn off the LED
        if (received == '0')
        {
            Serial.println("Turning off LED");
            digitalWrite(led, LOW);
        }
        //if the data is 1, turn on the LED
        else if (received == '1')
        {
            Serial.println("Turning on LED");
            digitalWrite(led, HIGH);
        }
    }
}

Credits

Neutrino

Neutrino

12 projects • 21 followers
Electrical Engineer and a programming hobbyist. I love to build exciting stuff!
Thanks to Lavanya R .

Comments

Add projectSign up / Login