there i am working on a project in which my system is connected to 3.7v~4.2V lithium battery, I have to read constant battery voltage irrespective of the current battery voltage and to do that I am using internal voltage reference (1.1V). My issue is that before adding sensor code my program was reading constant voltage irrespective of any battery level but the moment I add sensor code to it, the battery voltage readings fluctuate.

  • You still have some problems as all the other times you have asked this question. You need to make the minimal version of the code that works as you expect, and then show what change you make that produces output you do not expect. (1) do not mix Arduino analog pin functions with direct register access. Pick one or the other (you should pick arduino). (2) remember that you can only real voltages between 0-1.1V with the 1.1V. Any voltage higher than 1.1V will read as max value (1.1V) against this reference.(3) you are using A1 in your code, but A1 is not connected to anything in your schematic.
    – bigjosh
    Feb 28, 2023 at 23:55
  • People want to help you, but you have to help them to help you! By continuing to ask the same question over and over and over again you wasting the time of the nice people trying to help you and you are not even getting solutions to your problem. Make the simplest version of the program that works. This is probably measuring the battery voltage though the bridge using A0 pin using only Arduino function. This should be a very short program. Make sure it really works as you expect across all potential voltages you might see.
    – bigjosh
    Feb 28, 2023 at 23:59
  • 1
    I know you just want someone to give you a quick fix, but you have already spent way way more time asking this question over and over again than you would have to systematically work your way through this problem! Start simple, understand what is going on. I promise! :)
    – bigjosh
    Mar 1, 2023 at 0:01
  • @bigjosh It is working, i needed stable output. As you said i have removed all register function and using simple arduino code. please check above Mar 1, 2023 at 10:45
  • My issue is that i want to connect my solar panel to positive and negative of battery but the moment i make the connection my sensor reads 1023 which it obviously should. so, is there a way to separate out or connect. Mar 1, 2023 at 11:02

1 Answer 1


If you set the Vref with the internal reference of 1.1v, then the voltage presented at analog pin A1 is simply as:

const float Vref = 1.1; // according to datasheet there is a +/-10% variance, need calibration to confirm the actual value

float VA1 = Vref / 1023.0 * analogRead(A1); // voltage at analog pin A1
float Vbat = VA1 * 5.7;                     // battery voltage
  • 2
    For more accurate measurement. you can use a multimeter to measure the actual Vref, and use the actual measurement in your sketch as the Vref value. BTW, if you are using battery, you may want to change your voltage divider to 47k and 10k to reduce the current draw by the voltage divider.
    – hcheung
    Feb 20, 2023 at 23:48
  • sure, i will use the exact vref value. Is it 47k or 4.7k? because i have used 4.7k and if i change my 1k to 10k, do i need to change the value (5.7) in the program?, we need one pin just to read the battery voltage right? Feb 22, 2023 at 4:06
  • 1
    Use 47k and 10k resistors, the ration will still be the same (47000+10000)/10000. But this only draw current of 3.7/(47000+10000) = 65uA, versus when using 4.7k+1k which draw 0.65mA. 10 times difference.
    – hcheung
    Feb 22, 2023 at 4:12
  • 1
    Your original post mentioned nothing about any light sensor, it was asking how to read the battery voltage. If my answer help you answered that question, please accept the answer by click on the 'tick' and upvote it so that future reader know this is a correct answer. Feel free to post another question regarding your lighting sensor question with your code separately.
    – hcheung
    Feb 22, 2023 at 6:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.