Noob here, I have been working on a project using an esp8266 with a r503 fingerprint sensor which includes a relay for a door lock, a buzzer and a reed switch for sensing if the door has been opened without fingerprint being authorized, which should turn on the buzzer.
But I cant manage to find a creative solution for my problem.
Also Is there a way to digitalRead a pin that is in output mode.
I dont know many options with coding like using the while function or boolean etc... but please can someone guide me whats my best way to make this run.
I have posted the code i was trying but didnt work for me
ex
if(digitalRead(switchReed !=LOW) && (digitalRead(relayPin == High) { //or some other solution from you guys
serialPrint("Authorized access")
} else if (digitalRead(switchReed !=LOW) && (digitalRead(relayPin != High) {
serialPrint("Intruder alert")
digitalWrite(buzzerAlarm, HIGH)
}
I much prefer to simplify complex IF tests - for example like this
if(digitalRead(switchReed !=LOW) {
if (digitalRead(relayPin == HIGH) { //or some other solution from you guys
serialPrint("Authorized access")
} else {
serialPrint("Intruder alert")
digitalWrite(buzzerAlarm, HIGH)
}
}
Better still, I like to read the pins prior to the IF tests as that allows me to print the values that are being considered by the tests if I need to. It also ensures that all the IF tests work from the same data.
reedSwitchState = digitalRead(switchReed);
relayState = digitalRead(relayPin);
if(reedSwitchState !=LOW) {
if (relayState == HIGH) { //or some other solution from you guys
serialPrint("Authorized access")
} else {
serialPrint("Intruder alert")
digitalWrite(buzzerAlarm, HIGH)
}
}
Even better is to handle the buttons with a debouncing library first, then you can code
entirely in terms of events (button up, button down), which hides a whole lot of
detail about the interface and keeps debouce logic out of the business logic (separation
of concerns is good!).
However this can be overkill in simple cases - probably good to have in a MIDI controller,
unnecessary if just lighting an LED!