0% found this document useful (0 votes)
36 views

Xbee Relay Code - Arduino and Xbee Wireless Setup

This code summarizes an Arduino sketch that controls an LED using an XBee wireless module. When the Arduino receives a '1' or '2' from the XBee, it will turn an LED on or off respectively and send the data back. A second section of code is for controlling two LEDs to mimic an AC outlet by toggling them on and off with delays.

Uploaded by

Jonathan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Xbee Relay Code - Arduino and Xbee Wireless Setup

This code summarizes an Arduino sketch that controls an LED using an XBee wireless module. When the Arduino receives a '1' or '2' from the XBee, it will turn an LED on or off respectively and send the data back. A second section of code is for controlling two LEDs to mimic an AC outlet by toggling them on and off with delays.

Uploaded by

Jonathan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Xbee relay code--arduino and xbee wireless setup

int myData = 0; int const ledpin = 13; void setup(){ // Start up our serial port, we configured our XBEE devices for 9600 bps. Serial.begin(9600); pinMode(ledpin, OUTPUT); } void loop(){ if(Serial.available() > 0){ myData = Serial.read(); if(myData == '1'){ digitalWrite(ledpin, HIGH); Serial.print(myData,BYTE); } if(myData == '2'){ digitalWrite(ledpin, LOW); Serial.print(myData, BYTE); } else{ Serial.print(myData, BYTE); } } }

Code for the AC outlet Project


// this is where we will put our data int myData = 0; int const ledpin1 = 9; int const ledpin2 = 11; void setup(){ // Start up our serial port, we configured our XBEE devices for 9600 bps. Serial.begin(9600); pinMode(ledpin1, OUTPUT); pinMode(ledpin2, OUTPUT); } void loop(){ // handle serial data, if any if(Serial.available() > 0){ myData = Serial.read(); if(myData == '1'){ digitalWrite(ledpin2, LOW); delay(100); digitalWrite(ledpin1, HIGH); delay(100); Serial.print(myData,BYTE); delay(100); } if(myData == '2'){ digitalWrite(ledpin1, LOW); delay(100); digitalWrite(ledpin2, HIGH); delay(100); Serial.print(myData, BYTE); delay(100); } else{ Serial.print(myData, BYTE); } } }

You might also like