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 -
Code Garage to the rescue.
General Discussion • 11 Jan 2025, 11:25 • skywatch 11 days ago -
Why is the output of ACS712 current measurement module unchanged?
General Discussion • 19 Jul 2021, 09:09 • Tessie T 23 days ago -
Which device I have to use to connect with accelerometer before connecting to my pc?
General Discussion • 24 Jan 2023, 17:16 • Yada Kijsathan 16 Mar 2025, 20:17 -
is this project dead?
General Discussion • 11 days ago • perfectom 2 days ago -
ESP-NOW
General Discussion • 22 Apr 2018, 05:58 • NeverDie 17 Feb 2025, 22:24