Created
December 22, 2012 17:46
-
-
Save murphybytes/4360193 to your computer and use it in GitHub Desktop.
This Arduino sketch is used to interact with a motion sensor.
This file contains hidden or 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_pin = 13; | |
| int pir_pin = 2; | |
| int pir_state = LOW; | |
| int pin_status = 0; | |
| void setup() { | |
| pinMode( led_pin, OUTPUT ); | |
| pinMode( pir_pin, INPUT ); | |
| Serial.begin(9600); | |
| } | |
| void loop() { | |
| pin_status = digitalRead( pir_pin ); | |
| if( pin_status == HIGH ) { | |
| digitalWrite(led_pin, HIGH ); | |
| delay(150); | |
| if( pir_state = LOW ) { | |
| Serial.println( "Motion detected!" ); | |
| pir_state = HIGH; | |
| } | |
| } else { | |
| digitalWrite(led_pin, LOW ); | |
| delay( 300 ); | |
| if( pir_state = HIGH ) { | |
| Serial.println( "No motion" ); | |
| pir_state = LOW; | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment