Skip to content

Instantly share code, notes, and snippets.

@murphybytes
Created December 22, 2012 17:46
Show Gist options
  • Select an option

  • Save murphybytes/4360193 to your computer and use it in GitHub Desktop.

Select an option

Save murphybytes/4360193 to your computer and use it in GitHub Desktop.
This Arduino sketch is used to interact with a motion sensor.
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