ESP8266 reading ADC data

The ESP8266 has in built single channel ADC that can measure between 0V and 1V with 10 bit resolution. To read higher voltages you need external voltage divider. ADC is available on ESP12.

Voltage Divider

Resistor voltage dividers are commonly used to create reference voltages, or to reduce the magnitude of a voltage so it can be measured.

Voltage Divider Circuit
Voltage Divider Circuit

Formula to find Vout is. Assume (R1+R2) =  10K for 5V input or higher depending on input voltage level and find R2.

For 5V use R1=8.2 K and R2=2.2 K

ESP8266 ADC Programming

ADC programming is similar to Arduino, Only difference is you have 0 to 1V with 10-bit resolution.

 * ADC reading in ESP8266

void setup() {
  Serial.begin(9600);  //Initialize serial

void loop() {
  int sensor;                 //Define variable to read ADC data
  sensor = analogRead(A0);    //Read ADC
  Serial.print("ADC Value:"); //Print Message
  Serial.println(sensor);     //Print ADC value
  delay(500);                 //Have some delay to make it visible


Observe the ADC value on serial monitor.

ADC Results
ADC Results


Leave a Reply