Go Down

Topic: Battery Monitor MisReads (Read 357 times) previous topic - next topic

modsbyus

Please see attached picture for reference.
The read voltage will go to zero for a while and then begin reading proper voltage again. I am unsure what to do about this problem. When I check battery voltage with a VM meter at the time my arduino is saying its zero it shows 3.33 volts. Why is my arduino saying the voltage is fluctuating?

Code: [Select]

//set up the sensor pin for reading the voltage
int sensorPin = A0;
//initialize serial communication
int sensorValue = 0;
void setup()
{
//initialize serial communication
Serial.begin(9600);
}
void loop()
{
//set sensorValue as an analog read of the A0 pin
sensorValue = analogRead(sensorPin);
//print the value of the sensor multiplied by 0.00326 to get a true voltage reading.
//this is a value of 0 - 1023 coming from the sensor pin and has to be converted.
Serial.println (sensorValue * 0.00326);
delay(1000); //give a delay between readings.
}

johnwasser

Looks like a bad connection. :(

How is the analog input connected to the battery?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

modsbyus

Indeed! Bad connection to Arduino ground. Thank you.
Also, I had some math wrong! Instead of multiplying by 0.00326 it should have been 0.00951.


Code: [Select]

int sensorPin = 0; //set up the sensor pin for reading the voltage
int sensorValue = 0; //variable to store the value coming from the sensor

void setup()
{
  //This is the default value, but we can set it anyways
  analogReference(DEFAULT); //5V Reference on UNO
Serial.begin(9600); //initialize serial communication
}

void loop()
{
  sensorValue = analogRead(sensorPin); //set sensorValue and an analog read of the A0 pin
  //print the value of the sensor multiplied by 0.00951 to get true voltage reading.
  //this is a value of 0 - 1023 coming from the sensor pin and has to be converted.
  Serial.println("Battery Voltage Is");
  Serial.println(sensorValue * 0.00951);
 
  delay(1000); //give a delay between readings.
}



Go Up