Checking the voltage of a chain of 5 AA batteries

Board: Freenove equiv of Uno WiFi.

I want to know when the batteries of a model are getting low.
The 5 AA batteries are over 5 volts so I cannot check the end voltage.
I make a tap after the second AA battery and take it to pin A0.
Unfortunately a meter shows a voltage of 2.39 but A0 shows 1.18!!

What is the correct way to get a real reading?

void doshowvoltage()
  {
    adcValue = analogRead(A0); // Convert analog of pin A0 to digital
    voltage = adcValue * (5.0 / 1023.0); // Calculate voltage according to digital
    Serial.println(adcValue);
    Serial.println(voltage);
    matrix.beginDraw();
    matrix.stroke(0xFFFFFFFF);
    matrix.textFont(Font_4x6);
    matrix.beginText(0, 1, 0xFFFFFF);
    matrix.println(voltage);
    matrix.endText(0);
    matrix.endDraw();
  }

Circuit:
Screenshot 2024-09-24 121504

Yes you can. Use a voltage divider.

2 Likes

2.39V is pretty low... are the batteries empty?
Or is a large motor running off the batteries?
How do you feed the battery voltage into arduino?
Via 5V pin or via vin?
If via vin, did you check the 5V pin? It should be at 5V...

Yes I know the batteries are getting low hence the reason I wanted a checking system.
I use Vin plug and socket to power up the Arduino - the current voltage is 6.101V at the plug and 5.065 on the board.

What do you have the reference set to?

I know roughly what you mean but I haven't used one - please help?

What are you getting from serial monitor if you connect 5V pin to A0?

Put in setup()
analogReference(VDD);

If the value is still wrong, then I suspect that your Freenove is not the same as an Uno WiFi

Unfortunately that won't compile.

Surprised to see 2.37 V!!

When powered just with the USB the reading0.22V

Powered from 5V usb port?
and 5V pin on A0 reads 0.22V?
Broken wire?

This on setup should compile:
analogReference(AR_DEFAULT);

Then it is not equivalent to a Uno WiFI.
Was there a special board package/core you were supposed to download and install?
Which board do you have selected from the board manager?
What processor is on the board?

Maybe show a picture of the board.

From the Arduino documentation:
analogReference(type)
Arduino megaAVR Boards (Uno WiFi Rev2)
DEFAULT: a built-in 0.55V reference
INTERNAL: a built-in 0.55V reference
VDD: Vdd of the ATmega4809. 5V on the Uno WiFi Rev2
INTERNAL0V55: a built-in 0.55V reference
INTERNAL1V1: a built-in 1.1V reference
INTERNAL1V5: a built-in 1.5V reference
INTERNAL2V5: a built-in 2.5V reference
INTERNAL4V3: a built-in 4.3V reference
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference

Probably Uno R4 wifi clone

For measuring batteries, it would be best to use the Arduino's interval voltage reference. Using Vdd, which is the default, won't give an accurate reading when the batteries get low.

The interval voltage reference might be 1.1V or some other voltage depending on the model of Arduino you are using.

You then need a voltage divider to reduce the battery voltage down to less than 1.1V (or whatever for your Arduino model).

If you want to measure, for example, up to about 8.5V and the interval reference voltage is 1.1V, then you could make a voltage divider using a 10K and a 1.5K resistor.

You could then calculate the voltage like this:

voltage = adcValue * (8.44/ 1023.0); // Calculate voltage according to digital

The 8.44V is calculated like this:
1.1V * (10K + 1.5K) / 1.5K = 8.44V

Compiled Ok but reads 0.22 to 0.24V

jim-p ;
nothing about downloading a special core
Arduino UNO R4 WiFi
no name on chip - first row of numbers R7FAAM1

Power arduino from usb.
Connect 5V pin to A1
Make sure your wire is good.
Change your code to read A1.
post output

Is it this one

Yes - from Amazon (where my picture came from

There is a difference beteen the Uno WiFi and the Uno R4 Wifi but in any case if you set the reference to AR_DEFAULT as @kmin suggested it should read correctly.
The only thing I can think of is to add analogReadResolution(10) to setup to make sure it's set to 10 bits

1 Like

Worked perfectly reads 5V and I tried my tap wire and that read perfectly.

I have a terrible confession to make I had used the wrong end of the Analogue strip.

My apologies to everyone - but I am incredibly impressed at the support I have received.

I have updated my profile - this may explain what happened.!!