-1

I'm using an ESP12F microcontroller powered by a 3.7V battery.

What I want is to get actual information about the battery's state of charge. So to know when the battery needs to recharge.

To achieve this I created a voltage drop from 3.7V to 0.94V (because I read that ADC pin of esp12f operates between 0V - 1V) with 3k and 1k ohm resistors and connected the V out of the voltage drop to the ADC pin. But the analog read is constantly 1024 and doesn't change. When I drop voltage to 0.54V analog read is again 1024. I tried with second esp12f and the result is the same. When I try to read analog value from different components like a temperature sensor it all seems alright - analog value is ~500 and when temp rises the value goes up to ~650. I followed this article about how to read battery voltage but without success. I tried to do the same task with Arduino Uno instead of esp12f and everything works fine.

So based on these tests and observations, I think that there isn't a problem with the circuit because on Arduino Uno works fine, there isn't a problem with esp12f's ADC pin because with the temperature sensor the analog value is accurate.

To summarize: My problem is that the analog value from the battery is constantly 1024 and I can't get actual information about the battery's remaining voltage via esp12f.

In the image below is what my circuit looks like:

enter image description here

And this is the code of how I read the analog value:

const int analogPin = A0;
void setup()
{
    Serial.begin(115200);
}

void loop()
{
    int sensorValue = analogRead(analogPin);
    Serial.print("sensorValue: ");
    Serial.print(sensorValue);

    delay(1000);
}
12
  • 1
    First some off-topic notes: 1. Commonly you cannot conclude the charge of a rechargeable battery by its voltage. It has a reason why many battery management devices measure the current in and out the battery. 2. The sum resistance is quite low and presumably will discharge your battery more than the rest of your circuit. 3. You might want to add a capacitor in parallel to the low-end resistor to keep the voltage stable while the ADC samples. Commented Apr 29 at 5:44
  • 1
    Maximum operating voltage of an ESP8266 is 3.6v (read the datasheet), you can't connect a 3.7V directly to an ESP8266, not mentioned that when the battery is full charged, it could go up to 4.2V.
    – hcheung
    Commented Apr 29 at 13:13
  • 2
    So you measured 0.94V across the 3kOhm resistor? This is not the voltage the MCU sees. It sees the voltage across the 1kOhm resistor: 3.8V - 0.94V = 2.86V... -- Please measure the voltage between ADC input and GND. This is what the MCU converts. Commented Apr 29 at 20:11
  • 1
    @thebusybee makes a good point. And this means that your 1k Ohm resistor is actually around 10K in value. It is very easy to mistake a red band for an orange band on a resistor body. This has got to be the solution surely?
    – Lee-xp
    Commented Apr 30 at 8:22
  • 1
    @thebusybee, you were right! I swapped the resistors 1k ohm is the first and 3k ohm is the second. I measured the voltage between ADC pin and GND and now is 0.94V. The analog value I currently read is around ~940. I need to go back and read more about voltage dividers because this was a silly mistake of mine. My next steps will be to add resistors with bigger resistance so the battery won't discharge so fast and try to add a transistor too that will switch on the voltage divider only when I want to measure the battery voltage. Thank you very much both thebusybee and Lee-xp.
    – stanimirsp
    Commented Apr 30 at 20:01

1 Answer 1

1

As you confirm in a comment, you swapped the resistors. So the ADC input received a voltage too high, and the ADC returned always the maximum value.

With this principle schematic we can calculate the appproximate voltage:

schematic

simulate this circuit – Schematic created using CircuitLab

You used R1 = 1kΩ and R2 = 3kΩ, this gives V_ADC = 3.7V * R2 / (R1 + R2) = 3.7V * 3kΩ / (1kΩ + 3kΩ) = about 2,8V.

With the correct values of R1 = 3kΩ and R2 = 1kΩ it is V_ADC = 3.7V * R2 / (R1 + R2) = 3.7V * 1kΩ / (3kΩ + 1kΩ) = about 0.9V.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.