User manual

www.sainsmart.com
Copyright © 2013 SainSmart All Rights Reserved
It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading
rate is about 10,000 times a second.
Syntax
analogRead(pin)
Parameters
pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini
and Nano, 0 to 15 on the Mega)
Returns
int (0 to 1023)
Whats Potentiometer?
A potentiometer is a simple knob that provides a variable resistance, which we can read into the
Arduino board as an analog value. In this example, that value controls the rate at which an LED
blinks.
We connect three wires to the Arduino board. The first goes to ground from one of the outer
pins of the potentiometer. The second goes from 5 volts to the other outer pin of the
potentiometer. The third goes from analog input 2 to the middle pin of the potentiometer.
By turning the shaft of the potentiometer, we change the amount of resistence on either side of
the wiper which is connected to the center pin of the potentiometer. This changes the relative
"closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is
turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the
shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read
1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to
the amount of voltage being applied to the pin.
Example code: