Wants to get an Accurate Voltage Readings from the Battery

Hi ...

I want to get an accurate battery voltage readings from the battery but i could not get it

I get the readings like this on my serial monitor:

12.61,V,Battery Voltages,
12.66,V,Battery Voltages,
12.66,V,Battery Voltages,
12.66,V,Battery Voltages,
12.66,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.66,V,Battery Voltages,
12.76,V,Battery Voltages, sometimes it gives more value than the battery voltage
12.71,V,Battery Voltages,
12.71,V,Battery Voltages,
12.71,V,Battery Voltages,
12.61,V,Battery Voltages,
12.66,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages

Here is the code ...

//BATTERY READINGS VARIABLES
const int Battery = A0;
float Voltage = 0.0; //input battery voltage
float Voltage1 = 0.0; //output voltage for analog pin A0
float R1 = 9000; // R1 =9k ; also used 1.590 k ohms resistors
float R2 = 1000; // R2 =1k ; remain same
int readValue = 0;
long previousMillis_battery = 0;
byte Bat_start_timer = 0;
int battery_wait;
unsigned long currentMillis = 0; // VALID FOR ALL FUNCTIONS(COUNTER)

//BATTERY FUNCTION
void battery()
{
 readValue = analogRead(Battery);
 Voltage1 = (readValue * 5.0) / 1023.0; 
 Voltage = Voltage1 / (R2/(R1+R2));
 if(Bat_start_timer == 0) battery_wait = 100;
 if(currentMillis - previousMillis_battery > battery_wait) {
    Serial.println("Battery Voltages,"); Serial.print(Voltage); Serial.print(",V,");
  previousMillis_battery = currentMillis;
    battery_wait = 100; Bat_start_timer = 1; }
} // battery FUNCTION END

void setup()
{
  Serial.begin(9600);
  pinMode(Battery, INPUT);
  Serial.println("Battery Voltages");
  
}

void loop()
{
    currentMillis = millis();
    battery();

}

i also tried with

Voltage1 = (readValue + 0.5) * 5.0 / 1024.0; // or 1023.0`

but it could not works.

@mubashirazmat, your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem :wink:

1 Like

How do you know it’s wrong ?

its not wrong but i want to get an accurate voltage readings ..?

For example like this on my serial monitor
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages

Not like this on my serial monitor

12.61,V,Battery Voltages,
12.66,V,Battery Voltages,
12.66,V,Battery Voltages,
12.66,V,Battery Voltages,
12.66,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.66,V,Battery Voltages,
12.76,V,Battery Voltages, sometimes it gives more value than the battery voltage
12.71,V,Battery Voltages,
12.71,V,Battery Voltages,
12.71,V,Battery Voltages,
12.61,V,Battery Voltages,
12.66,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages,
12.61,V,Battery Voltages

because it fluctuates too much in the decimals

a) what are you comparing it to ?
b) why not average the value over time ?

It’s highly unlikely to be stable to .01v while there is a running load, or maybe you need a better regulator ?

1 Like

I only need to stable the readings I am running the arduino uno with the USB cable ...

I only made a voltage divider with two Resistors
R1 = 9Kohms
R2 = 1Kohms

What should i need to do to add-ons ...?

How much is too much? From the 328P datasheet (you don't say which processor you use)

From that perspective, you should throw the last two bits away (divide by 4) or get a better external ADC.

1 Like

I see, so your divider let’s you read up to ~45V with a 9:1 ratio…

I personally would use higher value resistors to get a lower waste of current in the divider, and if you closed the ratio down e.g. 47k/10k (5:1), you’d get improved resolution (approx doubled) around 25V full scale where you’re measuring down around 12V.

BUT that means you’ll probably see more/greater ripple in the measured output…

Hence part (b) of my first comment.
Averaging the reading over time to get a more stable value - or getting a bigger, better regulated supply that doesn’t ripple.

1 Like

Hi,
Can you post a circuit diagram please.
Have you tried a 0.1uF and 10uF capacitor from A0 to gnd?
What is the load on your battery?

What Arduino controller are you using?

Have you tried using the possibly more stable internal reference instead of the 5V power supply as your reference.
https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/
Tom... :smiley: :+1: :coffee: :australia:

1 Like

GitHub - sebnil/Moving-Avarage-Filter--Arduino-Library-: A moving average, also called rolling average, rolling mean or running average, is a type of finite impulse response filter (FIR) used to analyze a set of datum points by creating a series of averages of different subsets of the full data set.

Have a look at data smoothing

I tried but still not improved .... can you please provide me the circuit diagram of this ...?