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– bigjosh2023-02-28 23:55:19 +00:00Commented 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– bigjosh2023-02-28 23:59:43 +00:00Commented Feb 28, 2023 at 23:59
-
1I 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– bigjosh2023-03-01 00:01:18 +00:00Commented 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 aboveelectro_nooobbbb– electro_nooobbbb2023-03-01 10:45:26 +00:00Commented 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.electro_nooobbbb– electro_nooobbbb2023-03-01 11:02:52 +00:00Commented Mar 1, 2023 at 11:02
|
Show 7 more comments
1 Answer
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
analogReference(INTERNAL);
float VA1 = Vref / 1023.0 * analogRead(A1); // voltage at analog pin A1
float Vbat = VA1 * 5.7; // battery voltage
-
2For 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– hcheung2023-02-20 23:48:04 +00:00Commented 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?electro_nooobbbb– electro_nooobbbb2023-02-22 04:06:20 +00:00Commented Feb 22, 2023 at 4:06
-
1Use 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– hcheung2023-02-22 04:12:11 +00:00Commented Feb 22, 2023 at 4:12
-
1Your 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– hcheung2023-02-22 06:53:44 +00:00Commented Feb 22, 2023 at 6:53