arduino internal pull up resistor

const int buttonPin = 2; // Define the pin for the button
int buttonState = 0;     // Variable to store the button state

void setup() {
  pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as input with internal pull-up resistor
}

void loop() {
  buttonState = digitalRead(buttonPin); // Read the state of the button (HIGH or LOW)

  if (buttonState == LOW) {
    // Button is pressed, perform actions here
  } else {
    // Button is not pressed, perform other actions here
  }
}