Skip to content

Instantly share code, notes, and snippets.

@e-Gizmo
Created August 27, 2018 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-Gizmo/aa6a8a646af07105e9809f8a04156fa4 to your computer and use it in GitHub Desktop.
Save e-Gizmo/aa6a8a646af07105e9809f8a04156fa4 to your computer and use it in GitHub Desktop.
/*
Motion Detector using PIR Human Motion sensor
This is an example sketch where you will determine if there's
a motion on your surrounding with LED indicator. Motion Detected,
LED is HIGH.
*/
int LED_INDICATOR = 13;
int PIR_SENSOR = 2;
int STATS = LOW;
int VALUE = 0;
void setup() {
Serial.begin(9600);
pinMode(LED_INDICATOR, OUTPUT);
pinMode(PIR_SENSOR, INPUT);
}
void loop(){
VALUE = digitalRead(PIR_SENSOR);
if (VALUE == HIGH) {
digitalWrite(LED_INDICATOR, HIGH);
delay(100);
if (STATS == LOW) {
Serial.println("MOTION DETECTED! - HIGH");
STATS = HIGH;
}
}
else {
digitalWrite(LED_INDICATOR, LOW);
delay(200);
if (STATS == HIGH){
Serial.println("MOTION STOPPED!");
STATS = LOW;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment