Arduino Tutorial 03: Analog Inputs

Welcome to the third Arduino Tutorial from our Arduino Tutorial Series. In this tutorial we will learn how the Arduino Analog Inputs pins work and make few examples using a potentiometer and a photocell.

This is a Step by Step Video Tutorial which is easy to be followed. Also, below the video you can find what Parts do we need for this tutorial and the Source Codes of the Examples in the video.

Components needed for this Arduino Tutorial

  •  Arduino Board – [Get One]
  • Breadboard and Jump Wires – [Get One]
  • Potentiometer
  • Photocell (Photo-resistor)
  • LED
  • 220 & 10k Ohm Resistors

Circuit schematic of the first example. Using the potentiometer value as analog input

Analog Inputs Circuit Schematic 01

Circuit schematic of the second example. Using the photocell as a voltage divider and it’s variable value as analog input

Analog Inputs Circuit Schematic 02

Source Code of the first and the second example

void setup() {

void loop() {
int sensorValue = analogRead(A0);

Circuit schematic of the third example. Using the potentiometer to control the LED brightness via PWM

Analog Inputs Circuit Schematic 03

Source Code of the third example

int led = 7;

void setup() {
pinMode(led, OUTPUT);

void loop() {
int sensorValue = analogRead(A0);
int newValeu = map(sensorValue, 0, 1023, 0, 255);
analogWrite(led, newValeu);

6 Responses

  1. Liam

    Hi there
    Would you be able to post code to control 2 stepper motors with a potentiometer, I have tried myself by cant seem to work it out.

  2. stark

    how can I control 2 motors with two potentiometers?

    I tried to duplicate the code twice and changing the names so that it can read from A0 and A1 but didn’t work

    • Dejan Nedelkovski

      Sure, you can do that. You can’t duplicate the entire code twice, you need to duplicate and rename the motor and potentiometer definitions.


Leave a Reply

Your email address will not be published.