Last active
January 31, 2018 11:00
-
-
Save JimishF/91e0e52fde0a273ec8ff5b6574872156 to your computer and use it in GitHub Desktop.
A PIR (passive infrared sensor) sensor is an electronic sensor that measures Infrared (IR) light radiating from objects in its field of view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int LED = 13; | |
int inputPin = 2; | |
int PIR_STATE = LOW; | |
int VALUE = 0; | |
void setup() { | |
pinMode( LED, OUTPUT ); | |
Serial.begin( 9600 ); | |
} | |
void loop() { | |
VALUE = digitalRead( inputPin ); | |
if ( VALUE == HIGH ) | |
{ | |
digitalWrite( LED, HIGH ); | |
if ( PIR_STATE == LOW ) | |
{ | |
// ————–we have just turned on | |
Serial.println( “Motion has been detected!” ); | |
PIR_STATE = HIGH; | |
} | |
} | |
else | |
{ | |
digitalWrite( LED, LOW ); | |
if (PIR_STATE == HIGH) | |
{ | |
// ———we have just turned off | |
Serial.println( “Motion has been stopped!” ); | |
PIR_STATE = LOW; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment