# Trying to measure voltage between two points

Dear community,

I believe this is a very basic question but I’m a bit stuck in a circuit I’m trying to build - this is one my very first tries with Arduino and electronics in general. I’m trying to use the arduino as a voltmeter.

The first setup I tried was the one as shown in the added picture “digital-voltmeter-arduino”. This comes directly from a tutorial (http://www.allaboutcircuits.com/projects/make-a-digital-voltmeter-using-the-arduino/). This gives me 0.0V, which makes sense to me because the A0 input is connected to the ground. Now I wanted to see some voltage appear. Since I was afraid to burn my arduino, I didn’t directly plug the 5V into the A0 input, but added a resistance of 15KOhms between 5V and the input A0. However, my voltmeter (well, the LCD output of my Arduino) gives 4.9-5.0V. Shouldn’t it be lower, since I added a resistance?

I should add that this is my code (well, basically the tutorial’s code except the names of the pins)

``````#include "LiquidCrystal.h"

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float input_voltage = 0.0;
float temp=0.0;

void setup()
{
Serial.begin(9600);     //  opens serial port, sets data rate to 9600 bps
lcd.begin(16, 2);       //// set up the LCD's number of columns and rows:
lcd.print("DIGITAL VOLTMETER");
}
void loop()
{

//Conversion formula for voltage

input_voltage = (analog_value * 5.0) / 1024.0;

if (input_voltage < 0.1)
{
input_voltage=0.0;
}
Serial.print("v= ");
Serial.println(input_voltage);
lcd.setCursor(0, 1);
lcd.print("Voltage= ");
lcd.print(input_voltage);
delay(300);
}
``````

Thanks a lot!

It is safe to connect the analog inputs directly to 5V, but not safe if the voltage is greater than about 5.5V (or over about 3.8V, if you are using a 3.3V Arduino).

Adding a 15K resistor in series with the analog input is a good idea, and it won’t make any difference for an analog voltage reading, because the input resistance of the analog input is somewhere around 100 megohms.

All right, so this explains why I still obtain 5V. Now, I would like to measure the voltage of a 2-AAA-battery pack (1.5V each) (picture attached). I am wondering where I should plug these in. I was thinking of plugging the black wire in the same ground powerail (which is also still commected to GND of Arduino), and connect the red wire to any point of the breadboard (disconnected from any other points), and then to link these two with a resistance. Or, maybe the black wire should also be wired to an independent point of the circuit, and again connect the red and the black wires through a resistance. Maybe this second option makes more sense? Also, I do need a resistance, right? Otherwise the current will be too high, no?

It really doesn't matter how you connect the batteries, as long as the negative terminal is connected to ground and the positive terminal to the analog input.

You do not need a resistor if the voltage is between 0 and 5V.

(picture attached).

Nope... didn't work...

You connect battery's negative connection to the Arduino's ground and connect the positive to the Arduino's analog input.

Make sure you don't short something to the Arduino's ground that isn't supposed to be grounded. And, make sure the voltage you're measuring is not negative and not greater than +5V.

Or, maybe the black wire should also be wired to an independent point of the circuit, and again connect the red and the black wires through a resistance.

You need a "ground reference". Assuming the black is negative, you can connect it directly to the Arduino's ground.

You don't need any resistance on the positive side, but it does limit the current to give you some safety if you exceed +5V or if you connect a negative voltage. The Arduino's high input impedance/resistance means that essentially no current flows (as long as you don't exceed Vcc or apply a negative voltage).

If you want to measure higher voltages you can use a [u]voltage divider[/u] (2 resistors) and if you have an unknown voltage or if you want to be extra-safe you can use a [u]protection circuit[/u].

Trying to measure voltage between two points

With the Arduino, one of those "points" must be ground and the other connection must have a positive voltage.

The black lead on a multimeter isn't necessarily ground and you can connect between any two "random points". And, multimeters are usually also protected up to a few hundred volts and you can also usually safely connect them backwards.

Thank you for the both of the last posts. I did as you told, plugging the negative end of the battery pack to the ground and the positive end to the analog input and it worked as I hoped. This is great!
@DVDdoug: thanks for the extra information, that made it clearer.

Now I attached a potentiometer (100kOhm) with one end to the positive side of the battery pack, the other end to the negative side of the battery pack and the middle end to the analogical input. I thought this would change the voltage, but the only thing I saw was a crazy toggling between 0V and 5V and back to 0V..! What am I doing wrong?

Nongsai:
Thank you for the both of the last posts. I did as you told, plugging the negative end of the battery pack to the ground and the positive end to the analog input and it worked as I hoped. This is great!
@DVDdoug: thanks for the extra information, that made it clearer.

Now I attached a potentiometer (100kOhm) with one end to the positive side of the battery pack, the other end to the negative side of the battery pack and the middle end to the analogical input. I thought this would change the voltage, but the only thing I saw was a crazy toggling between 0V and 5V and back to 0V..! What am I doing wrong?

Did you forget to connect the negative side of the battery pack to ground? With only one connection point, the whole battery+pot combo is floating with respect to the Arduino, so you get random readings. See the posts above.

To have any two circuits talk electrically, you need to connect the grounds. If you can't for some weird reason, then you need to take special measures, such as using an optoisolator or relay.

Indeed I had not connected the negative wire of the battery to the ground. No it works better, even though it has trouble stabilizing. But that's good enough for what I wanted to test.

So now I have been printing voltage on the LCD screen, however I would like to log this analogical input into an SD card. For some reason I couldn't find any tutorial for beginners explaining how to connect the shield to the Arduino (Mega ADK). For exmaple, in this tutorial it says "The Arduino or Genuino board has to be connected to the Ethernet Shield. " without giving any clue of how to do this. In this tutorial, there is no information either on how to connect the shield to the arduino. This can't be that hard, right?

The Arduino or Genuino board has to be connected to the Ethernet Shield. " without giving any clue of how to do this.

.
A shield fits over the Arduino it will only plug in one way round.

The word analogical is wrong it should be just analogue.

Nongsai:
I didn’t directly plug the 5V into the A0 input, but added a resistance of 15KOhms between 5V and the input A0. However, my voltmeter (well, the LCD output of my Arduino) gives 4.9-5.0V. Shouldn’t it be lower, since I added a resistance?

It would be lower IF the resistance that you had added were much greater than 15 kOhm. The theory is ‘voltage divider’. Assuming that the voltage source has relatively small ‘source impedance’… so ignoring voltage source impedance.

Then the voltage divider equation will show that the output voltage of the divider circuit will be approximately the same as the incoming source voltage whenever the newly added series resistance (impedance) is relatively small (compared with the impedance of the load, and the ‘load’ in this case is arduino “A0”).

If the newly added resistance is ‘significantly large’ (compared with the load), then you get the ‘loading effect’, which will lead to the voltage measured at output of the divider being much less than the actual source voltage (unless that effect is accounted for).

It would be lower IF the resistance that you had added were much greater than 15 kOhm. The theory is 'voltage divider'. Assuming that the voltage source has relatively small 'source impedance'.... so ignoring voltage source impedance.

It's a bit more complicated than that actually.

From section 24.6.1 Analog Input Circuitry in the datasheet (if you don't have it, download it, it is literally the most important document for everything about the chip)

The analog input circuitry for single ended channels is illustrated in Figure 24-8. An analog source applied to ADCn is subjected to the pin capacitance and input leakage of that pin, regardless of whether that channel is selected as input for the ADC. When the channel is selected, the source must drive the S/H capacitor through the series resistance (combined resistance in the input path).

The ADC is optimized for analog signals with an output impedance of approximately 10 k or less. If such a source is used, the sampling time will be negligible.

S/H is short for "Sample and Hold", a type of circuit that holds the voltage steady long enough to perform a full conversion so that you get a sensible result, even if the voltage applied to the pin changes in the middle of the conversion. It uses a capacitor to hold the voltage, so if the analog signals impedance is too large it won't be able to charge the capacitor to the correct level in time, so the result will be off.

100k is too large. At mid-scale (worst case), that's 50k equivalent output impedance, 5x what the datasheet recommends. Either buffer it with an op amp, or reduce the value to 20k or 10k.

Dear Grumpy_Mike, Southpark and Jiggy-Ninja,

Thank you for the valuable inputs. Indeed I realized that the shield had to be plugged in directly into the Arduino; I thought they had to be wired somehow. Thank you for this!

I now understand the concept of a voltage divider better. So from what I understand, voltage dividers are built up by connecting resistances in series. They can also be plugged in parallel, but only in order to "simulate different values for resistances in series", does that make sense?

Nongsai:
They can also be plugged in parallel, but only in order to "simulate different values for resistances in series", does that make sense?

Not really.

Putting resistors in parallel only changes the effective
resistance of the two resistors together. It is not a series
or a voltage divider unless there is a third series resistor.
Dwight

That's what I thought. Thank you!