voltage measurement error

This is before all programming. This problem is simple measurement. I am using a simple resistor divider to measure voltage. At this point all measurements are made with a standard digital VOM.

My objective is to measure the battery voltage of my alternate energy system so I can make decisions and take actions based on that. But before any of that can happen I need for this to be resolved.

I made a divider using a 4.7k and two 3.3k resistors as follows.

Input voltage 4.7K + 3.3K for a total of 8K. measure voltage 3.3K ground

When not plugged into the Arduino my divider performs exactly as the math would indicate. 16.54V = 4.83 15.00V = 4.381 12.00V = 3.504 11.60V = 3.388

When plugged in to the Arduino board I get the following. I have tried this on 2 different input pins.

16.54V = 4.03 15.00V = 4.00 12.00V = 3.504 11.60V = 3.388

I don't understand what is going on here. Why is my high end voltage not the same? The input impedance of the ADC is supposed to be 10Mohms as I understand it which should make no difference here.

Would appreciate any insight.

Brian

What's your VCC? If you're running off 3.3V those numbers would sort of make sense.

Hi, and welcome to the forum.

The result of the A/D depends on two things. 1) Input voltage 2) Reference voltage.

Don't expect 5volt (default Aref) to be a constant 5.000volt.

These values are not linear. Are you sure you just use a voltage divider, not some zener protection circuit? Leo..

Wawa, I assumed those numbers were multimeter values, not calculated from ADC readings.

Hi, What model Arduino are you using?

Tom... :)

As quickly as I can here.

Saximus,
Using a 9V wallwart into the barrel connector. Don’t know where that lands me actually divider is on an expander Maker board which I plug into the Arduino.

Wawa,
Hi and thanks. No it is literally a simple resistor divider. Not other components.

Saximus,
Correct these are multimeter readings. I figure if I can’t even get meter readings correct then measurement by the arduino doesn’t matter yet.

TomGeorge,
It is an Uno.

Thanks for the replies.

Have read that there should be <10K input impedance and have read on this forum that there should be >50K input impedance. I am trying to do a really simple thing here. Not sure if any of that is relevant. Was thinking about changing values to 122K (100K+22K) and 47K. Should get me about the same values range. All examples I have seen show much higher value resistors. Don’t know if this is a valid thought or not.

Have been doing electronics all my life with all kinds of processors and circuits doing all kinds of things in my professional life. I am new to the Arduino. I must be missing something specific to Arduino because this should work as far as I can tell.

Brian

Is it an Arduino or a clone?

Vcc is different to Vin. I was leaning to 3.3V for Vcc because the top two readings look like 3.3+0.7V as if the internal protection diodes are clipping it.

I don’t know which expander maker board you’re talking about (googling that phrase wasn’t very fruitful) but is there a chance that is clipping it?

arduinouserme: Using a 9V wallwart into the barrel connector. Don't know where that lands me actually divider is on an expander Maker board which I plug into the Arduino.

Is this a modern regulated switching supply, or a heavy unregulated transformer bassed old supply.

When you plug a supply into the DC jack, you don't have access to that voltage anymore. There is a reverse protection diode between the DC jack and V-in, so the V-in pin is the closest to this voltage. About 0.7volt less.

Still not exactly sure what's going on. Could you draw a diagram. Leo..

Saximus,

It is an Uno.

Is there some switch or jumper that I need to move maybe? I didn't see anything about that anywhere. What you say almost makes sense.

The maker board is simply a breadboard with headers that fits on an Arduino Uno. There is no circuitry going on that I don't add aside from some power and ground bussing which I am not using, a reset button and a pot which I am not using. There is literally nothing going on besides giving me a way to interface my circuit with the Arduino. I can't even find the board anymore online. It is just a bread board with headers. I got it on clearance from RadioShack because I saw it there and it was cheap and basic and easier than buying headers and cutting up a hunk of breadboard. It is nicely sized.

Wawa, I think it is a 9V switching wallwart. It is pretty light so that is my experienced guess. I get the diode so that would be around 8.3V. The onboard surface mount three terminal regulator should bring that down to 5V. I can measure to be sure. Drawing. Let me figure out how I will do that. I no longer have access to a nice schematic capture program.

Brian

Let's see if this works. It is this with my resistor divider and a 2 pin terminal block.

http://makezine.com/wp-content/uploads/2012/12/BjLipOJWdDmlVSSP.jpg

Here are the instructions for the board.

http://makezine.com/projects/build-a-makershield/

This is the best schematic I can come up with at the moment.

So, if I understand this correctly... you are attaching the voltage output from your resistor divider to the A5 pin of the Uno and the pin loads the voltage down.

You said in your opening post that "this was before any programming". Have you at least programmed the AtMega328 with a program that leaves the A5 pin in a known, high impedance state? Seems to me you are assuming the pin is set for an analog input. What would happen if the pin was last used as a digital input with the internal pull-up resistor enabled?

I do have a small program loaded that defines A0 as an analog input and reads it to determine whether to turn an LED on or off based on voltage level. If the internal pull up was enabled wouldn't that set the pin at 5V without anything attached to it? That has been my experience with other circuitry. I do not see anything that allows me to declare an analog input pin as anything but an analog input and I don't see a pull up for that as an option. Either way I just defined it as an input.

Would undefined analog input pins be anything but a high impedance input if they were never defined before?

avr_fred: So, if I understand this correctly... you are attaching the voltage output from your resistor divider to the A5 pin of the Uno and the pin loads the voltage down.

I wonder if the Arduino was turned on when the measurements were taken.

Without the Arduino being powered, the pin would act as a zener diode (pin protection diode to VCC). That would explain things. Leo..

Wawa: I wonder if the Arduino was turned on when the measurements were taken.

Without the Arduino being powered, the pin would act as a zener diode (pin protection diode to VCC). That would explain things. Leo..

Leo... Good thought... Tom.. :)

Use a 2K2 resistor (ground connection) and the problem will be gone. And your analogue input is better protected from higher voltages. If you need high resolution, use a 2K7 resistor.

At 16.5V you get 4.83V which is quite high. If your Arduino internal power regulator gives you maybe only 4,7V your input is higher then the input voltage of your Arduino chip. The analogue input sees an overvoltage and is no longer high impedance.

The same values at 12V and 11.6V input are an indicator for this.

Wawa (Leo?),

Yes it was powered on. I didn't know if that would make a difference or not but it was on just to be the correct operating condition.

arduinoaleman,

I will give that a try. I would like to get my voltage range to the highest resolution possible. I was also trying to keep the current through the divider as low as possible. 1.5mA should be fine.

So the input range is not actually 0-5V as the spec says?

Thanks all. I will keep you posted.

Brian

arduinouserme: So the input range is not actually 0-5V as the spec says?

I have a clone board that runs at about 4.5V when it's powered from USB.

I don't know how practical this is for you to do but I'd be keen to see more voltage measurements to determine if it is always topping out at about 4V or it was just those two particular voltages. The easy way would be to replace your bottom resistor with a potentiometer and keep your voltage source constant. Just make sure you have enough resistance between the power supply and Arduino to limit the current in case it is the internal protection diodes causing the clipping.

arduinouserme:
So the input range is not actually 0-5V as the spec says?

Input range is 0volt to VCC (~5volt on a 5volt Arduino, when on).
Working range 0volt to Aref (normally the same as VCC, but Arduinos can be set to a lower Aref).
It seems that you want to measure a 12volt battery system.
Much better (stable) to use Arduino’s internal reference voltage.
Here is a sketch that uses that. Read the comments.
Leo…

/*
  0 - ~17volt voltmeter
  works with 3.3volt and 5volt Arduinos
  uses the stable internal 1.1volt reference
  10k resistor from A0 to ground, and 150k resistor from A0 to +batt
  (1k8:27k or 2k2:33k are also valid 1:15 ratios)
  100n capacitor from A0 to ground for stable readings
*/

unsigned int total; // holds readings
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() {
  total = 0; // reset
  analogRead(A0); // one unused reading to clear any ghost charge
  for (int x = 0; x < 64; x++) { // 64 analogue readings for averaging
    total = total + analogRead(A0); // add each value
  }
  voltage = total * 0.0002567; // convert readings to volt | ---calibrate by changing the last three digits---

  Serial.print("The battery is ");
  Serial.print(voltage); // change to (voltage, 3) for three decimal places
  Serial.println(" volt");
  delay(1000); // use a non-blocking delay when used with other code
}