code is a little big (its attached) , this is the only part where i read the voltage apart from this i have just defined these two pins as input
#define battery_pin A3
#define buck_pin A2
pinMode(A2, INPUT); // buck input
pinMode(A3,INPUT); // battery input
the conversion factor is due to the voltage divider ,
for battery it is … +__660K____A3____330K____Gnd
for buck it is +_____330K____A2_____330K_____gnd
i thought the resistors are way to big to allow the ADC to draw some current , but then i tried using another arduino just to measure the voltages after setting the conversion time to max to get better results , which i got so i made the same modification in the arduino on car but still same readings .
i also thought that this could be due to the fact that i am powering the arduino using a buck converter.
( buck converter use a switching transistor with inductor in series and turn it on and off depending on the required voltage , so it is pulsating DC , though multimeter will show constant output … a oscilloscope wil not show constant output .)
i would also like to mention that i am giving the voltage at 5v , rather than Vin.
so i connected it with the usb supply from laptop which did modify the output but it further increased it by 0.2 , 0.3 rather than decreasing it ( actual value is 0.2 -0.4 less than what i m getting ).
i don’t have a coding background , so sorry if code is not neat.(put these three files in a folder named “carv2__oncar” , there are 2 “_” underscores )
carv2__oncar.ino (3.52 KB)
input_processing.ino (1.24 KB)
processing.ino (3.9 KB)