Skip to content

Instantly share code, notes, and snippets.

@buley
Created November 14, 2012 03:53
Show Gist options
  • Save buley/4070160 to your computer and use it in GitHub Desktop.
Save buley/4070160 to your computer and use it in GitHub Desktop.
Ardunio: PIR Sensor + LED Setup
boolean alreadyLow = true;
int pirPin = 3;
int ledPin = 2;
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
digitalWrite(pirPin, LOW);
pinMode(ledPin, OUTPUT);
}
void loop(){
if(HIGH == digitalRead(pirPin) && alreadyLow){
alreadyLow = false;
digitalWrite(ledPin, HIGH);
Serial.print("motion detected - ");
Serial.println(millis());
} else if( LOW == digitalRead(pirPin) && !alreadyLow){
alreadyLow = true;
digitalWrite(ledPin, LOW);
Serial.print("motion no longer detected - ");
Serial.println(millis());
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment