How can I correctly measure battery voltage using the A0 pin on Arduino?

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(); }
attachment 0
6 Replies
Afuevu
Afuevu2w ago
A voltage divider can work well, send the total voltage through a voltage divider, use R1 = 5.1k and R2 = 1k. If current consumption is a concern, you can use 51k and 10k. Then you can read the entire voltage of the battery. Then for the readings you are getting, is the distance between the battery and the A0 pin much? long distance affects readings. Also try and put a 100nf capacitor on the A0 pin to ground.
aymen ammari
aymen ammari2w ago
Thanks for the suggestion! The distance between the battery and A0 pin is about 7 - 10 cm does it effect the readings? , I’ll also add the 100nF capacitor to the A0 pin and see if that stabilizes the readings."
bruce_wayne
bruce_wayne2w ago
Hello. @aymen ammari is tapping the voltage for two batteries => 1.5 x 2 =3 volts. I’m confused why is a divider needed? Please correct me if im wrong, @Afuevu Also @aymen ammari you can tap the entire 1.5 x 5 =7.5 volts directly by using voltage divider like @Afuevu suggested. You can use any voltage divider calculator online for this purpose.
Afuevu
Afuevu2w ago
Distance affects readings, try and shorten the distance as much as possible.
Afuevu
Afuevu2w ago
Hello @bruce_wayne, a voltage divider is unnecessary if the total voltage is not more than 5v. But if the voltage is more than 5v, it is necessary.
bruce_wayne
bruce_wayne2w ago
That’s right! What he can actually do is tap the cumulative voltage of 7.5V using a divider. Maybe that is better than tapping only into part of the battery.
Want results from more Discord servers?
Add your server