PyRasp

← All practice problems

Raspberry Pi Pico practice problem · Raspberry Pi Pico

Read a voltage

MediumBudget $3MicroPython

Two 10 kΩ resistors make a divider from 3V3 to GND, with the middle on GP26. That is about half of 3.3 V — around 1.65 V (real resistors vary by a few percent).

Use machine.ADC to read the pin and print the voltage in volts, rounded to two decimals:

adc = ADC(26)
volts = adc.read_u16() * 3.3 / 65535

The console should show a single line like 1.65 (1.60–1.72 with real parts).

More in Raspberry Pi Pico