PROJECT - MEASURE ESP8266's SUPPLY VOLTAGE

Objective: use a built-in feature of the ESP8266 to measure the supply voltage.

You will need: ESP8266 - you don't even need a breadboard!

INTRODUCTION

ESP8266 on PCB

This project shows how to use the built-in feature that measures the supply voltage to the ESP8266. To use it you cannot also use the A0 pin - it needs to have nothing connected to it and be left floating.

The feature is set to be enabled or disabled when you compile the sketch. The feature is disabled by default, but to enable it you need to add the following statement to your sketch. It must be outside all functions and could usefully follow any #defines. The statement has to be placed outside functions because it is a macro and it expands to a function definition, which cannot be within another function.

ADC_MODE(ADC_VCC);

The example code sets up serial communications and then calls ESP.getVcc() which returns the voltage in millivolts. The returned value is divided by 1000.00 to obtain volts.

When you open the serial monitor, you should see a display similar to this. The 2.99 and 3.00 values are the supply voltage. You can switch off the timestamp feature by deselecting it at the bottom of the serial monitor window.

ESP8266 on PCB