Monitor 12v battery


#22

You have no resistors hooked to A0 ?


#23

I using the same resistors from above. Voltage divider


R1 = 120K, R2 = 33K


#24

Right now on the Voltage Output Im getting 4
and on the Raw Im getting 1453


#25

If your raw is 1453, then it is probably reading well. Now how do you convert that with math to 5V ?
Did you test the voltage with a volt meter. It may not really be 5v (probably a little off).
I normally do a test, and calibrate using the map() function.
Based on recent info, the input impedance of the analog input is sorta low. You may be better using some resistors a bit lower that you list.


#26

using this.


#27

Yes, I measured with voltmeter and is giving 5.0 v.
Im using a variable power source and on the sourse is giving the same number.


#28

@Kuto,

use this and you are good to go :smile:

const float voltsPerBit = 3.3 / 4095;  // Calculate volts per bit of ADC reading
const float ratioV = (120000 + 33000) / 33000;  //Calculates to 4.636363


void setup()
{
Serial.begin(9600); 
}

void loop() 
{
   int Vin = analogRead(A0);
   float rawVolts = Vin * voltsPerBit;  //Calculate voltage at A0 input
   float batteryVolts = rawVolts * ratioV;
   Serial.print("Voltage ");
   Serial.print(batteryVolts);
   delay(3000);
}

#29

Also,

for education purposes, this is a better way to induce delayed polling. Not the best but better. :smile:

const float voltsPerBit = 3.3 / 4095;  // Calculate volts per bit of ADC reading
const float ratioV = (120000 + 33000) / 33000;  //Calculates to 4.636363

unsigned long old_time = millis();

void setup()
{
    Serial.begin(9600); 
}

void loop() 
{
    if(millis() - old_time >= 3000){
        int Vin = analogRead(A0);
        float rawVolts = Vin * voltsPerBit;  //Calculate voltage at A0 input
        float batteryVolts = rawVolts * ratioV;
        Serial.print("Voltage ");
        Serial.print(batteryVolts);
        
        old_time = millis();
    }
}

#30

Now It works, but is a little off. Im getting this.
Voltage 4.69 Raw 1.174.691455


#31

I normally calibrate mine using map().


#32

Don’t know whats going on. Now if I increase the voltage to 10.0 v , the output difference in the spark is bigger. Is showing 8.37 V.


#33

May be the fact that the analogue input is sorta low impedance, and your resistors are a bit to large. I really don’t know tho.
Did the raw reading reach its max?


#34

No. reading Raw 2599


#35

did you get the 5 volt reading pretty accurate, and then it went asque testing the 10v range?


#36

No. At 5.0V, I got this Voltage 4.69
At 10.0 V, I getting this 8.37


#37

Oh, I see. You seem hesitant to try the map() function. Have you never used it before, or you just don’t like it?


#38

to be honest, I don’t know how to do that )-; Sorry. Im new to this.


#39

We are all new at some point. I am still about there.
I think it will be helpful to you. If you check the documentation it probably tells more than I could, but basicly
I think you can specify that 1322 raw = 4.5 volts, and that 3763 = 9.9 volts, then as the raw varies, the volts will follow, even it it not within the ranges that you specified. If you want to check it out, and have questions, I will try to answer.


#40

Thank You. I would give a try and see how I handle it. (-:


#41

I normally test the value about 10% above the lowest I expect, and about 10% below the highest I expect, and measure the voltage (or temperature) or whatever, and put that into the map() function.
Good luck,
if you have more questions, just ask.