Skip to main content

Section 3.9 Analog to digital converter (ADC)

Subsection 3.9.1 Reading values from the ADC

from machine import ADC, Pin
from time import sleep

adc = ADC(Pin(35))

# Can change the voltage range with
#adc.atten(ADC.ATTN_11DB)

while True:
    raw = adc.read()
    volts = raw * 1.0 / 4096
    print("measured {} V ({})".format(volts, raw))
    sleep(0.1)