The video covers using PIR (Passive InfraRed) sensors with an Arduino. These are simple movement sensors and although libraries are available they are not required to work with these devices. The sample code shown in the video is shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* XTronical PIR demo * Use/amend in any way you wish * No warrenty at all. */ int LED = 13; // LED for Uno, may be different on Nano etc. int PirSignal = 2; // The middle signal pin, high for detection, low for none bool LastDetection = false; // PIR status, true if detected uint16_t DetectionCounter=0; // Keep track of number of detections bool Detected=false; // Current value from signal pin void setup() { pinMode(LED, OUTPUT); pinMode(PirSignal, INPUT); Serial.begin(9600); // Ensure your derial monitor is also set to this speed } void loop(){ Detected=digitalRead(PirSignal); if((Detected)&(LastDetection==false)) // If something detected and not already flagged as detected { LastDetection=true; DetectionCounter++; digitalWrite(LED, HIGH); // turn LED ON Serial.print(DetectionCounter); Serial.println(" detections so far."); } if((Detected==false)&(LastDetection)) // If no current detection and last detection was high { // clear the dection flag LastDetection=false; Serial.println("Timer ended."); digitalWrite(LED, LOW); // turn LED off } } |