Unit B - Inputs & Outputs

10. Analogue Inputs, ADC & Voltage Dividers

Measure voltage and scale readings into engineering values.

Estimated time 4 hours

Learning outcomes

  • Explain 10-bit ADC resolution
  • Wire a potentiometer as a divider
  • Convert ADC counts to volts
  • Use map and constrain appropriately

Parts and preparation

Uno, 10 k ohm potentiometer, breadboard, jumper wires and multimeter.

Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.

Analogue Inputs, ADC & Voltage Dividers instructional connection diagram
Open the diagram for a larger view. Trace every connection before building.

ADC conversion

On a 5 V Uno with the default reference, analogRead returns 0-1023 for approximately 0-5 V. One count is about 5 / 1023 = 4.89 mV.

Voltage divider

Two series resistances divide a supply. A potentiometer provides an adjustable ratio through its wiper.

Scaling

Voltage = raw * Vref / 1023.0. map performs integer linear scaling; constrain limits a value to a safe range.

Measurement uncertainty

USB 5 V is not an exact reference. Measure the actual 5 V rail when accuracy matters and average noisy readings.

Wiring and safe build sequence

Breadboard wiring for lesson 10: Analogue Inputs, ADC & Voltage Dividers
Breadboard layout for this lesson. Match colours and pins before powering the circuit. Click the image for a larger view.
  1. Pot outer leg -> 5 V
  2. Other outer leg -> GND
  3. Centre wiper -> A0
Power rule: switch off before moving wires. Arduino I/O pins are control signals; high-current loads require a driver and suitable external supply.
const byte sensorPin = A0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(sensorPin);
  float voltage = raw * (5.0 / 1023.0);
  int percent = map(raw, 0, 1023, 0, 100);

  Serial.print("ADC=");
  Serial.print(raw);
  Serial.print("  V=");
  Serial.print(voltage, 2);
  Serial.print("  %=");
  Serial.println(percent);
  delay(200);
}

How the code works

  1. 5.0 forces floating-point calculation.
  2. The ADC count and voltage should rise together as the wiper moves toward 5 V.

Test and record evidence

Expected result: The reading moves through about 0-1023, 0.00-5.00 V and 0-100%.

Practical evidence checklist

Common faults and checks
  • A fixed reading suggests the wiper is not connected to A0.
  • Erratic readings can indicate a missing GND or poor breadboard contact.
Extension challenge: Take ten readings, calculate their average and compare stability.

Check your understanding

Q1. How many codes does a 10-bit ADC have?

Show answer

1024 codes, numbered 0-1023.

Q2. Why use 5.0 instead of 5?

Show answer

To request floating-point division rather than integer arithmetic.