Measuring a 1.5V battery with analogRead, wrong (I think)

Hi, I measured a 1.5V battery to check if arduino was reading values the rigth way, however the analogRead gives back 1V (I use the map function in here). Is this supose to happen? I did this because in another project the analogRead isn't giving me the rigth feedback either.

Post your code. The issue may be how you are converting the analog values to a voltage.

Also a pic of the project as well as a schematic would be great.

Here is an Image of the code, for the project is only conect a pin to ground and another to A0 nothing else.

imagem_2021-02-19_223340.png

imagem_2021-02-19_223340.png

try
Serial.println(analogRead(A0) * 0.0048875);

or

int value = analogRead(A0);
double v = map (value,0,1023,0,500)/100;
Serial.println(v);

Also DON'T post an image of code, post the TEXT using the </> Icon above

missdrew:
double v = map (value,0,1023,0,500)/100;

AFAIK map() will return a long integer, not a double.

That would then be an implied conversion.

Do you have a multimeter?

If so, check the battery and check "5V" on your Arduino. 5V (Vcc) is your reference and if that's off your reading will be off. ...It's probably not a Vcc problem because Vcc would have to be WAY too high to be reading THAT low.

And use your meter to measure the battery in the same circuit with the Arduino at the same time so nothing changes.

P.S.

AFAIK map() will return a long integer, not a double.

That would explain it!

map() uses integer maths. Any calculation that results in anything from 1 to 1.99999 will just return 1, as explained in the reference. See map() - Arduino Reference

Steve

Ok that makes a lot of sense thanks a lot. I dont know nothing from this language, I began with python and I'm still learnign C. Also thank you a lot for all the awnsers. Great comunity

map to millivolts, problem solved?

Which Arduino or other MCU board?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.