I'm writing a code for the Arduino at the moment to control the electromagnetic locks on the doors in my office, i have set the Arduino up on a circut that will receive infomation from an input (in this case a keypad) that will tell it to open the doors (by setting the output to the lock high). The code i have so far i think is pretty sweet, but my boss wants a time delay on the locks so that when the output goes high it continues to stay that way for approx. 5 seconds so that the lock is open for that time. i've been messing about for ages trying to work out how to do this. this is my current code without the time delay:
int potPin = 1;
int Pin = 13;
int val = 0;
void setup() {
pinMode(Pin, OUTPUT);
}
void loop() {
{val = analogRead(potPin);
if (val < 200) digitalWrite(Pin, HIGH);
else
if (val > 200) digitalWrite(Pin, LOW);}
}
can anyone suggest a way to put a time delay in or refine my code. thanks!