Created
February 17, 2014 22:51
-
-
Save jonmarkgo/9060847 to your computer and use it in GitHub Desktop.
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
#include <Servo.h> | |
int pirPin = 2; //digital 2 | |
int servoPin = 12; //digital 12 | |
int lock = 0; | |
int unlock = 180; | |
Servo myservo; | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(pirPin, INPUT); | |
digitalWrite(pirPin, HIGH); //internal pull-up to activate PIR | |
myservo.attach(servoPin); | |
myservo.write(lock); | |
} | |
void loop(){ | |
int pirVal = digitalRead(pirPin); | |
if(pirVal == LOW){ //was motion detected | |
Serial.println("Motion Detected"); | |
if (myservo.read() >= 90) { | |
Serial.println("locking"); | |
myservo.write(lock); | |
} | |
else { | |
Serial.println("unlocking"); | |
myservo.write(unlock); | |
} | |
delay(3000); //pause to let the servo move | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment