An Experiment

Before we go ahead and use the LEDs, you can try a little experiment using just the variable resistor also known as a potentiometer (often called a 'pot' for short) and the Arduino Serial Monitor.

Connect up your breadboard as shown below:

Load the following sketch onto your Arduino.

Download: file
/*
Adafruit Arduino - Lesson 8. Analog Inputs
*/

int potPin = 0;

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  int reading  = analogRead(potPin);
  Serial.println(reading);
  delay(500);
}

Now open the Serial Monitor, and you will see a stream of numbers appearing.

Turn the knob on the variable resistor and you will see the number change between 0 and 1023.

The Serial Monitor is displaying the analog reading value from A0 using the line:

Download: file
 int reading  = analogRead(potPin);

The voltage at A0 is being transformed into a number between 0 and 1023.

This guide was first published on Dec 10, 2012. It was last updated on Dec 10, 2012.
This page (An Experiment) was last updated on Aug 14, 2020.