Make a couple changes:
pinMode(buttonPin, INPUT_PULLUP); // turn on internal pullup resistor
Wire the button to connect the pin to Gnd when pressed.
Then change the checking logic:
if (buttonState == LOW) { // was button pressed?
Make a couple changes:
pinMode(buttonPin, INPUT_PULLUP); // turn on internal pullup resistor
Wire the button to connect the pin to Gnd when pressed.
Then change the checking logic:
if (buttonState == LOW) { // was button pressed?