Floating pin with pullup and no external components

I have an Arduino Micro, and I'm trying to get the button example to work.
I'm getting a floating pin for some reason, in the end I disconnected everything, and still getting the same results. The serial monitor is showing a lot of '1's and '0's without anything connected to it, and using the internal pull-up.
What am I doing wrong?

const int pinButton = 2;
int buttonState = 0;
int previousButtonState = HIGH; 

void setup() {
  Serial.begin(9600);
  while (!Serial) ; 

  delay(1000);
}

void loop() {
  buttonState = digitalRead(pinButton);
  Serial.println(buttonState);

  if (buttonState == HIGH) {
    //digitalWrite(LED_BUILTIN, LOW);
  } else {
    //digitalWrite(LED_BUILTIN, HIGH);
  }
}

No schematic, no code tags.

No pinMode (though input is the default)

I'm not seeing that.

1 Like

Run pinMode() in setup() to clarify the purpose of the pin.

Sorry, my bad, had the issue with more code, made a smaller afterwards and forgot the pullup.

Added code tags.

Didn't add schematic as the problem was for no components attached.

I will try adding the button again and see what happens

FYI

1 Like

I was using INPUT_PULLUP, however, I have an Arduino Micro, not UNO.
Is there a similar diagram with which pins are best for pullup in the Micro board?

Got it to work now. thx for the help!

Digital pins are digital pins, the micro is similar in this respect.


Just poll the switch(s) every 50ms.

I got it to work with the debouncing example. Don't want to add too many delays if not needed. Thx anyway

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