Analog to digital conversion is the ability to read a voltage level found on a pin between 0 and some maximum value and convert that analog value into a digital representation . Varying the voltage applied to the pin will change the value read. The ESP32 has an analog to digital converter built into it with a resolution of up to 12 bits which is 4096 distinct values. What that means is that 0 volts will produce a digital value of 0 while the maximum voltage will produce a digital value of 4095 and voltage ranges between these will produce a correspondingly scaled digital value.One of the properties on the analog to digital converter channels is attenuation. This is a voltage scaling factor. Normally the input range is 0-1V but with different attenuations we can scale the input voltage in to this range. The available scales beyond the 0-1V include 0-1.34V, 0-2V and 0-3.6V.
ESP32 Wroom Pin Out
Here is an example application using the Arduino IDE. What this example does is print the
value read from the ADC every 100m second.
Arduino Code for Reading ESP32 Analog Input
/* AnalogReadSerial ESP32 ADC example Reads an analog input on ADC1_0, prints the result to the Serial Monitor. Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). Attach the center pin of a potentiometer to pin A0, and the outside pins to +3.3V and ground.
Note: that only a subset of ADC pins and functions are exposed. First, the supplied drivers expose only ADC1. The board layout of the ESP32-DevKitC only exposes some of the pins. Specifically, the following are exposed: ADC1_CH0 , ADC1_CH3 , ADC1_CH4 , ADC1_CH5 , ADC1_CH6 and ADC1_CH7 .
Open Serial monitor from tools menu and set it at baud rate of 9600. If you see some garbage manually reset the ESP32 DevKit board.