#define lockBTN 2
#define unlockBTN 3
#define Lsignal 4
#define Rsignal 5
#define buzz 6
#define relay1 7
#define relay2 8
int button1;
int button2;
void setup() {
// put your setup code here, to run once:
pinMode(lockBTN, INPUT_PULLUP);
pinMode(unlockBTN, INPUT_PULLUP);
pinMode(Lsignal, OUTPUT);
pinMode(Rsignal, OUTPUT);
pinMode(buzz, OUTPUT);
pinMode(relay1, OUTPUT);
}
void loop() {
//LED respresents the Forward and Reverse. Dont mind if it was lit when off
//since actuator consume a lot of current, it needs to be OFF.
//In car door lock acuator, if you trigger it forward and turn
//it off, the posistion still the same.
//and when you trigger reverse it the acuator will move opposite
//and turn it off, the position is till same.
//this is to conserve car battery.
doorLock();
doorUnlock();
}
void doorLock(){
button2 = digitalRead(unlockBTN);
if(button2 == LOW){ // Unlock the door
digitalWrite(relay1, HIGH); // this will turn the accuator ON
tone(buzz, 2200);
delay(10);
noTone(buzz);
digitalWrite(Lsignal, HIGH);
digitalWrite(Rsignal, HIGH);
delay(150);
digitalWrite(Lsignal, LOW);
digitalWrite(Rsignal, LOW);
delay(200);
tone(buzz, 2200);
delay(10);
noTone(buzz);
digitalWrite(Lsignal, HIGH);
digitalWrite(Rsignal, HIGH);
delay(150);
digitalWrite(Lsignal, LOW);
digitalWrite(Rsignal, LOW);
delay(500);
digitalWrite(relay1, LOW);
}
}
void doorUnlock(){
button1 = digitalRead(lockBTN);
if(button1 == LOW){ // Lock the door
tone(buzz, 2200);
delay(10);
noTone(buzz);
digitalWrite(relay2, HIGH); // this will turn the accuator ON
digitalWrite(Lsignal, HIGH);
digitalWrite(Rsignal, HIGH);
delay(200);
digitalWrite(Lsignal, LOW);
digitalWrite(Rsignal, LOW);
delay(500);
digitalWrite(relay2, LOW);
}
}