Battery Door switch without debounce
-
I have a battery operated node with a door switch using sleep and no debouncer.
The node seem to work well but I have some thoughts about reliably in my sketch.
The first 2 lines in the "void loop()" is:
wait(50); // Short delay to allow switch to properly settle
value = digitalRead(BUTTON_PIN);
and the last is:
sleep(digitalPinToInterrupt(BUTTON_PIN), CHANGE, SLEEP_TIME);.
As I have understand, when the door e.g. is opened during sleep time the arduino wakes up and starts the loop from the beginning, is this correct?
If so, will "wait (50)" prevent "bouncing"?
-
@MagnusF as the sleep statement is the last entry in the loop, the next command from your loop will be the 50ms delay.
50ms should normally be sufficient for a mechanical switch to settle, so the value read will reflect the state of the switch.
Should your switch take longer than 50ms to debounce, the value read will be arbitrary.
-
@Yveaux Thanks, it helped me.
Suggested Topics
-
Update RF24 library to latest version
Bug Reports • 23 Mar 2014, 23:37 • andriej 24 Mar 2014, 22:52 -
is this project dead?
General Discussion • 5 days ago • perfectom 5 days ago -
Why is the output of ACS712 current measurement module unchanged?
General Discussion • 19 Jul 2021, 09:09 • Tessie T 17 days ago -
Code Garage to the rescue.
General Discussion • 11 Jan 2025, 11:25 • skywatch 5 days ago -
ESP32 with LoRa
General Discussion • 31 Jan 2023, 11:06 • dhanushmh 13 days ago -
No merge into master in the last 5 years, should we use development?
General Discussion • 23 Sept 2024, 17:48 • kiesel 21 days ago