4

I am trying to display the battery voltage as it is being used to power the Arduino.

I have tried powering the Arduino through the USB and the battery voltage is read accurately when compared to the multimeter reading.

But when the battery is powering the Arduino and being read, it keeps displaying 5.00 V, which it should not be.

Just wondering what might be happening and how I can go about resolving this issue.

I have been trying to research some answers, and came across something about an 1.1 V reference voltage, but I'm not entirely sure what they mean.

Here is my code for reference:

#include <SoftwareSerial.h>
SoftwareSerial BTserial(10,11);
int battPin = A1;
void setup() {
 pinMode(battPin, INPUT);
 BTserial.begin(9600);
 Serial.begin(9600);
}
void loop() {
 int voltReading = analogRead(battPin);
 float volts = (voltReading/204.6);
 BTserial.print(volts);
 BTserial.print(";"); 
 Serial.println(volts);
}

I am using a 3.7 V Li-po battery. It is connected to A1 and also to Vin.

ocrdu
1,7953 gold badges12 silver badges24 bronze badges
asked Dec 23, 2019 at 17:04

3 Answers 3

2

AFAIK, Arduinos are set up to use their operating voltage as the analogRead reference voltage by default.

So what I think is happening is that you are trying to measure the battery voltage with the battery itself as a reference voltage.

This will, of course, always show "full scale".

You could use a voltage divider to bring the measured battery voltage down to about 1 V (max) and use the Arduino's internal reference of about 1.1 V for measuring.

Note that the 1.1 V internal reference is stable, but not necessarily exactly 1.1 V. You will have to measure it first.

answered Dec 23, 2019 at 17:47
3
  • Oh I see! I will give that a try and see what happens! Thanks! Commented Dec 23, 2019 at 17:51
  • Also, how can I go about using the internal reference? Commented Dec 23, 2019 at 17:56
  • See arduino.cc/reference/en/language/functions/analog-io/… Commented Dec 23, 2019 at 18:04
0

You need to divide down the battery voltage into the 1.1V max range, and use the Internal bandgap voltage reference for the ADC conversions.

Connect the Battery to VCC, not Vin, you don't want it going thru the regulator.

answered Dec 23, 2019 at 17:28
4
  • By "divide down the battery voltage" do you mean with circuitry, such as a voltage divider, or through the code? And what is the internal bandgap voltage reference? Commented Dec 23, 2019 at 17:44
  • Yes, two resistors, in series between VCC and GND. Connect Ax to the junction. See the datasheet for more info on the internal source. Commented Dec 23, 2019 at 18:23
  • connecting the battery to the VCC, means connect to the 5V pin? Is that okay? I read that if you connect the USB while battery is connected to the 5V pin, it could damage stuff. Commented Dec 23, 2019 at 21:17
  • Maybe. 3.7V into the barrel jack will be overcome by the USB input and the power switching circuit, and USB will be used. Commented Dec 23, 2019 at 23:15
0

If you want measuring a "battery level" in mAh for example, you must measure Voltage AND Current, so INA219 is a better deal (it is a I2C control).

answered Jun 8, 2021 at 20:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.