Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Battery Door switch without debounce
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Battery Door switch without debounce

Scheduled Pinned Locked Moved General Discussion
3 Posts 2 Posters 1.1k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MagnusF
    wrote on last edited by
    #1

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

    YveauxY 1 Reply Last reply
    0
    • M MagnusF

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

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

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

      http://yveaux.blogspot.nl

      M 1 Reply Last reply
      0
      • YveauxY Yveaux

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

        M Offline
        M Offline
        MagnusF
        wrote on last edited by
        #3

        @Yveaux Thanks, it helped me.

        1 Reply Last reply
        1
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        6

        Online

        11.7k

        Users

        11.2k

        Topics

        113.0k

        Posts


        Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular