Battery Level Monitoring

Introduction

This experiment shows how to monitor the voltage of a battery using an Arduino and display the level on the Serial Monitor.

Battery Monitoring Circuit

Components Needed

Circuit Setup

  1. Use a voltage divider circuit to scale down the battery voltage to a safe range for the Arduino analog input.
Battery Monitoring Circuit Setup

Code for Battery Level Monitoring

Upload the following code to your Arduino to monitor the battery level:


const int analogPin = A0;  // Pin connected to the voltage divider
int batteryLevel;

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

void loop() {
  batteryLevel = analogRead(analogPin);
  float voltage = (batteryLevel / 1023.0) * 5.0; // Convert to voltage
  Serial.print("Battery Voltage: ");
  Serial.println(voltage);
  delay(1000);
}
            

Explanation

The Arduino reads the voltage from the voltage divider and calculates the battery level by converting the analog value to a voltage.

Troubleshooting