Skip to content

Instantly share code, notes, and snippets.

@seaneshbaugh
Created February 9, 2013 08:56
Show Gist options
  • Save seaneshbaugh/4744633 to your computer and use it in GitHub Desktop.
Save seaneshbaugh/4744633 to your computer and use it in GitHub Desktop.
Arduino Sketches
int pirPin = 2;
int piezoPin = 12;
int pirState = LOW;
int pirInputValue = 0;
void setup() {
pinMode(piezoPin, OUTPUT);
pinMode(pirPin, INPUT);
Serial.begin(9600);
}
void loop() {
pirInputValue = digitalRead(pirPin);
if (pirInputValue == HIGH) {
tone(piezoPin, 1000);
if (pirState == LOW) {
Serial.println("Motion detected!");
pirState = HIGH;
}
} else {
noTone(piezoPin);
if (pirState == HIGH) {
Serial.println("Motion ended!");
pirState = LOW;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment