Measure battery with adc internal
Posted: Thu Jul 04, 2019 3:55 am
my circuit to measure battery right now is esp32, nrf24l01, and 18650. i powered up esp32 with 18650 3.6v norminal/4.2 max battery. run a voltage divider 100k, 27k then it's 0.893v a measure point. at 3.6v measure point like ~0.72.
i use internal 1.1v adc but why i only receive ~3v at monitor
My circuit here
i use internal 1.1v adc but why i only receive ~3v at monitor
Code: Select all
adc1_config_width(ADC_WIDTH_BIT_11);
adc1_config_channel_atten(ADC1_CHANNEL_0,ADC_ATTEN_DB_0);
float battery_read()
{
//read battery voltage per %
long sum = 0; // sum of samples taken
float voltage = 0.0; // calculated voltage
float output = 0.0; //output value
const float battery_max = 4.2; //maximum voltage of battery
const float battery_min = 3.0; //minimum voltage of battery before shutdown
float R1 = 100000.0; // resistance of R1 (100K)
float R2 = 27000.0; // resistance of R2 (10K)
for (int i = 0; i < 100; i++)
{
sum += adc1_get_voltage(ADC1_CHANNEL_0);
delayMicroseconds(1000);
}
// calculate the voltage*/
voltage = sum / (float)100;
Serial.println(voltage);
voltage = (voltage *1.1) / 2047.0; //for internal 1.1v reference
// use if added divider circuit
voltage = voltage / (R2/(R1+R2));
}