Simple Button Issue

I am trying to get a simple button as digital input on my Arduino Micro. Here is my code, using the internal pullup resistor. I have checked that the voltage across the button is working, but am not seeing any reaction in my serial monitor. Any advice?

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 7;     // the number of the pushbutton pin


// variables will change:
int buttonState = 1;         // variable for reading the pushbutton status

void setup() {

  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  // read the state of the pushbutton value:
 buttonState = digitalRead(buttonPin);
  Serial.println(buttonState);
}

Whole code, please. Variable declarations may or may not have something to do with it.

Ok updated, thanks!

You neglected to call the begin () method for the serial object.

  Serial.begin(115200);

Make sure the serial monitor is set to 115200.

a7

1 Like

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