Battery Voltage
Calculate Battery Voltage and display on Monitor
We have a lithium ion battery source at a nominal voltage of 7.4v that powers the entire setup. A regulator circuit regulates the input power to 5v to run the controller. Since these are lithium ion cells, the voltage per cell can range anywhere between 3.4v to 4.2v. There are two cells in series which makes up the total voltage between 6.8v to 8.4v. Once the voltage drops less than 6.8v, the BMS attached to the battery cuts off power and should be recharged.
It is imperative that we monitor this voltage regularly to avoid any unintended cut-off. Since micro:Xbot GPIO pins support only 5 volts maximum, we need a Voltage Divider to reduce battery voltage to a readable voltage (under 5v). The board has a voltage divider circuit made up of two resistors in series (2K and 10K) and the voltage reading between the resistors is read and calculated to get the actual battery voltage.
Battery Voltage can be monitored on pin A3. The analog value read from the pin is converted to digital reading between 0 to 1023. To understand how Analog to Digital conversion works in micro-controller, refer: http://www.robotplatform.com/knowledge/ADC/adc_tutorial.html
Upload the below program and check the voltage displayed on Serial Monitor.
The circuit uses resistors which may have a deviation between 1% to 5%. To get the exact voltage, we can use a multi-meter to check battery voltage and change the calibration_factor
. For example in the above code, if the board has a deviation of 5% between measured and actual voltage, then enter 0.05. This is done only once per board to correct any deviation due to variance in resistors as well as any resistance added through the tracks.
Last updated