Page 1 of 1

How to measure voltage of battery using ESP32 internal reference voltage?

Posted: Sun May 23, 2021 6:59 pm
by andrewkeir
When using the internal 1.1V reference voltage, I powered an ESP32 with 5V USB and measured a 1.5V source using one of the ADC inputs, this got me 4095 as the ADC measurement which was expected as 1.5>1.1. However, when powering the ESP32 with a 3.3V battery directly with the 3.3V port, I got an ADC value of ~1600 which is completely wrong. This is the code I used (using Arduino IDE) and the ADC port was GPIO36.

Code: Select all

#include "esp_adc_cal.h"
 
void setup() {
  
  adc1_config_width(ADC_WIDTH_12Bit);
  adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_0db); //set reference voltage to internal
  
}

void loop() {

  int adcValue = adc1_get_raw(ADC1_CHANNEL_0);

}

Re: How to measure voltage of battery using ESP32 internal reference voltage?

Posted: Sat May 29, 2021 3:50 am
by becorey
See https://github.com/espressif/arduino-esp32/issues/1804

1.5 / 3.9 * 4095 = 1575, it's about what you'd expect