Voltmeter Project (taking voltage measurements with Arduino only)

Here is the project where I measure a 2 x AA battery pack voltage with Arduino only, without using any voltage sensors. I real multimeter confirms the taken voltage data is correct, but I just decided to send it here to make sure that what I did was not wrong. Please, send your comments, if any.

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {

    Serial.begin(9600);

    lcd.init();
    lcd.backlight();

    pinMode(A0, INPUT);

}

void loop() {

    int adc = analogRead(A0);

    float voltage = adc * ((16.5 + 10.2) / 1023.0) * 1.076; // Convert to 9V scale (17K + 10K - resistors, taking into account 5%)

    lcd.setCursor(0, 0);
    lcd.print("Battery: ");
    lcd.print(voltage);
    lcd.print("V");

    delay(1000);

}

/*

Recommended Practical Limits

Application     Max Voltage Resistor Values A0 Voltage Notes

12V Car Battery 12V         20KΩ + 10KΩ     4V         ✅ Safe

15V Solar Panel 15V         33KΩ + 10KΩ     3.5V       ✅ Safe

24V System      24V         47KΩ + 10KΩ     4.4V       ✅ Safe

*/

Thank you.

Your code does not match your picture. As shown your limit is 5V before you start applying over voltage to the analog inputs.

Nothing in your picture defines this. Connecting these to the Arduino will damage and or destroy it. It appears you are missing Pull Up resistors on the I2C circuit.

The 9V PP9 battery will not be supplying enough energy to properly power the Arduino Uno over time. The battery will start at about 9.8 and drop to about 6.5 when discharged. The minimum voltage for Vin is 7V, that is reached when the battery is about 75% used up.

1 Like

Many of the same issues as your other post. Since you have not followed the directions you got on the other post here, I am giving you time to fix this.

1 Like

Created by which AI?

DeepSeek.

gilshultz, I just use voltage divider with 17KOhm and 10KOhm resistors to measure 2 x AA battery pack voltage. And Recommended Practical Limits table just means the upper limit I can measure using the same approach with other resistors. I measured it many times and confirmed by the multimeter - it's correct. I just wanted to make sure. So, voltmeter just shows the same voltage values as Arduino does. And I just used 17KOhm resistor instead of 20kOhm one because I didn't have one, but it appeared to be just alright.

If you read my earlier post, I stated that the resistor dividers were not visible in your picture. After using significant magnification, I was able to locate them on the prototyping board. This would not have been an issue if an annotated schematic had been provided.

You also show the I2C pins connected to an LCD display, but no pull-up resistors or interface module are indicated. It is not clear how the I2C bus is being implemented.

In addition, there are no links to the technical documentation for the hardware components being used. Without datasheets or product references, it is difficult to verify specifications or confirm proper connections.

Providing a complete schematic and links to the relevant technical information would make it much easier to understand your design and offer accurate assistance.