Reputation: 169
My circuit to measure battery right now is esp32, nrf24l01, and 18650. I powered up esp32 with 18650 3.6V nominal/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
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));
Upvotes: 0
Views: 1899
Reputation: 1897
I am assuming you are using ESP32-WROOM-32 module.
Your register divider should be connected to SENSOR_VP (VP) pin if you wish to read from channel ADC1_CHANNEL_0 and not EN pin.
ADC1_CHANNEL_0 is mapped to SENSOR_VP (VP) pin.
Your EN pin should be to +3.3VDC through an RC network (R-> 10k and C-> 0.1uF). I doubt if your module is even booting as it is active high and needs 150uS delay before going high after every reset.
Make sure you execute adc1_config_width()
and adc1_config_channel_atten()
before the first time adc1_get_voltage()
is called.
Upvotes: 1