Shares

ESP8266 ADC – Reading Analog Values with NodeMCU

Shares

Both ESP-12E and ESP-07 have an ADC pin that is easily accessible. This means that those ESP boards can read analog values from components, such as, temperature sensors, potentiometers, light sensors, etc.

Before you continue reading this project, please complete the following tutorials: 

If you like the ESP WiFi module and you want to build more projects you can download my eBook called “Home Automation using ESP8266” hereLet’s get started!

ADC Specifications

When referring to the ESP ADC pin you will often hear these different terms interchangeably:

  • ADC (Analog-to-digital Converter)
  • TOUT
  • Pin6
  • A0
  • Analog Pin 0

All these terms refer to the same pin in the ESP8266 that is highlighted in the next section.

Currently, TOUT (Pin6) has a 10-bit precision and its input voltage range is 0 to 3.3V when TOUT is connected to an external circuit.

Accessing the ESP8266 Analog Pin

With the ESP-12E is very easy to access the A0, you simply connect a jumper wire to the pin (see figure below).

With the ESP-07 you need solder a wire to that pin.

Parts List

Here’s the hardware that you need to complete this tutorial:

Flashing Your ESP with NodeMCU

In this tutorial we are going to use the NodeMCU firmware to read analog values.

You have to flash your ESPs with NodeMCU firmare.

Downloading ESPlorer IDE

I recommend using the ESPlorer IDE which is a program created by 4refr0nt to send commands to your ESP8266.

Follow these instructions to download and install ESPlorer IDE:

1) Click here to download ESPlorer

2) Unzip that folder

3) Go to the main folder

4) Run ESPlorer.jar

5) Open the ESPlorer

Info

According to the ESP8266 datasheet, the ADC pin has 10 bit resolution. This means that your analog reading will return a value between 0 to 1024.

The ADC only converts voltage between 0 and 3.3Volts. So before you apply any voltage to your A0 pin, you need to make sure that you’re using a device that only outputs 3.3V. Otherwise you might need to use a voltage divider:

Note: with earlier versions of the ESP, the A0 pin operated at maximum voltage of 1.0V, so check your board A0 voltage before following the next circuit.

Final Circuit

Here’s the final circuit that you need to assemble:

  • red wire: 3.3V
  • orange wire: A0
  • black wire: GND

Testing the ADC Pin (A0)

To send commands with the ESPlorer IDE, you need to establish a serial communication with your ESP, follow these instructions:

1) Connect your ESP-12E or FTDI programmer to your computer

2) Set bad raute as 9600

3) Select your ESP-12E or FTDI programmer port (COM3, for example)

4) Press Open/Close

esplorer (1)

Then type the command “print(adc.read(0))” and click the button “Send” as shown below.

ESPlorer

It should return a value between 0 and 1024. Rotate your potentiometer and send the “print(adc.read(0))” command a few more times.

When your potentiometer is near 0V it prints 0 and when it reaches 3.3V it should print 1024.

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.

Leave a Comment:

Add Your Reply