3.7v LiPo readings is Correct?

It doesn’t tell you what board the code is for, what analog reference is set or how it is even connected to the board. There are no follow ups either and not a single confirmation that it actually works

I run a test just now to disconnect the wire from A0 pin, and the result is the voltage now is 0.00v (not reading anything). So the code is working when Ve+ connect to A0 pin. And my only problem now is somewhere on (3.6, 4.2, 0,200) line to display to correct (atleast) battery to show.

I'm sorry I just dont know how else to explain that you need reference voltage independent of battery current potential, so you could compare the change in battery potential to that voltage. Otherwise your battery will always show 100%

Okay this is mind bending, tested on 2 arduino nano. 1 already wired to other sensors, 1 not wire to anything.

Both i get reading 002, i assume there is nothing wrong with the boards.

So, the arduino is powered from the battery which is connected to 5V & GND. Then there is a wire from 5V/Batt+ to A0 and you expect to be able to read the voltage from A0? That's not gonna work for you. The arduino uses the supply-voltage as reference (which can be read with a DMM on the ARef pin) in order to compare other voltages to the reference. In your case the reference voltage is always equal to the voltage supplied to A0 and thus the reading will always be the same. You are in other words comparing a voltage to itself.

Did you by chance try the code I linked to in reply #4? That code will compare the analog reference voltage to the internal reference voltage and give you a very good reading of the supply voltage. If you did not try that code, it seems like you do not want to solve your problem.

Yes im taking readings from A0 pin. And i think i got it right just now. Will monitor it and update later if its correct or just a placebo

How is your current wiring?

If you are reading 2 millivolts on the Aref pin when you run the sketch and send an R with Serial Monitor then something is very wrong with both of your Nanos or your meter. Before you send the R, the voltage on Aref should be about 5V (or 3.3v if you are using a 3.3V Nano).

Try the meter to "20" and read 5v its normal i get 4.88-4.99v

Same as above

Or maybe because i connect the battery to TP4056 before it connect to the board?

can you quote in full what you are replying to instead of unhelpful one word quotes? thanks

Sorry for that, im new here and many function of the forum is new to me :frowning:

Beside of the code i share here, can you help pointing me any code/sketch on how to monitor 3.7v battery actually is? Or is it cannot be monitored?

I make a new thread (sorry) can anyone guide me? I found the library is like what i want to do (read A0 pin)

Interesting, now figuring how to display it in percentage, could it be like this?

if (perc > voltage = 100);

{ if else (perc > voltage = 50);

Why not just print the percentage?

Guide me please :frowning: the reason i use the code is just for bitmap display of battery icon, i guess battery icon is not important now as i can just show the icon wihthout animated it.

Is it like this?


So the final code is, still not sure if its working or not, or anything wrong in the code

int value = 0;
float voltage;
float perc;

long float_map(float x, float in_min, float in_max, float out_min, float out_max)
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;

void setup(){

void loop(){
  value = analogRead(A0);
  voltage = value * 3.7 / 1024;
  perc = float_map(voltage, 3.0, 4.2, 0, 100);

  Serial.print("Voltage= ");
  Serial.print("Battery level= ");
  Serial.println(" %");

with a schematic as follow

Shouldn't that be a boost converter?

Yes correct, and now its working