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