Voltage Reader
An Arduino reads a two-resistor divider with analogRead and prints the voltage. Change a resistor and watch the reading follow.
- Beginner
- Analog Electronics
- 3 parts
Opens in your browser with the parts, wiring and code already in place. Press Run to watch it work, then change anything you like.
How it works
Two resistors, R1 of 10 kilohms and R2 of 4.7 kilohms, sit in a row between the board’s 5 volt pin and ground, and analog pin A0 is wired to the point between them. As in the Voltage Divider, the voltage there is the supply times R2 ÷ (R1 + R2), which is 5 × 4.7 ÷ 14.7, about 1.6 volts. A0 only listens: it draws almost no current, so it does not disturb the divider.
analogRead(A0) turns that voltage into a whole number from 0 (0 volts) to 1023 (5 volts), here about 327. The sketch turns it back into volts with raw × 5.0 ÷ 1023.0 and prints both numbers to the Serial tab twice a second. The reading comes from the circuit solver, which works out the voltage from the real resistors, so any divider you build gives the right number, not just this one.
Parts
- Arduino Uno
- 2 × Resistor
Wiring
- Arduino Uno 5V → Resistor 1 A
- Resistor 1 B → Resistor 2 A
- Resistor 1 B → Arduino Uno A0
- Resistor 2 B → Arduino Uno GND
Arduino code
// Voltage Reader
// R1 and R2 split the 5 V supply; A0 listens to the point between them.
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(A0);
float volts = raw * 5.0 / 1023.0;
Serial.print("A0 raw: ");
Serial.print(raw);
Serial.print(" volts: ");
Serial.println(volts);
delay(500);
}
Try changing it
- Select R2 and change its resistance to 10000. The two resistors are equal, so the reading falls to half the supply: about 512 raw, 2.5 volts.
- Make the readings come faster by changing delay(500) to delay(100).
- Add a capacitor from A0 to ground and watch the reading drift towards its final value instead of jumping.
Next challenge
More projects in Analog Electronics
- Voltage DividerTwo resistors share a supply voltage in proportion to their values. Measure the middle…
- Thermistor ThermometerA thermistor and a fixed resistor form a divider the Arduino reads. The sketch turns the…
- LED Current LimitingA resistor sets how much current an LED carries. Put a multimeter in series and see it.
- RC Low-Pass FilterA resistor and capacitor let slow signals through and soften fast ones. Watch both on an…