Voltage Sensor not reading/displaying correctly

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));

uint16_t auxConv = Aux_Read *10;
uint16_t vwbConv = VWB_Read *10;
printHMIValue("WVB.val=", auxConv);
printHMIValue("AVB.val=", vwbConv);

Let me know if you guys need anything else ! hopefully im missing something daft, thank you!!

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.

Aux read* 10 = Aux Conv and it is then displayed.

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.

Are you sure that you use in calculation correct resistor values?

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..

Looks like you have R1 & R2 reversed:
7.5k / 37.5k * 12.57 = 2.514, 30k / 37.5k * 12.57 = 10.056.

1 Like

Hi, thanks for your response - but you calculate this without the other steps, the multiply by 5 and divide by 1024..?

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..?

many thanks.

Which Arduino are you using? How is the voltage module connected to the battery and Arduino?

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