door lock with Arduino and a servo
hi doing code want change servos going other way , time before locks again getting longer?
code: [select]
/*
doorsystem lock controller sketch
language: arduino
sketch open door if receives signal the
processing sketch handles rfid part. there two
buttons allow user open door (from inside) and
disconnect servo short periode of time (from outside)
can open door key.
created 23 march 2013
tjalling tolle
uses servo library arduino
*/
#include <servo.h>
const int buttonpin = 2; // number of pushbutton pin
const int powerpin = 4; // number of pushbutton pin
int currentangle = 0;
int requiredangle = 0;
servo myservo; // create servo object control servo
int buttonstate = 0; // variable reading pushbutton status
int timer = 0;
void setup() {
pinmode(buttonpin, input);
pinmode(powerpin, output);
serial.begin(9600);
myservo.attach(9); // attaches servo on pin 9 servo object
myservo.write(currentangle);
}
void loop() {
if(timer>0) {
requiredangle=189;
timer--;
}
else {
requiredangle=0;
}
if(currentangle==requiredangle) {
myservo.detach();
}
else {
myservo.attach(9); // attaches servo on pin 9 servo object
if(currentangle<requiredangle) {
currentangle++;
}
else {
currentangle--;
}
serial.print(currentangle);
serial.print("-");
serial.println(requiredangle);
}
myservo.write(currentangle);
if (serial.available() > 0) {
char in = (char) serial.read();
if(in=='y') {
timer=29999;
}
}
buttonstate = digitalread(buttonpin);
if (buttonstate == high) {
timer=29999;
}
}
quote
but want change servos going other way
code: [select]
servo.write(180 - thepos);
(assuming 180 degree servo)
quote
and time before locks again getting longer?
assign different value timer. you'll have change type of timer long.
why detaching , reattaching servo? has no impact on amount of energy uses.
Arduino Forum > Using Arduino > Programming Questions > door lock with Arduino and a servo
arduino
Comments
Post a Comment