What is Analog Input?
While digital pins read only HIGH or LOW, analog input pins measure the actual voltage level and convert it to a number.
analogRead()
int value = analogRead(A0); // Returns 0-1023
- 0 = 0V at the pin
- 1023 = 5V at the pin
- 512 ≈ 2.5V at the pin
The ADC (Analog-to-Digital Converter)
The Arduino's built-in ADC has:
- 10-bit resolution: 1024 steps (0-1023)
- Voltage range: 0V to 5V (by default)
- Conversion time: ~100 microseconds per read
Analog Pins
| Pin | Name | |-----|------| | A0-A5 | Analog input pins (also usable as digital) |
Converting to Voltage
int raw = analogRead(A0);
float voltage = raw * (5.0 / 1023.0);
Serial.print("Voltage: ");
Serial.println(voltage);
Common Analog Sensors
| Sensor | Typical Range | |--------|--------------| | Potentiometer | 0-1023 (full range) | | Photoresistor | 0-1023 (varies with light) | | Temperature (TMP36) | ~150-350 | | Flex sensor | 200-800 |
Tips
- Analog pins don't need
pinMode()because they default to input - For stable readings, take multiple samples and average them
- Unused analog pins can pick up noise, so connect them to GND if not used