3. Analog Input with ESP32 Using Micro-Python Programming
Today I'll show you how to read an analog value from any analog sensor using ESP32 and Micro-Python Programming. This is very useful when working with analog sensors like potentiometers, LDR, MQ sensors, etc.
Description:
There are several pins on the ESP32 that can use as analog pins- these are called ADC pins. Like - 0, 2, 4, 12, 13, 14, 15, 25, 26, 27, 32, 33, 34, 35, 36, and 39.
ESP32 ADC pins have 12-bit resolution by default. That means these pins read voltage between 0 and 3.3V and then return a value between 0 and 4095
Component use:
Pin Diagram -
Circuit Diagram
Code:
from machine import Pin, AD
from time import sleep
pot = ADC(Pin(34))
pot.atten(ADC.ATTN_11DB) # Full range: 3.3v
while True:
pot_value = pot.read()
print(pot_value)
sleep(0.1)C
Serial Monitor
Video:
What is that?