Introduction
In this article, I will show you how I built a simple Arduino-based battery monitor for under $15. This handy device allows me to keep track of the voltage level of any battery pack, which is great for monitoring and maintaining the health of batteries used for projects and hobby electronics.
The battery monitor uses an Arduino Nano, an I2C OLED display module, a voltage divider circuit, and a few other simple components. I will provide step-by-step instructions to assemble the circuit and write the Arduino sketch. No prior experience with Arduinos is necessary to follow along!
Required Components
To build the Arduino battery monitor, you will need the following components:
-
Arduino Nano - The brains of the operation. This small microcontroller board can be purchased for around $4.
-
0.96" I2C OLED display - Provides a bright and crisp display for voltage readings. These displays can be found for ~$2 on eBay.
-
10k resistor - Used in the voltage divider circuit. Resistors are just a few cents each.
-
Wires - For connecting the components together. I used jumper wires which are widely available and inexpensive.
-
9V battery clip - Enables connecting a 9V battery to the input of the circuit. These are about $1.
-
9V battery - For testing the monitor. High quality 9V batteries cost $2-4.
With careful shopping, all the components can be purchased for right around $15 total! Now let's look at how to put everything together.
Assembling the Circuit
The circuit for this Arduino battery monitor only requires a few connections:
-
The Arduino Nano needs to be connected to the OLED display module using 4 jumper wires. Specifically, connect the SDA, SCL, GND, and 5V pins between the two boards. This allows serial communication between the Arduino and display using the I2C protocol.
-
The voltage divider circuit consists of the 10k resistor connected from the 9V battery's positive terminal to one of the Arduino's analog input pins, A0. The other leg of the resistor goes to the battery's negative/ground terminal.
-
The negative terminal of the battery also gets connected directly to ground on the Arduino Nano.
That's it for the circuit! Very simple. Now the Arduino just needs to be loaded with a sketch to take analog voltage readings and display them on the OLED.
Writing the Arduino Sketch
With the Arduino IDE installed on your computer, you can copy, paste, and upload the following sketch to your Arduino Nano:
```cpp
include
include
include
define SCREEN_WIDTH 128
define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
// Initialize the OLED display
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
// Draw startup screen
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.println("Arduino");
display.println("Battery Monitor");
display.display();
}
void loop() {
// Read battery voltage
int sensorValue = analogRead(A0);
float voltage = sensorValue * (9.0 / 1023.0);
// Display battery voltage centered on screen
display.clearDisplay();
display.setCursor(0, 30);
display.println(voltage);
display.display();
delay(100);
}
```
This uses the Adafruit SSD1306 library to handle communication with the OLED display. The key part is reading the analog input A0, converting that to a voltage based on the resistor divider ratio, and printing the voltage value to the screen.
After verifying the code, upload it to your Arduino Nano. Once programmed, the battery monitor is ready for testing!
Testing It Out
To test out the Arduino battery monitor:
-
Connect a fresh 9V battery to the 9V clip. This will provide input power to the voltage divider circuit.
-
The OLED display should initialize and show the startup text.
-
The voltage reading from the battery will then be displayed and refreshed every 100 ms.
-
As you drain the 9V battery by connecting an LED or other device, you will see the voltage steadily decrease on the screen.
-
The monitor will follow the voltage all the way down to 0V when the battery is fully discharged.
And there you have it, a complete functional Arduino battery monitor for under $15! With this on hand, you'll always know the state of your batteries and when it's time to swap them out or recharge.
Going Further
Some ways this basic battery monitor could be expanded are:
-
Add a buzzer or LED to provide an audible/visual low voltage warning.
-
Monitor multiple battery inputs by adding additional voltage dividers.
-
Log voltage over time to an SD card for tracking battery health.
-
Make a portable version with everything built into a custom enclosure!
The core Arduino platform makes it easy to customize the battery monitor to your needs. As your projects grow more advanced, accurate battery monitoring will become even more important.
Hopefully this guide has shown how accessible and useful Arduino projects can be. Let me know if you end up building your own version or have any other questions!