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"? -
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. -
@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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login