The sense pin wiring can vary depending on your battery configuration, but here are a few examples based on the assumption you are using a 5V board: in case of a 3.3V board you should be performing the necessary adjustments. To improve this we suggest using the VoltageReference library to obtain a better calibration value for all analog readings. If you want your readings to be more accurate we strongly suggest to calibrate the library by providing your board reference voltage: most of the times you assume your board has exactly 5V between Vcc and GND, but this is rarely the case. The library requires at least 1 analog pin (we will call this the sense pin) and no less than 2 pieces of info on your battery: the voltage you will consider the minimum acceptable level, below which your project/product becomes unreliable and should be shut down, and the maximum voltage you can expect when the battery is fully charged.Īdditionally, you can provide a second pin (either analog or digital) to activate the battery measurement circuit (we call it the activation pin), useful in all those situations where you can sacrifice a pin to further increase your battery duration. Higher than 5V, with external voltage regulator.Higher than 5V, with internal voltage regulator.In reality, the relation between battery capacity and its voltage is better represented by a curve and there are many factors affecting it: current drawn, temperature, age, etc. The big assumption here is that battery capacity is linearly correlated to its voltage: the assumption itself is wrong, but in most cases it's close enough to reality, especially when it comes to the battery higher capacity side. The principle is simple: we are going to measure our battery capacity by measuring the voltage across the battery terminals. This is a simple Arduino library to monitor battery consumption of your battery powered projects, being LiPo, LiIon, NiCd or any other battery type, single or multiple cells: if it can power your Arduino you can monitor it! Then, in the Arduino sketch, I'll start by including the library and initializing the sensor: # include "MAX17043.Please, before submitting a support request read carefully this README and check if an answer already exists among previously answered questions: do not abuse of the Github issue tracker. I'll start by adding it as a dependency to my platformio.ini file: lib_deps = There are several Arduino libraries for the MAX17042:īoth of these will work fine, even with breakout boards from different brands. Now that everything is wired up, we can start writing some code. That's why there are 2 additional wires in my setup. It only accepts power over USB or the battery connector. However, in this case, my ESP32 board can't be powered through its pins. The fuel gauge will pass along power to the microcontroller. Note: Normally, you only have to connect the battery to the fuel gauge, and the fuel gauge to your microcontroller. I'm using a 2000mAh LiPo battery and a LOLIN32 board (ESP32 based), but you can use any microcontroller you'd like, including an Arduino. Here's a simplified schematic that should work regardless of the breakout board you have: Wiring it upĬonnecting this breakout board to your microcontroller is easy: connect the power output to the VIN of your board and connect the SDA and SCL pins for i2c connectivity. Other brands have similar boards: SparkFun / AliExpress. It also has an interrupt pin, so you can have it wake your microcontroller when the battery dips below a certain level.Īnd even more good news: it's available as a breakout board for DIY projects, such as this one from DFRobot: It works through an i2c interface, and it can report the battery's percentage and voltage. It doesn't require resistors or calibration. This tiny chip uses the ModelGauge algorithm to measure a battery's capacity. Fuel Gauge: MAX17043Ī better solution is to use a "battery fuel gauge," such as the Maxim Integrated MAX17043 ( datasheet). It's challenging to convert a measured voltage into a battery percentage. The voltage drops off quickly in the beginning, stays very stable for a long time, and then suddenly drops low at the end of its life: And secondly, the voltage of Li-ion or LiPo batteries doesn't drop linearly. First up: it continuously drains the battery (depending on the resistors you use). Usually with a voltage divider to bring down the voltage so that an ADC can read it.īut this method is not ideal. Many websites tell you to measure the battery level by measuring its voltage.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |