Skip to content

Instantly share code, notes, and snippets.

@JimishF
Last active January 31, 2018 11:00
Show Gist options
  • Save JimishF/91e0e52fde0a273ec8ff5b6574872156 to your computer and use it in GitHub Desktop.
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.
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