Hi I'm new to this forum and would like to ask for some advice.
I am making an auto-lock for my car and I have made my code.
The lock will send a pulse every 34 seconds if the conditions are met for example if the door is closed.
If the remote is pressed to open the door then reset the counter which will then allow you enough time before getting in the car to avoid the circuit tries to close the door.
int remote = 0;
int door = 1;
int lock = 2;
//int core_Open = 3;
//int Rescue_Button = 4;
void setup()
{
// Setting up things once when Auduino is first turned on.
// Setup pins
pinMode(remote, INPUT);
pinMode(door, INPUT);
pinMode(lock, OUTPUT);
//cli(); // disable global interrupts
//sei(); // enable interrupts
}
void loop()
{
// If door is closed, then lock
if(digitalRead(door) == LOW)
{
digitalWrite(lock, HIGH);
delay(500);
digitalWrite(lock, LOW);
}
else
{
digitalWrite(lock, LOW);
}
delay(34000);
// If remote is detected high then delay
if(digitalRead(remote) == HIGH)
{
delay(34000);
}
}
The problem is is that the 34 seconds isn't exact. It's always random between 34 seconds-1minute 20.
What can I do which will give me the exact time of my choosing?