Datasheet

Not Working
Make sure you haven't
accidentally connected the
potentiometer's wiper to digital
pin 0 rather than analog pin 0.
(the row of pins beneath the
power pins)
File > Examples > 3.Analog > AnalogInput
(example from the great arduino.cc site, check it out for other great ideas)
/* Analog Input
* Demonstrates analog input by reading an analog sensor on analog
* pin 0 and turning on and off a light emitting diode(LED) connected to
digital pin 13.
* The amount of time the LED will be on and off depends on the value obtained by
* analogRead().
* Created by David Cuartielles
* Modified 16 Jun 2009
* By Tom Igoe
* http://arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin = 0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT); //declare the ledPin as an OUTPUT:
}
void loop() {
sensorValue = analogRead(sensorPin);// read the value from the sensor:
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(sensorValue); // stop the program for <sensorValue> milliseconds:
digitalWrite(ledPin, LOW); // turn the ledPin off:
delay(sensorValue); // stop the program for for <sensorValue> milliseconds:
}
More details, where to buy more parts, where to ask more questions:
http://ardx.org/CIRC08
Sporadically Working
This is most likely due to a
slightly dodgy connection with
the potentiometer's pins. This
can usually be conquered by
taping the potentiometer down.
Threshold switching: Then change the loop code to.
void loop() {
Sometimes you will want to switch an output when a value
int value = analogRead(potPin) / 4;
exceeds a certain threshold. To do this with a
analogWrite(ledPin, value);
}
potentiometer change the loop() code to.
Upload the code and watch as your LED fades in relation to
void loop() {
your potentiometer spinning. (Note: the reason we divide the
int threshold = 512;
if(analogRead(sensorPin) > threshold){
value by 4 is the analogRead() function returns a value from 0
digitalWrite(ledPin, HIGH);}
to 1023 (10 bits), and analogWrite() takes a value from 0 to
else{ digitalWrite(ledPin, LOW);}
}
255 (8 bits) )
This will cause the LED to turn on when the value is above
Controlling a servo:
512 (about halfway), you can adjust the sensitivity by
This is a really neat example and brings a couple of circuits
changing the threshold value.
together. Wire up the servo like you did in CIRC-04, then open
Fading:
the example program Knob (File > Examples > Servo >
Let’s control the brightness of an LED directly from the
Knob ), then change one line of code.
potentiometer. To do this we need to first change the pin
int potpin = 0; ----> int potpin = 2;
Upload to your Arduino and then watch as the servo shaft turns
the LED is connected to. Move the wire from pin 13 to pin
as you turn the potentiometer.
9 and change one line in the code.
int ledPin = 13; ----> int ledPin = 9;
Still Backward
You can try operating the
circuit upside down.
Sometimes this helps.
23
CIRC-08
NOT WORKING? (3 things to try)
MAKING IT BETTER
CODE (no need to type everything in just click)
MORE, MORE, MORE: