-
1Step 1
Source code:
int rolePin = 2; // pin that connects the relay int magnetPin = 3; // pin that connects magnetic switches int wait = 10000; // time to turn off light (in milliseconds) boolean doorStatus = false; void setup() { pinMode(rolePin, OUTPUT); pinMode(magnetPin, INPUT_PULLUP); } void loop() { int magnetState = digitalRead(magnetPin); if (magnetState == HIGH) { digitalWrite(rolePin, HIGH); doorStatus = true; } else{ if (doorStatus == true) { delay(wait); digitalWrite(rolePin, LOW); doorStatus = false; } } delay(5); }
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.