// ================================================================== // RELAY PIR SENSOR // // Alexander Revtsov, 29/08/2016 // ================================================================== const int sensorPin = 2; // sensorPin const int ledPin = 13; // Built-in LED const int outPin = 3; // output pin const int hand_modePin = 12; // hand mode pin (0 = ON) const int ledBlinkTime = 500; // Blink one for half a second while calibrating long int max_delta = 10000L; // max time delay to OFF int i = 0; int sensor = 0; // movie sensor: False int light = 0; // light of LED: ON or OFF long int last_millis = 0L; long int delta = 0L; int calibrationTime = 10000; // Wait for the sensor to calibrate (20 - 60 seconds according to datasheet) // 10 Seconds in milliseconds void setup() { pinMode(sensorPin,INPUT_PULLUP); pinMode(hand_modePin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); pinMode(outPin, OUTPUT); // We need to wait one minute for the sensor to calibrate // Get out of view of the sensor for this duration! // Blink the LED while calibrating for (unsigned int i=0; i light ON switch(sensor) { case 1: { // movie detection true digitalWrite(ledPin,HIGH); digitalWrite(outPin,HIGH); delay(40); } break; case 0: { // movie detecion false digitalWrite(ledPin,LOW); delta=millis()-last_millis; if(delta>max_delta) { // delay to OFF digitalWrite(outPin,LOW); delay(100); }} break; } }