Become a leader in the IoT community!

New DevHeads get a 320-point leaderboard boost when joining the DevHeads IoT Integration Community. In addition to learning and advising, active community leaders are rewarded with community recognition and free tech stuff. Start your Legendary Collaboration now!

Step 1 of 5

CREATE YOUR PROFILE *Required

OR
Step 2 of 5

WHAT BRINGS YOU TO DEVHEADS? *Choose 1 or more

Collaboration & Work 🤝
Learn & Grow 📚
Contribute Experience & Expertise 🔧
Step 3 of 5

WHAT'S YOUR INTEREST OR EXPERTISE? *Choose 1 or more

Hardware & Design 💡
Embedded Software 💻
Edge Networking
Step 4 of 5

Personalize your profile

Step 5 of 5

Read & agree to our COMMUNITY RULES

  1. We want this server to be a welcoming space! Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.
  2. If you see something against the rules or something that makes you feel unsafe, let staff know by messaging @admin in the "support-tickets" tab in the Live DevChat menu.
  3. No age-restricted, obscene or NSFW content. This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.
  4. No spam. This includes DMing fellow members.
  5. You must be over the age of 18 years old to participate in our community.
  6. Our community uses Answer Overflow to index content on the web. By posting in this channel your messages will be indexed on the worldwide web to help others find answers.
  7. You agree to our Terms of Service (https://www.devheads.io/terms-of-service/) and Privacy Policy (https://www.devheads.io/privacy-policy)
By clicking "Finish", you have read and agreed to the our Terms of Service and Privacy Policy.

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();
}

file0.jpg

  1. Afuevu#0000

    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.

  2. aymen ammari#0000

    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.”

  3. bruce_wayne#0000

    Hello. @mr.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 @mr.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.

  4. Afuevu#0000

    Distance affects readings, try and shorten the distance as much as possible.

  5. Afuevu#0000

    Hello @bruce_wayne5006, 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.

  6. bruce_wayne#0000

    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.

CONTRIBUTE TO THIS THREAD

Leaderboard

RANKED BY XP

All time
  • 1.
    Avatar
    @Nayel115
    1620 XP
  • 2.
    Avatar
    @UcGee
    650 XP
  • 3.
    Avatar
    @melta101
    600 XP
  • 4.
    Avatar
    @lifegochi
    250 XP
  • 5.
    Avatar
    @Youuce
    180 XP
  • 6.
    Avatar
    @hemalchevli
    170 XP