Analog Read and Ohm's Law

Digital Data

First we need to differentiate digital from analog. Computers are digital and at best can only approximate analog. For a full description of what this means check out How Stuff Works "Digital Data". The Arduino has 6 analog inputs (numbered from 0-5) that are capable of reading values from 0-1023. So, if you were to hook up a potentiometer to one of the analog inputs and twist the knob the input pin would report only numbers from 0-1023, even though there is really an infinite number of positions you can set the potentiometer to.

The Arduino sees the potentiometer as if it has 1024 hard stops (lick the ticking of a second hand on a watch for each second). It does not see the smooth motion from one step to the next. For example, if you have a 10 kOhm pot you can easily set it to any value from 0 Ohms to 10,000 Ohms. Not only 0 ohms, 1 ohm, 2 ohms, ect., but also 1.1 ohm, 1.01 ohm, 1.001ohm, 1.0001 ohm and so on. There is literally an infinite number of values from 0 ohms to 10,000 ohms you can hit. The Arduino will only ever see 1024 of those infinite number of settings.

Ohm's Law

Ohm's Law involves the relationship between voltage, current, and resistance (or load). A circuit, or component within a circuit, will always use all of the voltage available to it. The Arduino provides up to 5 V as an output voltage. The amount of current draw in a circuit depends on the load (resistance). The higher the resistance, the lower the current draw. It seems kind of backwards, but its true. The relationship can be expressed as:

V is voltage, I is current, and R is resistance. I know, it would be much easier of we used C rather than I, but C is reserved for capacitance.

Kirchoff's Law

Simply put, Kirchoff's Law states: current in = current out. So, if you have two resistors hooked in series from positive to negative they will each have the same current running through them. The result is that the two resistors will divide the total voltage. If the resistors are equal in size then they will divide it equally. If one is larger than it will get proportionately more voltage.

Conversely, if two resistors are hooked in parallel with one another they will divide the current available with the smaller resistor getting more of the current.

For more on the relationship between Ohm's and Kirchoff's laws you should check out the section on DC Voltage and Current in the Electronics text book at Wikibooks.

Analog Read

The analogRead(pin) command is really a voltage comparator. What does this mean? It means that it compares the voltage divided between two resistors in a series circuit. So the two resistors divide up the voltage proportionately. The larger resistor gets more of the 5 volts. Analog Read uses a different set of pins than we've been using. So far we've been using the digital pins. The digital pins can be inputs or outputs. The analog pins can only be inputs. They are numbered 0-5.