Hi!
I have been going through the Wireless Sensors Network book and have tried taking the "romantic light sensor" chapter and trying to make it work with my project. It's somewhat the reverse of the model illustrated in there, but I borrowed a lot of the code....
What I am trying to do: I have a photoresistor connected to an arduino (analog input 0) with a xbee radio. I want the values from that photoresistor to be sent to the second xbee, which has no microcontroller, to light an LED. Basically, when xbee A sees light, I want xbee B to turn on an LED. Seems simple enough?
Right now, I have the arduino/sensor connected xbee set as a Coordinator in the API mode and the MCU-free xbee/LED set as an AT Router.
It isn't working. Does the sensor need to be the router? Do they both need to be in API mode? Or AT mode? What can I do to make the two xbees talk?
Maybe my code is broken?
#define VERSION "1.02"
int LED = 11;
int debugLED = 13;
int analogValue = A0;
int remoteIndicator = false; // keeps track of the desired remote on/off state
int lastRemoteIndicator = false; // record of prior remote state
unsigned long lastSent = 0; // records last time the remote was re-set to keep it in sync
void setup() {
pinMode(analogValue,INPUT);
pinMode(debugLED,OUTPUT);
Serial.begin(9600);
}
void loop() {
int analogHigh = analogRead(analogValue);
int analogLow = analogRead(analogValue);
analogValue = analogLow + (analogHigh * 256);
if (analogValue > 0 && analogValue <= 50) {
Serial.print(0x7E, BYTE); // start byte
Serial.print(0x0, BYTE); // high part of length (always zero)
Serial.print(0x10, BYTE); // low part of length (the number of bytes that follow, not including checksum)
Serial.print(0x17, BYTE); // 0x17 is a remote AT command
Serial.print(0x0, BYTE); // frame id set to zero for no reply
// ID of recipient, or use 0xFFFF for broadcast
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(0xFF, BYTE); // 0xFF for broadcast
Serial.print(0xFF, BYTE); // 0xFF for broadcast
// 16 bit of recipient or 0xFFFE if unknown
Serial.print(0xFF, BYTE);
Serial.print(0xFE, BYTE);
Serial.print(0x02, BYTE); // 0x02 to apply changes immediately on remote
// command name in ASCII characters
Serial.print('D', BYTE);
Serial.print('0', BYTE);
// command data in as many bytes as needed
Serial.print(4, BYTE);
// checksum is all bytes after length bytes
long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '1' + value;
Serial.print( 0xFF - ( sum & 0xFF) , BYTE ); // calculate the proper checksum
delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)
}
if (analogValue > 50) {
Serial.print(0x7E, BYTE); // start byte
Serial.print(0x0, BYTE); // high part of length (always zero)
Serial.print(0x10, BYTE); // low part of length (the number of bytes that follow, not including checksum)
Serial.print(0x17, BYTE); // 0x17 is a remote AT command
Serial.print(0x0, BYTE); // frame id set to zero for no reply
// ID of recipient, or use 0xFFFF for broadcast
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(00, BYTE);
Serial.print(0xFF, BYTE); // 0xFF for broadcast
Serial.print(0xFF, BYTE); // 0xFF for broadcast
// 16 bit of recipient or 0xFFFE if unknown
Serial.print(0xFF, BYTE);
Serial.print(0xFE, BYTE);
Serial.print(0x02, BYTE); // 0x02 to apply changes immediately on remote
// command name in ASCII characters
Serial.print('D', BYTE);
Serial.print('0', BYTE);
// command data in as many bytes as needed
Serial.print(5, BYTE);
// checksum is all bytes after length bytes
long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '1' + value;
Serial.print( 0xFF - ( sum & 0xFF) , BYTE ); // calculate the proper checksum
delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)
}
}
Please help, I've been pulling my hair out for days!!!