zachfejes / mandalorian_blaster_esp32

Code for my custom prop based on the blaster from The Mandalorian, based on ESP32 hardware.
0 stars 0 forks source link

Build basic scratch file and log the current state of a connected battery #2

Open zachfejes opened 4 years ago

zachfejes commented 4 years ago

This is a well-documented problem, and seems to be mostly done by reading the battery's voltage through one of the analog pins, and knowing the voltage vs. charge curve for the particular battery. Some solutions suggest building a voltage divider circuit to ensure that the voltage signal fits the board's tolerance range of the input pins. I've found a couple of projects with various levels of rigor which could be helpful here:

rlogiacco commented 4 years ago

Thanks for the mention! A little note: the voltage divider is not there for accuracy, but to bring the battery voltage range within IO pin tolerance: unless your board boosts up Vin, the battery is usually at a higher voltage than your board and you cannot measure anything higher than your board voltage. Once the battery Starts going down, the same happens to your board: when you power up a 5V Arduino board With a depleted 4.8V battery, your board voltage goes down to 4.8V... meaning the battery will stay at 100% until the board shuts down, if that makes sense....

zachfejes commented 4 years ago

That makes a lot of sense @rlogiacco ! Thanks for the insight - that makes a lot more sense.

rlogiacco commented 4 years ago

I must correct myself, at least in the example, but more probably the correction applies to other boards/mcu as well. The Atmel MCU powering the Arduino, and probably many other MCUs, uses an internal voltage reference which is at a much lower voltage than Vin, in this case at 1.1 V, which implies the above example is totally invalid.

When a 4.8 V depleted battery powers a 5 V Arduino board the Arduino is capable of determining the Vin is below the required voltage, at least until it browns out. Actually the brown out feature depends precisely on this internal voltage reference. Simply put, you can say "Input voltage is 85%", in total contrast with what I stated earlier: better late than never 😄