Adruino micro some pins stuck on high

Hi all,

I've just got an arduino micro and am reading the digital input pins. Some of them seem to be stuck on high, is this normal? The code below constantly prints out "pin2" even though nothing is connected to the board.

const int buttonPin = 2;
const int buttonPin2 = 3;

int buttonState = 0;
int buttonState2 = 0;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin2, INPUT);

  Serial.begin(9600);
}

void loop() {

  buttonState = digitalRead(buttonPin);
  buttonState2 = digitalRead(buttonPin2);

  if(buttonState == HIGH){
    Serial.println("pin2");
  }
    
  if(buttonState2 == HIGH){
    Serial.println("pin3");
  }

  delay(100);
}

That’s probably because you haven’t attached anything to it. It’s called an open connection and can be anything. To solve this you can use a pull down resistor :.

Or if you want them to be HIGH if nothing is connected, use the build in pull up resistors.

Yes, sorry you're right!