Beginners (de)Bounce code on momentary buttons wont work.

Im trying to use two momentary buttons as digitial inputs to count up (+1) and down (-1) using the counter ‘x’. Im displaing the result on an LCD screen.

However the counter is going up by random amounts. I assume as a result of ‘bounce’

Why is my bounce code not working?

Any help much appreciated!


// include the library code:
#include <LiquidCrystal.h>
#include <Bounce.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int up = 3;         // the number of the input pin
int down = 4;

// Instantiate a Bounce object with a 5 millisecond debounce time
Bounce bouncerup = Bounce(up,5 );
Bounce bouncerdown = Bounce(down,5 );

int x = 0;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  pinMode(up, INPUT);
  pinMode(down, INPUT);

void loop() {
  bouncerup.update ( );
  bouncerdown.update ( );
  int readup =;
  int readdown =;

    if (readup == HIGH) {     
      x = x +1;
    if (readdown == HIGH) {       
      x = x -1;
  1. Do you have external pull-ups or pull-downs (or what) on the switch pins?

  2. What happens if you use the Bounce risingEdge() and/or fallingEdge() function instead of the read() function for the switches?

  3. If you have a few extra counts for either switch, then try increasing the debounce interval when you create the Bounce objects. If you have a whole lot of extra counts, then post again and describe your switch connections.



You are not using the internal pull-up resistors. Is it safe to assume that you have external pull-up or pull-down resistors with the switches? If so, how are they wired? If not, that is your problem.

I have connected it on my breadboard like this -

One side of the buttons are connected to ground via '10k 0.5W Metal Film Resistor' then to a digital pin on Arduino. Other side of button is connected to 5v.

Im getting about 30-50 extra counts per press.

How does my wiring look?

thanks again.

I hate to repeat myself but:

davekw7x: What happens if you use the Bounce risingEdge() ... function instead of the read() function for the switches?

Maybe like this:

  int readup = bouncerup.risingEdge();
  int readdown = bouncerdown.risingEdge()




For some reason your image at didn't show up with my browser. Looking at it now, it seems to match your description, and it matches my current hookup, which works for me (after changing your code the way that I indicated above.)


There is a question that I might have asked in my previous response. I'll ask it now:

With your original code, what happens if you press and hold one of the switches for a second or two before releasing instead of just "jabbing" it? That can, maybe, give a clue...