Hi all, hopefully someone can help me - I have an electrical system designed and in use. One function of this is system is to read my vehicle battery voltage and leisure battery voltage.
Concentrating on one, as they both have the same problem.
The phycsial voltage going into my aux battery (leisure ) is 12.57v BUT when you look at the nextion display it shows 10.8v.
Below is the relevant code - the calculations it completes are as follows
Aux out= (analogue value of battery * 5)/ 1024
Aux read = (aux out) / (R2 / (R1+R2))
Aux read* 10 = Aux Conv and it is then displayed.
However having done the maths using these values - i get the answer to be 3v and yet the display says 10.8v
R1 = 30000
R2= 7500
analogue value of battery - 12.57v
Code Below
Aux_Adj = analogRead(Aux_Pin);
Aux_Out = (Aux_Adj * 5.0) / 1024.0; // see text
Aux_Read = Aux_Out / (R2/(R1+R2));
No, we do miss a lot of information, and snippets are rarely going to help.
We don't know which Arduino you have, and how you have powered it.
What the values are of your voltage divider, etc.
(Aux_Adj * 5.0) tells me you're using the potentially noisy/unstable MCU supply as reference, wich could be a bad idea. Many Arduinos have a more stable internal 1.1volt reference that you can activate with code.
Please read the forum posting guidelines, so you can provide us with all the relevant info.
Leo..
You need to calibrate the device for the voltage divider and ADC reference voltage used. A simple multiplicative factor should work.
Most multimeters are accurate to about 1%, so calculate a scale factor (replacing the "10" in the line below), such that the reading of the Arduino voltage sensor agrees with the multimeter.
Hi ! thanks for your response, that makes alot of sense - the only thing that confuses me is that if you do the physical maths it does not sum up to the voltage it is displaying. So I suppose it is just a matter of trial and error?
Hi Wawa, Apologies I am fairly new to coding and using arduino. The board is the arduino mega 2560. I provided the values of my voltage divider in R1 & R2. However this is predominately a maths problem - As I an simply struggling to understand how its reaching 10.8v on the display.
I will try what Jremington suggested below. Many thanks.
I guess OP is using a voltage module.
Should have been mentioned, and we still don't know how the Mega is powered.
If resistors and/or VCC is off, or the module doesn't have it's own dedicted +Batt/GND wiring,
then you have inaccurate readout, which can of course be compensated with code.
A 10k:15k divider with 1.1volt Aref would have been a better choice.
Leo..
I am using a voltage module, It is not GND wiring but I can easily do that, and it takes a signal cable to the board. I am not sure on your other questions - the mega is powered from a 5v supply
So lower voltage 1.1v provides a more stable readout..?