 I am working with a bread board ATMEGA328P that is regulated to 2.8V running the internal 8mhz oscillator. I want to measure the voltage of a lipo battery which is 4.2V when fully charged. I use a voltage divider to reduce the lipo voltage and then connect to the ADC. On the Aruino side I use the internal 1.1V reference. This project runs on a tiny battery and I have to be super careful about every micro amp. With that in mind I used very high impedence resisters for the voltage divider to limit the current consumption on the ADC. I am still kind of new so that might be a bad idea but that was my thought process. For the voltage divider I used a 330k and 100k resistor which gives me a max voltage to the ADC of 0.977V. I sample the ADC 6 times and then divide the number in order to get the ADC number. I check the battery voltage every hour and then put the unit to sleep again.The problem I have is my readings seem to be inconsistent and I am pretty sure the issue is the resistor values. My question is what is the best option on the hardware side? Can I put a small cap in between the ADC and the voltage divider? Or do I really need to reduce the values of the resistors I am using?

Here is the code I am using to poll the ADC value.

``````ADCSRA |= (1 << ADEN); // Enable ADC
analogReference(2); //sets the reference to 1.1V internal. Using a voltage divider off VCC for a max of 0.997
digitalWrite(A1, INPUT); //ADC line to lipo
pinMode(A1, LOW);
volts = 0; //reset the variable
delay(2000);
for(int i = 0; i < 6; i++){
volts = volts + analogRead(A1);     //get analog reading 6 times and then average them
delay(100);
}
volts = volts /6;
``````

fbriggs4: This project runs on a tiny battery and I have to be super careful about every micro amp. With that in mind I used very high impedence resisters for the voltage divider to limit the current consumption on the ADC. I am still kind of new so that might be a bad idea but that was my thought process.

The ADC has a little capacitor that it charges up for sampling, you need a minimum amount current to charge it up in the sampling period.

But...if you're only reading from one analog pin, and it's a signal that changes very slowly, you're OK because the voltage entering the ADC doesn't change much between samples.

In fact you should probably add another capacitor between the analog input pin and GND to reduce noise on the input wires.

fbriggs4: Or do I really need to reduce the values of the resistors I am using?

You could consider using an opamp in unity mode and a mosfet to switch this circuit on. In that way, the current will be minimal and only when you measure and you will have a super low impedance. Now the resistors will drain current all the time. Using a switch and the opamp will let it draw current only when you measure. And potentially a couple of microamps when sleeping.

A couple of things: 1) running the internal 8[u]MH[/u]z oscillator. 2) Post your code.

``````  digitalWrite(A1, INPUT); //ADC line to lipo
pinMode(A1, LOW);
``````

I think you have those backwards.

That little piece of code makes me frown.

If current is so important, why have a delay of 100ms? And also a delay of 2000ms.

If you take the average of 20 samples without delay, you have a better result. Do you need to reject 50Hz or 60Hz mains noise ? In that case you do need a delay.

What kind of capacitor is there on Aref ? If it is 100nF, wait 20ms after selecting analogReference. If there is no capacitor, about 100us will be enough.

The 100k and 330k is no problem. You could add a 1nF to A1 and GND.

Please don't use '2' with this: "analogReference(2)". Use one of the defines. Also correct the code as James C4S wrote.

I have a standalone ATmega connected to the mains and high impedance input. I had to take the average of 10000 samples for a very stable value. I also have a battery powered standalone ATmega. I use the average of 3 and 5 samples (without delay between them) for high impedance inputs. That was good enough. I use the normal analogRead function. So I guess your 6 times is just fine.