|
Hi libelium-dev,
I used this code to detect motion for an amount of time. If it senses motion it will light an LED, if the motion stops the LED will stop. The LED will keep blinking even though there is no movements. I've tried putting the waspmote inside a box. It will still detect movements even inside the box. Is it something wrong with my code or is the PIR Sensor faulty?
This is my code,
int calibrationTime = 10; long unsigned int lowIn; long unsigned int pause = 5000; boolean lockLow = true; boolean takeLowTime;
void setup() { XBee.setMode(XBEE_ON); SensorEvent.setBoardMode(SENS_ON); XBee.println("Init RTC"); RTC.ON(); RTC.setTime("11:08:08:02:16:10:00"); XBee.print("calibrating sensor"); for(int i=0; i < calibrationTime; i++) { XBee.print("."); delay(1000); } XBee.println(" done"); XBee.println("SENSOR ACTIVE"); delay(50); }
void loop() { if(SensorEvent.readValue(SENS_SOCKET7) == 1) { Utils.setLED(LED0, LED_ON); if(lockLow) { lockLow = false; XBee.println("---"); XBee.print("motion detected at "); XBee.print(millis()/1000); XBee.println(" sec"); XBee.println(RTC.getTime()); delay(50); } takeLowTime = true; } if(SensorEvent.readValue(SENS_SOCKET7) == 0) { Utils.setLED(LED0, LED_OFF); if(takeLowTime) { lowIn = millis(); takeLowTime = false; } if(!lockLow && millis() - lowIn > pause) { lockLow = true; XBee.print("motion ended at "); XBee.print(millis()/1000); XBee.println(" sec"); XBee.println(RTC.getTime()); delay(50); } } }
Best Regards.
|