Potentiometer Example

The potentiometer sends a voltage of between 0 and 5VDC to the Arduino analog input A0. The Arduino sketch monitors input A0 and turns on Arduino outputs 10, 11 and 12 as the A0 input increases from 0 – 5VDC

Hardware Required

  • 1 x Arduino Uno R3 or compatible
  • 3 x LED
  • 3 x 220 Ohm Resistor
  • 1 x Potentiometer
  • 1 x Solderless breadboard

Arduino Code

After you build the circuit plug your Arduino board into your computer, start the Arduino IDE, and enter the code below.

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().

The circuit:
– potentiometer
center pin of the potentiometer to the analog input 0
one side pin (either one) to ground
the other side pin to +5V
anode (long leg) attached to digital output 10 through 220 ohm resistor
cathode (short leg) attached to ground

created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe

This example code is in the public domain.


int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 10; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for milliseconds:
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for milliseconds:


Item added to cart.
0 items - R0.00