Button with INPUT_PULLUP not working

Hi,
I have an Arduino Leonardo pro micro clone and wanted to do a simple project, where the internal LED is controlled by a button. The button uses the pullup resistor of the pin.
The Problem is, that the press of the Button isn’t detected (the LED won’t turn on).

I correctly wired the button to pin 2 and gnd.


#include <Arduino.h>

void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(17, OUTPUT);
}

void loop() {
  if (digitalRead(2) == LOW) {
    digitalWrite(17, HIGH);
  } else {
    digitalWrite(17, LOW);
  }
}

Hi,
On Leonardo, onboard LED is pin D13.

Tom.. :grinning: :+1: :coffee: :australia:

Is it one of the popular 6mm tactile switches?

Untitled

If so, wire to diagonal terminals to avoid a short.

image

If this does not help, please post photos that clearly show your wiring.

Thank you for the fast answer. I rewired everything and now it works.

Then please flag the appropriate post as the solution, if someone helped.

You are welcome. Glad to see that it works.

If your question has been answered to your satisfaction, please mark the thread as solved so that other users that may want to help will not waste time opening the thread only to find the question has been answered.

Too late, but thanks!

Arduino Leonardo and SparkFun Pro Micro are different boards. so what board do you have?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.