const int switchPin = A6;
void setup() {
Serial.begin(9600);
pinMode(switchPin, INPUT_PULLUP); // Enable internal pull-up resistor on A6
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState == LOW) {
Serial.println("Switch ON");
} else {
Serial.println("Switch OFF");
}
delay(100); // Adjust delay as needed
}
This is the code im using to debug it, i have tried connecting the switch to 5v & A6, Gnd & A6 and A6 & Gnd using a 10k resistor but each time it just reads as switch on.
HIGH will return a value way bigger than 512, and LOW a value way smaller.
But why use analog pins at all? Maybe when you are pinched and have run out, just use digital pins and know that most so-called analog pins work perfectly well with digital read and write.