Can I Use Analog Pins as Digital Pins?
Yes. On most Arduino boards, analog pins can be used as regular digital pins. They are usually labeled A0 to A5.
How to use them
Use the analog pin label in your code:
pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);Limits to keep in mind
- When used as digital pins, they cannot read analog values at the same time.
- Some boards map A0 to a digital number. Check your pinout.
- ESP32 analog pins are not all safe for digital output. Check your board docs.
Bottom line
Analog pins can be extra digital pins when you run out, but check your board pinout first.
Related: What is the difference between digital and analog pins? · Why does analogRead give values 0 to 1023? · Why does analogWrite not work on this pin?