push button/One press, one action/09. When a press does nothing
One press, one action · 09 of 9

When a press does nothing

Press and look at the red LED first. Lit means the block, VCC and GND are fine and the fault is between SIGNAL and your sketch. Dark means the block has no supply. Then there are three sketch faults: a test for LOW, no debounce, and INPUT_PULLUP.

Five symptoms

When a press does nothing
What it does
The red LED lights from VCC through the switch, with no code involved. If it stays dark when you press, the block has no supply: VCC is not connected, GND is not connected, or the cable is one pin over. Count from the square pad.

Pick what the button is doing. The ringed part of the board is where to look first, and the list beside it is the order to check in, by how often each one is the answer.

The LED stays dark

The red LED is wired from VCC, through the switch, to ground. No code is involved, so a dark LED on a press is always the supply. VCC is not connected, or GND is not, or the cable is one pin over. Count from the square pad: GND, VCC, NC, SIGNAL.

The LED lights, and the sketch sees nothing

The press reached SIGNAL, so the block is fine. BUTTON_PIN is a GPIO number, the one printed beside the pin on your board, not a count along the header. Then the SIGNAL wire itself. Then the ground: if the block is powered from somewhere other than the board reading it, the two need a GND wire between them.

It reads pressed when it is not

Nearly always a sketch written for a pull-up button board, which treats LOW as the press. On this block LOW is released. Test for HIGH. The other cause is SIGNAL on a 3V3 or 5V pin by mistake, where it reads HIGH forever.

One press counts as several

Contact bounce, and the block is fine. Add the debounce window. If the count jumps by dozens rather than two or three, the sketch counts every pass of loop() while the pin is HIGH instead of the change to HIGH.

Presses nobody made

The pull-down only holds SIGNAL at 0 V if SIGNAL reaches your pin. A loose or missing SIGNAL wire leaves the pin floating, and a floating pin reads noise. Then check the sketch for INPUT_PULLUP: with it, the chip's pull-up and the block's pull-down share the line, and the released level sits around a volt, where a pin may read either way.

When it does not work

How can I test the block without any code?

Wire GND and VCC only, and press. The red LED should light while the button is down and go out when you let go. If it does, the switch, the resistors and the supply are all fine, and anything left is SIGNAL's wire or the sketch.

Which ESP32 pins should I avoid for the button?

The flash pins, which stop the board booting if touched, and the strapping pins read at reset, 0, 2, 5, 12 and 15: a button held down during a reset could change how the chip starts. The input-only pins 34 to 39 are fine for a button. GPIO 25 is used here because it has no job at boot.

It worked yesterday and does nothing today.

Look for a wire that has come out of the breadboard. The right-angle header pins lie flat, and a cable's weight can pull the block out of its row. Press it back in, or use a TinkerBlock cable instead of a breadboard.

The count is right but the reaction feels slow.

Something in loop() is blocking: a delay() left over from the first sketch, or a long print. The debounce only waits 20 ms; anything slower than that is the rest of the sketch. Find the call that waits.

Where this goes next

Forty-odd blocks, and the push button is the input most of the others' lessons are started with.

Back to the blocks

Edit this page — content/books/push-button/when-a-press-does-nothing.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Push Button

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum