Skip to content

HCDE439/ArduinoXBeeSendReceive-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Arduino XBee Send/Receive Example

A quick implementation of sending/receiving data via an XBee controller

Usage

Simply download a ZIP of this repository from this link and run the code on your Arduino.

What's going on?

Sending a message

xBee.println("buzzer");

Prints the string to the XBee controller (as opposed to Serial). Using println adds a newline, or '\n' after each message which helps segment messages on the receiving side.

Receiving a message

if (xBee.available() > 0) {
    char c = xBee.read();

    if (isAlphaNumeric(c) || c == ' ') {
        buff = buff + c;
    } else {
        /* Your code goes here */
        buff = "";
    }
}

This reads message data from the XBee controller until we find a character that is not a letter, number, or space (such as a newline, or '\n'). Then we act on it and reset buff to read the next message.

Making a Decision

if (buff.equals("buzzer")) {
    tone(buzzerPin, 1000);
    delay(1000);
    noTone(buzzerPin);
}
else if (buff.equals("led")) {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
}

We can compare strings using equals. This returns a boolean for whether or not the strings are the same. There are other functions for comparing characters, splitting strings, etc. that can be found in the String() documentation.

License

TBA

About

A quick implementation of sending/receiving data via a serial

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages