const int buttonPin = A5; // Define the button connected to analog pin A5
int buttonState; // Variable to store the button state
void setup() {
pinMode(buttonPin, INPUT); // Set the pin as input mode
Serial.begin(9600); // Initialize serial communication
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the button state
if (buttonState == HIGH) { // If the button is pressed (connected to +5V)
Serial.println("Button is pressed");
Serial.println(analogRead(A5));
} else { // If the button is not pressed (pulled down to GND)
Serial.println("Button is not pressed");
Serial.println(analogRead(A5));
}
delay(200); // A short delay to avoid jitter and reduce serial output
}