Calculating input voltage beforehand [Newbie question]

Being new to electronics I'm trying to wrap my head around the arduino and how to calculate what readings I will get using a pin to read the voltage. But I have no idea how to do the math. I even tried using circuit lab but to no prevail.

The reason why I'm confused is that I thought you could only measure voltage between to points and the potential difference between them. But the arduino measures at a specific point; the pin. How can I calculate that beforehand?

It would also be nice to know how I could then simulate the arduinos readings in circuit lab

Thanks

I'm not 100% sure what you're getting at, but this might answer your question.

The Arduino does use two pins to read an input: there's a ground as well as the pin you're using. So if you had 3xAA cells giving out about 4.5v, and you poked the +ve with a wire from an Arduino pin, you would get no reading. But if you connected the Arduino ground to the -ve of the battery, then you would get a reading: a digital pin would read a high, and an analog would give you about 0.9 of the 1023 max reading, ie about 920.

Thanks, that makes my mental model better.

But if I added a resistor to that circuit then the voltage readings would be the same, correct?
So if I wanted to vary the voltage to an analog pin depending on the resistance of a wire.
How would I then hook it up and calculate the voltage to the pin it?

Ah, then what you want is to look at a voltage divider, where the output voltage (which I guess then becomes your input voltage) depends on the ratio of the two reseistances.

In fact, a potentiometer is exactly that, where the "mid-point" actually moves along a long resistor. Pots have 3 connections: the "top" being the input voltage, the "bottom" being ground, and the "moving mid-point" is your variable output. Have a look at this tutorial.

MrDumle:
Thanks, that makes my mental model better.

But if I added a resistor to that circuit then the voltage readings would be the same, correct?
So if I wanted to vary the voltage to an analog pin depending on the resistance of a wire.
How would I then hook it up and calculate the voltage to the pin it?

Since the Arduino ADC has an extremely high input resistance (10^10 ohms or more) then a
series resistance isn't going to change the reading perceptibly. Your multimeter might be
affected (since it probably has a 10Mohm input resistance - and thus takes current from
the circuit it measures.

The reason for this in multimeters is specifically because they have resistor dividers to allow
different ranges - a resistive divider has finite resistance.

The Arduino ADC doesn't actually measure voltage at all, it measures the ratio of voltages, namely
the ratio of (pin - ground) / (Vcc - ground). So when powered at 3.3V it reads differently than
if powered at 5V.

JimboZA:
Ah, then what you want is to look at a voltage divider, where the output voltage (which I guess then becomes your input voltage) depends on the ratio of the two reseistances.

In fact, a potentiometer is exactly that, where the "mid-point" actually moves along a long resistor. Pots have 3 connections: the "top" being the input voltage, the "bottom" being ground, and the "moving mid-point" is your variable output. Have a look at this tutorial.

Interesting! But how do I go about calculating this? I would be great to have a general rule to calculate the voltage to the input pin. No matter the resistance and the amount of paths the current can flow in.

I would be great to have a general rule to calculate the voltage to the input pin. No matter the resistance and the amount of paths the current can flow in.

There is! :wink: [u]Ohm's Law[/u] describes the relationship between voltage, resistance, and current. [u]kirckhoff's Laws[/u] describe how voltages & currents are distributed in series & parallel circuits. (i.e. How a voltage divider works.)

Those things aren't necessarly that easy to understand.. it's a good part of your 1st semester in a basic electronics class.

In most real-world applications, the high impedance (resistance) of the Arduino input, means that the Arduino itself essentially has no effect on the voltage... It depends on the external circuit.

The exception is if you try to put-in more than 5V, or a negative voltage. In those cases, the Arduino's internal protection diodes start conducting, and you suddenly have very low impedance. And, if too much current flows through those protection diodes they will fry, and you will kill your Arduino...

The reason why I'm confused is that I thought you could only measure voltage between to points and the potential difference between them. But the arduino measures at a specific point; the pin.

The Arduino ADC readings are always with respect to ground (being the 2nd point).

Thanks for all the replies.

Is this the correct set-up then?

bump

no, vOut and GND are at the same level in your drawing.

michael_x:
no, vOut and GND are at the same level in your drawing.

MrDumle, I think it's best if you lose all the lines inside your dotted Arduino, leaving that as a "black box" and not try to visualise what happens inside. If you do that, and mark the dot you have marked as Vout as PinX just to indicate some Arduino i/o pin or other, then you'll be good. If you want the drg to be complete, move the Vout label to the dot between the resistors.

What you'll have then, is this tutorial

Ok, how about this then? :slight_smile:

We usually identify ourselves with the Arduino, so "Vout" and "Vin" sound rather strange.

But from the voltage divider point of view its perfect :slight_smile:

Thanks Micheal! Fixed! :slight_smile:

>If anyone want to modify the circuit<