Skip to content

Analog Input (ADC) — Voltage (esp32_adc_volt)

What it does: Reads the voltage on the selected ESP32 ADC pin and returns it as mV or V.

Inputs

  • pin: ADC pin number.
  • Field Unit: output unit millivolts (mV) or volts (V).

Output

  • numerical voltage value (Number).

When to use it

  • if you want to measure the voltage from a potentiometer, divider or analog sensor directly in voltage units.
  • when you don't want to work with a raw ADC value and you just need mV or V directly.

Tips and pitfalls

  • The block uses machine.ADC(..., atten=ADC.ATTN_11DB) so it is suitable for higher analog voltages on the ESP32.
  • read_uv() returns microvolts, so the output after division is often decimal.
  • For clear output on the display or in the log, you can round the result with the block round_decimals.
  • When choosing mV, the value is divided by 1000, when choosing V, it is divided by 1000000.

Generated Python example

import machine
adc_uv34 = machine.ADC(machine.Pin(34, mode=machine.Pin.IN, pull=None), atten=machine.ADC.ATTN_11DB)
napeti = adc_uv34.read_uv()/1000