float get_volt() {
rawVolt = analogRead(voltageSensor);
vOUT = (rawVolt * 4.6) / 1024.0;
vIN = vOUT / (R2/(R1+R2));
//if(vIN>12.0){vIN=12;}
//if(vIN<11.12){vIN=11.12;}
//return (vIN - 10.18) * (100 - 0) / (12.0 - 10.18) + 0;
return vIN;
}
I am using a voltage sensor module which has a voltage divider with R1=30K Ohms and R2=7.5K Ohms and can measure up to 0-25V by using 10-bit Analog pin of arduino. the battery voltage comes as 11.4 volts when measured with a multimeter but I am getting an inaccurate reading from arduino ranging from 10.8 to 11.4. the Arduino voltage reference is stable at 4.6 V. Please help me to fix this, you can see the voltage reading in the image PS: the battery and arduino are connected to the same ground.
edit1: adding 0.1uf capacitor helped to improve from this
the data is taken for over a period of 1 hr at every 5 seconds, its a 12V 4000 mAh battery