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

andrewkeir
Posts: 1
Joined: Sun May 23, 2021 6:57 pm

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

Postby andrewkeir » Sun May 23, 2021 6:59 pm

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);

}

becorey
Posts: 92
Joined: Sat Mar 28, 2020 4:18 pm

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

Postby becorey » Sat May 29, 2021 3:50 am

See https://github.com/espressif/arduino-esp32/issues/1804

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

Who is online

Users browsing this forum: Google [Bot] and 38 guests