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"?


  • Mod

    @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.


Log in to reply
 

Suggested Topics

  • 4
  • 4
  • 9
  • 2
  • 17
  • 15

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts