Bathroom Occupancy Monitor
My roommate is always frustrated with the rest of us making it into the bathroom before she does. Here is a remote bathroom occupancy system that can keep her in bed and happy. By utilizing the romantic light sensor workshop from last week, I was able to achieve the wireless communication between my two Xbees. The router is in a soup container placed inside of the bathroom and the coordinator is in a box by her bed side with two icon lights that allow her to know if the person has left, is only using for 5 min or for longer (taking a shower).
/*
* *********ROMANTICLIGHTING SENSOR ********
* detects whether your lighting is
* setting the right mood
* USES PREVIOUSLY PAIRED XBEE ZB RADIOS
* by Rob Faludi http://faludi.com
* and behnazbabazadeh π
*/
/*
*** CONFIGURATION ***
SENDER: (REMOTE SENSOR RADIO)
ATID3456 (PAN ID)
ATDH -> set to SH of partner radio
ATDL -> set to SL of partner radio
ATJV1 -> rejoin with coordinator on startup
ATD02 pin 0 in analog in mode
ATIR64 sample rate 100 millisecs (hex 64)
* THE LOCAL RADIO _MUST_ BE IN API MODE *
RECEIVER: (LOCAL RADIO)
ATID3456 (PAN ID)
ATDH -> set to SH of partner radio
ATDL -> set to SL of partner radio
*/
#define VERSION "1.02"
int ALED = 11;
int BLED = 12;
int debugLED = 13;
int analogValue = 0;
void setup() {
pinMode(ALED,OUTPUT);
pinMode(BLED,OUTPUT);
pinMode(debugLED,OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(analogValu);
// make sure everything we need is in the buffer
if (Serial.available() >= 21) {
// look for the start byte
if (Serial.read() == 0x7E) {
//blink debug LED to indicate when data is received
digitalWrite(debugLED, HIGH);
delay(10);
digitalWrite(debugLED, LOW);
// read the variables that we're not using out of the buffer
for (int i = 0; i<18; i++) { byte discard = Serial.read(); } int analogHigh = Serial.read(); int analogLow = Serial.read(); analogValue = analogLow + (analogHigh * 256); } } // if (analogValue > 0 && analogValue <= 350) { digitalWrite(ALED, LOW); digitalWrite(BLED, LOW); } // if (analogValue > 350 && analogValue <= 750) { digitalWrite(ALED, HIGH); digitalWrite(BLED, LOW); delay (10000); digitalWrite(ALED, LOW); digitalWrite(BLED, HIGH); delay(100000); } // if (analogValue > 750 && analogValue <= 1023) {
digitalWrite(ALED, LOW);
digitalWrite(BLED, LOW);
}
}

Reply