Although microcontrollers are built around digital computers, often you’ll find yourself having to
interface with analog devices, such as controlling motors that require an analog input voltage or
reading sensors that output an analog signal.
For working with analog input signals, the Arduino includes an analog-to-digital converter (ADC).
The ADC converts an analog input signal into a digital value. The digital value is scaled based on the
value of the analog signal. Your Arduino sketch can read the digital value produced by the converter
and use it to determine the value of the original analog signal.
For most Arduino models, the ADC uses a 10-bit resolution to produce the digital value. Thus, the
digital values range from 0 for an input of 0 volts, to 1023, for an input of +5 volts.
Example Code
int analogInPin = A0; // Analog input pin that the potentiometer is attached to
int analogValue = 0; // variable to store the value coming from the analog pin
void setup() {
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop() {
analogValue = analogRead(analogInPin); // read the analog in value:
Serial.print("analogValue = "); // print the results to the Serial Monitor:
Serial.println(analogValue);
delay(1000); // wait 1 seconds
}