VEEROBOT Docs
StoreBlogWiki
  • 🌐Introduction
  • ROS Based Robots
    • 🐺Wolf Robot
      • ROS Introduction
      • Getting Started with ROS 2
      • Introduction to Wolf Robot
      • ROS 2 Setup
      • ROS Concepts
      • Using Wolf Examples
      • Creating a URDF File
      • Visualising in Gazebo
      • Controlling motors from ROS
      • LiDAR Basics & Control
      • Using a Camera with ROS2
      • ROS 2 Cleanup
      • ROS 2 Controller
      • Teleoperation
      • Slam Navigation
      • Wolf : Conclusion
  • Arduino Based Robots
    • 🚜Micro:Xbot
      • Preparations before First Use
      • Programming the Board
      • Powering the Board
      • Pin Mapping
      • Basic Programs
        • Blinking LED
        • Buzzer Program
        • Fading LED
        • RGB LED
        • Light Detection
        • Battery Voltage
        • Line Follower Module
        • Ultrasonic Sensor
        • Infrared Remote Control
        • Motor Control
        • Bluetooth Control
        • Display Test
        • Test Me
      • Robot Assembly
      • Advanced Programs
        • Bluetooth Controlled Robot
        • Obstacle Avoidance Robot
        • Line Follower Robot
  • ROS2 Repo
    • Introduction
    • Page 1
      • Sub Page 1
    • Page 2
Powered by GitBook
On this page
  1. Arduino Based Robots
  2. Micro:Xbot
  3. Basic Programs

Battery Voltage

Calculate Battery Voltage and display on Monitor

PreviousLight DetectionNextLine Follower Module

Last updated 2 years ago

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:

Upload the below program and check the voltage displayed on Serial Monitor.

/*
  Voltage Reading: This program reads analog voltage and converts it to battery voltage

  At VEEROBOT, we invest time and resources providing this open source code,
  Please support VEEROBOT and open-source hardware by purchasing products
  from us @ http://veerobot.com
  -----------------------------------------------------------------------------
  You are free to redistribute it and/or modify it under the terms of the GNU
  Lesser General Public License as  published by the Free Software Foundation,
  either version 3 of the License, or (at your option) any later version.

  This Code is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

  See <http://www.gnu.org/licenses/>
*/

#include "config.h"

float batteryVoltage = 0.00;
float R1 = 10000.0;        // R1 and R2 value in Ohms
float R2 = 2000.0;
float ref_voltage = 5.0;  // Float for Reference Voltage
int analogPinValue = 0;
float adc_voltage = 0.0;
float calibration_factor = 0.05;  // check the deviation using a multimeter

void setup() {
  Serial.begin(9600);
}

void loop() {
  // read battery pin analog value
  analogPinValue = analogRead(BV);
  adc_voltage  = analogPinValue * (ref_voltage / 1024.0);

  batteryVoltage = adc_voltage / (R2 / (R1 + R2));
  batteryVoltage = batteryVoltage + (batteryVoltage * calibration_factor);
  Serial.print("Battery Voltage = " );
  Serial.println(batteryVoltage );
  delay(300);
}

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.

🚜
http://www.robotplatform.com/knowledge/ADC/adc_tutorial.html