# How exactly is voltage measured on an Arduino?

How do the analog pins on an Arduino measure voltage?

Do they either measure current and calculate the voltage with Ohm's law? (If so, why can we only read voltage and not current directly?)

Or do they compare the unknown input voltage with a known internal one? (If so, how does that work? What's the known voltage?)

Known voltage is usually provided by a diode or similar reference. The atmega328p chip has a separate aref pin so you can choose your own reference.

An ADC or analog to digital converter http://en.m.wikipedia.org/wiki/Analog-to-digital_converter is a collection of comparators. A comparator is a logic gate that simply tells which of two inputs has more voltage. This aref voltage is divided evenly into 2^10 values (it's a 10 bit ADC). Then the incoming signal is compared against all of these and the largest comparator which triggers is the reading you get in your arduino code.

• A flash converter is a collection of comparators. The ADC in the ATmega328/1280/2560 is a successive approximation converter, which uses a DAC and comparator. This is all described in the datasheet. Apr 11 '15 at 18:09
• Thanks! Really satisfying to finally know how it works. Would you mind quickly explaining how comparators are triggered, if you happen to know? Apr 11 '15 at 18:22

The Arduino uses a 10 bit Analog to Digital Converter(ADC). A good ADC is made such that it has only as many comparators as is the resolution of the ADC (in BITS) . Therefore the Arduino should have only ten comparators.
More detailed:
Comparator Number Trigger voltage
1.(LSB).............................. (5/1024)V
2........................................ (5/512)V
3........................................(5/256)V
..........and so on till
4.(MSB)..............................(5/2)V

So, for a voltage of say 2.75V, you will get a value of 768(11000000 in Binary)

Update:If you choose to give and use a separate Ref Voltage to the Arduino, It replaces the 5V with the new ref voltage.
Update 2: Sometimes a single comparator may be used in exchange of all 10 comparators.i.e., it is used to trigger all the bits .But the voltage at which each bit is triggered remains same.

• @PenguinCake The simplest comparator is an Op-Amp.Search Google for more info on Op-Amps. Apr 12 '15 at 9:29
• Op amps make terrible comparators. And the ADC in AVRs only uses a single comparator. Apr 13 '15 at 16:19
• Are you sure? Is it a single comparator or a single device that has 10 comparators? While it is possible to use a single comparator, it is usually much slower. Apr 14 '15 at 8:34
• It is a single comparator. It is used to compare the input versus the output of a DAC. I can't think of any way of using 10 comparators that would be any faster than using 1. Apr 14 '15 at 13:31
• When using single comparator, it uses 2 cycles per bit, whereas with 10 different ones, it takes one per bit. Apr 14 '15 at 16:16

The Arduino uses a analog-to-digital converter. For instance on the Arduino Uno there is a 10-bit ADC. Therefore the resolution is 2^10 bits which is 1024 different representations. As the Uno runs at 5V, each step represents 4.9mV.

The actual inner workings of the ADC can be quite complex and I don't exactly know which specific type it uses, but there can be many ways. One example is measuring time to discharge of a known capacitor. Another is comparing the voltage to the running voltage and using a counter.

I'm not sure what the answer is or why no one has addressed the second part of your question. To calculate current you need to know voltage and resistance (I=E/R). The ADC is giving you the voltage but I don't know what value to use for resistance in order to calculate the current. I do better with digital electronics but I suspect you might be able to use a resistor divider network to measure the voltage drop across a known resistor to measure current but do not take my word for this.