// ================================================================== // LED PIR SENSOR // // Alexander Revtsov, 14/09/2016 // ================================================================== const int sensorPin = 2; // PIR Sensor is attached to digital pin 2 const int ledPin = 13; // Built-in LED const int outPin = 3; // PWM output const int hand_modePin = 12; // hand mode pin 12 (0 = ON) const int ledBlinkTime = 500; // Blink one for half a second while calibrating long int max_delta = 10000L; // max time delay OFF int i = 0; int sensor = 0; // movie sensor: False int light = 0; // light of LED: from 0 to 63 long int last_millis = 0; long int delta = 0; // Wait for the sensor to calibrate (20 - 60 seconds according to datasheet) // 10 Seconds in milliseconds const long int calibrationTime = 10000L; int loga[64]= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 25, 28, 30, 33, 36, 39, 42, 46, 49, 53, 56, 60, 64, 68, 72, 77, 81, 86, 90, 95, 100, 105, 110, 116, 121, 127, 132, 138, 144, 150, 156, 163, 169, 176, 182, 189, 196, 203, 210, 218, 225, 233, 240, 248, 255 }; void setup() { pinMode(sensorPin, INPUT_PULLUP); pinMode(hand_modePin, INPUT_PULLUP); pinMode(ledPin, 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; i63) light=63; analogWrite(outPin, loga[light]); delay(40); } break; case 0: { // movie detecion false digitalWrite(ledPin,LOW); delta=millis()-last_millis; if(delta>max_delta) { // delay to OFF light--; if(light<0) light=0; analogWrite(outPin, loga[light]); delay(100); }} break; } }