Don’t Forget Your Keys (Part 2)

The switch is activated.
The switch is activated.

So to be 100% honest I forgot to take a picture of my circuit before I disassembled it and I just didn’t feel making it again just to take a picture. However, because my project this week tied in to last weeks switch I just reused that picture. So I’ll just describe everything and I swear it works. The idea was that if the keys were on the hook and the door was closed one LED would flash on and off. If the key was on the hook but the door was opened the LED would stay on constantly and a buzzer would go off. If the key wasn’t on the hook though nothing would happen. To keep things simple though I just used two panic button switches instead of using the key and door switches. Below is the code for this. Also I couldn’t get the buzzer to work so I just used two LED lights instead.

void setup(){
pinMode(8,INPUT);
pinMode(7,OUTPUT);
pinMode(13,INPUT);
pinMode(12,OUTPUT);
}
void loop(){
if (digitalRead(8) == HIGH){
if (digitalRead(13)==HIGH){
digitalWrite(7,HIGH);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(7,LOW);
digitalWrite(12,LOW);
delay(1000);
}
else {digitalWrite(7,HIGH);
digitalWrite(12,HIGH);}
}
else {digitalWrite(7,LOW);
digitalWrite(12,LOW);
}
}

Leave a Reply