Created
February 9, 2013 08:56
-
-
Save seaneshbaugh/4744633 to your computer and use it in GitHub Desktop.
Arduino Sketches
This file contains 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 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