Battery Alarm unstable ADC

Hi Everyone,

I'm working on a simple battery alarm using a Arduino Micro to measure dc between 11 and 16 volts. To get a value between 0 and 5 v on a ADC I'm using a voltage divider, two resistors in series (100 k and 300 k) between ground and Vin, the middle is connected to the ADC.
It works OK as long as I power it from my computer via USB, if I power it via Vin (lab psu) the ADC gets very unstable.

I already tried to put a 7809 between the battery and Vin without success, also tried some capicitors on different locations in the circuit.

I hope someone can help me!

if I power it via Vin (lab psu) the ADC gets very unstable.

Do you have a common ground between the battery and the Arduino? You may be disconnecting the ground when you unplug the USB. Every voltage measurement requires a reference (2 connections) and in the case of the Arduino, it's the Arduino's ground.

What does "very unstable" mean? How much variation are you getting? Is the reading slowly drifting up & down, or is it jumping around "randomly"? Are the readings centered around the expected voltage (noisy), or just random?

With those relatively high value resistors in your voltage divider, you could be picking-up noise. Try adding a capacitor between the Arduino's analog input and ground (0.1uF or greater).

I do have a common ground, the battery is powering the Arduino while the Arduino measures the battery. The PSU is now in the place of the battery so I am able to adjust the voltage easily.

The variation is very randomly. Readings with 100 ms delay are for example: 671,655,630,647,479,647,640,632,663,679,634. While it is powered via USB the readings are more like 655,655,655,656,656,656,655,655,654,654,655 etc.

I already tried to put a capacitor between ground and analog in.

Your lab supply might have some ripple on it.
As suggested by DVDdoug, add a 100n cap from analogue-in to ground.
Something you have to do anyway when the voltage divider is made with high value resistors.
Pre-reading the pin, multiple reads, and averaging might also help.
Look at this example.
Leo..

/*
0 - ~17volt voltmeter
works with 3.3volt and 5volt Arduinos
uses the internal 1.1volt reference
10k resistor from A1 to ground, and 150k resistor from A1 to +batt
(1k8:27k or 2k2:33k are also valid 1:15 ratios)
100n capacitor from A1 to ground for stable readings
*/
float Aref = 1.075; // change this to the actual Aref voltage of ---YOUR--- Arduino (1.000 - 1.200), or adjust to get accurate voltage reading
unsigned int total; // A/D output
float voltage; // converted to volt
//
void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt reference, change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(9600); // ---set serial monitor to this value---
}
//
void loop() {
  analogRead(1); // one unused reading to clear old sh#t
  for (int x = 0; x < 16; x++) { // 16 analogue readings and 1/16 voltage divider = no additional maths
    total = total + analogRead(1); // add each value
  }
  voltage = total * Aref / 1024; // convert readings to volt
  // print to serial monitor
  Serial.print("The battery is ");
  Serial.print(voltage);
  Serial.println(" volt");
  total = 0; // reset value
  delay(1000); // readout delay
}

Hi,
Try 10K and 30K as your divider resistors,

Tom... :slight_smile:

Hi All,

I solved the problem by using a UNO instead of a MICRO... I'm not shure why but the Micro caused a HUGE spike (about 2.5 volts) on the Vin. Even when I disconnect everything the spike is still there. The strange thing is that it is sometimes gone and when I reconnect the Vin a couple of times it is back again.

Does anyone know why this is happening?