How to determine the battery percentage using an android app?

Hi guys,

If possible, I'd like to ask on how can I program a sketch wherein it determines the percentage of the battery that powers the whole device. The battery percentage will be sent to the android app.

I currently assembled:

  • Arduino UNO
  • SIM900 GSM/GPRS Shield
  • MQ-2 Gas Sensor
  • ESP-01 (ESP8266)

The whole machine will be powered by a 9V battery connected to the gsm shield.

Thanks a lot!

P.S. The gsm shield on fritzing isn't the exact type of the SIM900 one, just like the MQ-3 (it should be MQ-2 but couldn't find one).

Because you are powering the arduino from the battery you want to measure you need to add two resistors to form a voltage divider which is dimensioned so that 9V equals 1.1V (or better 1V) on the output.
Than switch the analog reference of the arduino to the internal 1.1V reference, which is stable against the supply voltage.
For the conversion of measured battery voltage (from the voltage divider) to a percentage you need to know the discharge curve of your battery.

LightuC:
Because you are powering the arduino from the battery you want to measure you need to add two resistors to form a voltage divider which is dimensioned so that 9V equals 1.1V (or better 1V) on the output.
Than switch the analog reference of the arduino to the internal 1.1V reference, which is stable against the supply voltage.
For the conversion of measured battery voltage (from the voltage divider) to a percentage you need to know the discharge curve of your battery.

I can't quite grasp what you just said since it is too technical (sorry!). Can you share a breadboard view so I can follow through?

Thank you so much for your reply. I appreciated it :slight_smile:

Something like this should work (I used an online calculator so it is advised, that you measure the output voltage yourself).

voltage_divider.jpg

voltage_divider.jpg

iamdeadlyz:
The whole machine will be powered by a 9V battery connected to the gsm shield.

If you mean one of the PP3 style smoke alarm batteries then you might wish to reconsider. I doubt if it will last long enough for it to be worthwhile checking its capacity. A pack of 6 x AA alkaline cells would be much better.

...R

LightuC:
Something like this should work (I used an online calculator so it is advised, that you measure the output voltage yourself).

voltage_divider.jpg

Thank you so much! I'll be trying this one.
Cheers! :slight_smile:

Robin2:
If you mean one of the PP3 style smoke alarm batteries then you might wish to reconsider. I doubt if it will last long enough for it to be worthwhile checking its capacity. A pack of 6 x AA alkaline cells would be much better.

...R

I am planning to use a Energizer max 9v alkaline battery for this. Is it ok?

iamdeadlyz:
I am planning to use a Energizer max 9v alkaline battery for this. Is it ok?

This will last about a day, more or less.

LightuC:
This will last about a day, more or less.

Yikes! I should've researched more. Thanks for letting me know.
I guess it will be somewhat enough for testing purposes

iamdeadlyz:
Yikes! I should've researched more. Thanks for letting me know.
I guess it will be somewhat enough for testing purposes

Obviously this was a very rough estimation I made. I looked up the actual power consumptions:

MQ-2 150mA
Arduino ~25mA
Sim900(GPRS) 453mA
ESP32 (rx only) ~50mA

Current draw: 678mA

According to this the battery will last ~2h.

This can be improved a lot by powering down unused parts. For example, by only being active every 5minutes for 1 second, the battery life can be improved to ~500h.