Potentiometer Analog Input Using Arduino Uno in Wokwi – Complete Beginner Guide

Potentiometer Analog Input with Arduino Uno – Wokwi Simulation | MakeMindz ▶ Simulate
Beginner · Arduino Uno · Wokwi

Potentiometer
Analog Input
Arduino Uno

Turn a knob — control LED brightness, servo angle, and RGB colour zones simultaneously. Learn ADC, PWM, and map() all in one project.

🔌 Arduino Uno 📻 10kΩ Potentiometer 💡 LED + RGB ⚙️ Servo Motor 🌐 Free on Wokwi ⏱ ~30 min
00 · Overview

What You'll Build & Learn

This beginner-friendly project teaches how to read analog input from a 10kΩ potentiometer with Arduino Uno. One knob controls four outputs simultaneously: LED brightness, RGB colour zones, servo angle, and live Serial Monitor data.

📊

ADC Reading

Understand 10-bit analog-to-digital conversion (0–1023)

💡

PWM Output

Control LED brightness smoothly with analogWrite()

📐

map() Function

Scale ADC values to voltage, %, brightness and servo angle

🎨

RGB Zones

Multi-range analog mapping: Red → Green → Blue

⚙️

Servo Control

Turn the knob to sweep a servo from 0° to 180°

📟

Serial Monitor

Live debugging: view raw ADC, voltage, %, brightness & angle

01 · Components

What You Need

All virtual components are available free in Wokwi — no shopping required.

Components for the Potentiometer Analog Input project
#ComponentQtyRole
1Arduino Uno×1Main controller — reads the potentiometer and drives all outputs
210kΩ Potentiometer×1Variable resistor that sends 0–5V to analog pin A0
3LED (Yellow)×1PWM brightness control via pin 9
4LEDs (Red, Green, Blue)×3RGB colour zones mapped to 0–33%, 34–66%, 67–100% of knob
5220Ω Resistors×4Current limiting for all 4 LEDs
6Servo Motor (SG90)×1Angle controlled 0°–180° by the potentiometer position
7Jumper Wires×~12All component connections
02 · Circuit Wiring

Circuit Connections

If you paste the diagram.json (see section below), all wiring is automatic. Use this table for manual reference.

Potentiometer

Pot PinArduino ConnectionWire
Left Pin5VRed
Middle (Wiper)A0 — variable voltage 0–5VGreen
Right PinGNDBlack

LEDs & Servo

ComponentPinArduinoWire
Yellow LED (via 220Ω)Anode → R → ArduinoPin 9 (PWM)Yellow
Red LED (via 220Ω)Anode → R → ArduinoPin 3 (PWM)Red
Green LED (via 220Ω)Anode → R → ArduinoPin 5 (PWM)Green
Blue LED (via 220Ω)Anode → R → ArduinoPin 6 (PWM)Blue
All LED CathodesCathodeGNDBlack
Servo (Red)V+5VRed
Servo (Brown)GNDGNDBlack
Servo (Orange)PWM SignalPin 10Orange
💡 All LED and servo PWM pins (3, 5, 6, 9, 10) are marked with a ~ symbol on the Arduino Uno board. Only these pins support analogWrite().
03 · Interactive Demo

Try It — Drag the Knob

Drag the slider to simulate rotating the potentiometer. Watch all 4 outputs update in real time.

Live Potentiometer Simulator — Drag to Control

512
0ADC value (0–1023)1023
Raw Voltage Percent Bright Angle
-----------------------------------------
512 2.50V 50% 127 90°
04 · How It Works

The Control Loop Explained

The Arduino Uno has a 10-bit ADC — it converts 0–5V into a digital value from 0 to 1023.

0
0V → 0
512
2.5V → ~512
1023
5V → 1023

Read the Potentiometer

analogRead(A0) returns a value from 0 to 1023 corresponding to the wiper voltage (0–5V). This is the raw ADC value.

Convert Using map()

The map() function linearly scales the ADC value to the desired output range. For example:

  • Brightness: map(potValue, 0, 1023, 0, 255)
  • Servo angle: map(potValue, 0, 1023, 0, 180)
  • Percentage: map(potValue, 0, 1023, 0, 100)

Control LED Brightness (PWM)

analogWrite(LED_PIN, brightness) uses PWM (Pulse Width Modulation) to smoothly vary LED intensity from off (0) to full brightness (255).

ℹ️PWM pins on Arduino Uno are: 3, 5, 6, 9, 10, 11 — marked with ~ on the board.

RGB LED Colour Zones

0–33%
🔴 Red
34–66%
🟢 Green
67–100%
🔵 Blue

Each zone gradually brightens its LED as the knob sweeps through that third — demonstrating multi-range analog mapping.

Servo Motor Control

myServo.write(servoAngle) positions the servo horn from 0° to 180° in direct proportion to the potentiometer rotation.

Serial Monitor Output

Every 100 ms the code prints a formatted table row to the Serial Monitor so you can visualise the ADC conversion in real time:

Raw Voltage Percent Bright Angle
-----------------------------------------
512 2.50V 50% 127 90°
768 3.75V 75% 191 135°
1023 5.00V 100% 255 180°
05 · Arduino Code

The Complete Sketch

Paste this into the sketch.ino tab in Wokwi. The code is organised into clean helper functions for each output.

sketch.ino — Potentiometer Analog Input
/*
 * Potentiometer Analog Input with Arduino Uno
 * Features: LED brightness, servo motor, RGB LED, serial output
 * Platform:  Wokwi Simulator · MakeMindz Summer Course
 */

#include <Servo.h>

// ── Pin Definitions ──────────────────────────────
const int POT_PIN   = A0;  // Potentiometer wiper → A0
const int LED_PIN   = 9;   // PWM yellow LED
const int LED_RED   = 3;   // RGB Red   (PWM)
const int LED_GREEN = 5;   // RGB Green (PWM)
const int LED_BLUE  = 6;   // RGB Blue  (PWM)
const int SERVO_PIN = 10;  // Servo signal

// ── Variables ────────────────────────────────────
int potValue  = 0;
int brightness = 0;
int servoAngle = 0;
float voltage  = 0.0;
int percentage = 0;

Servo myServo;

unsigned long lastUpdate = 0;
const int updateInterval = 100;

// ── setup() ──────────────────────────────────────
void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN,   OUTPUT);
  pinMode(LED_RED,   OUTPUT);
  pinMode(LED_GREEN, OUTPUT);
  pinMode(LED_BLUE,  OUTPUT);
  myServo.attach(SERVO_PIN);

  Serial.println("=================================");
  Serial.println("  Potentiometer Analog Input");
  Serial.println("=================================");
  Serial.println("Raw\tVoltage\tPercent\tBright\tAngle");
  Serial.println("-----------------------------------------");

  testSequence();  // Boot animation
}

// ── loop() ───────────────────────────────────────
void loop() {
  readPotentiometer();
  controlLED();
  controlRGBLED();
  controlServo();

  if (millis() - lastUpdate >= updateInterval) {
    lastUpdate = millis();
    displayData();
  }
  delay(10);
}

// ── Read & Convert ───────────────────────────────
void readPotentiometer() {
  potValue   = analogRead(POT_PIN);
  voltage    = potValue * (5.0 / 1023.0);
  percentage = map(potValue, 0, 1023, 0, 100);
  brightness = map(potValue, 0, 1023, 0, 255);
  servoAngle = map(potValue, 0, 1023, 0, 180);
}

// ── LED Brightness (PWM) ─────────────────────────
void controlLED() {
  analogWrite(LED_PIN, brightness);
}

// ── RGB LED Colour Zones ─────────────────────────
void controlRGBLED() {
  if (potValue < 341) {
    // 0–33%: Red zone
    analogWrite(LED_RED,   map(potValue, 0,   341, 0, 255));
    analogWrite(LED_GREEN, 0);
    analogWrite(LED_BLUE,  0);
  } else if (potValue < 682) {
    // 34–66%: Green zone
    analogWrite(LED_RED,   0);
    analogWrite(LED_GREEN, map(potValue, 341, 682, 0, 255));
    analogWrite(LED_BLUE,  0);
  } else {
    // 67–100%: Blue zone
    analogWrite(LED_RED,   0);
    analogWrite(LED_GREEN, 0);
    analogWrite(LED_BLUE,  map(potValue, 682, 1023, 0, 255));
  }
}

// ── Servo Control ────────────────────────────────
void controlServo() {
  myServo.write(servoAngle);
}

// ── Serial Monitor Output ────────────────────────
void displayData() {
  Serial.print(potValue);  Serial.print("\t");
  Serial.print(voltage, 2); Serial.print("V\t");
  Serial.print(percentage); Serial.print("%\t");
  Serial.print(brightness);  Serial.print("\t");
  Serial.print(servoAngle);  Serial.println("°");
}

// ── Boot Test Sequence ───────────────────────────
void testSequence() {
  Serial.println("Running startup test...");
  // Fade LED up and down
  for (int i=0; i<=255; i+=5) { analogWrite(LED_PIN, i); delay(10); }
  for (int i=255; i>=0; i-=5) { analogWrite(LED_PIN, i); delay(10); }
  // Flash RGB colours
  analogWrite(LED_RED,   255); delay(300); analogWrite(LED_RED,   0);
  analogWrite(LED_GREEN, 255); delay(300); analogWrite(LED_GREEN, 0);
  analogWrite(LED_BLUE,  255); delay(300); analogWrite(LED_BLUE,  0);
  // Servo sweep
  for (int a=0;  a<=180; a+=10) { myServo.write(a); delay(20); }
  for (int a=180; a>=0;  a-=10) { myServo.write(a); delay(20); }
  Serial.println("Test complete! Ready for input.");
}
💜 The code uses millis() instead of blocking delay() for the Serial output — this keeps all outputs responsive while printing data every 100 ms.
06 · Wokwi Circuit File

diagram.json — Paste to Auto-Wire Everything

In Wokwi, click the diagram.json tab, select all (Ctrl+A), delete, paste this, and press Ctrl+S. All components appear and wire themselves automatically.

⚠️ Copy the complete JSON — it starts with { and ends with }. Don't truncate any brackets or the circuit won't load.
diagram.json — Paste into Wokwi
{
  "version": 1,
  "author": "Potentiometer Analog Input",
  "editor": "wokwi",
  "parts": [
    {
      "type": "wokwi-arduino-uno",
      "id": "uno",
      "top": 0, "left": 0, "attrs": {}
    },
    {
      "type": "wokwi-potentiometer",
      "id": "pot1",
      "top": -57.6, "left": -201.6,
      "rotate": 90,
      "attrs": { "value": "512" }
    },
    {
      "type": "wokwi-led", "id": "led1",
      "top": -96, "left": 153.6,
      "attrs": { "color": "yellow" }
    },
    {
      "type": "wokwi-resistor", "id": "r1",
      "top": -9.6, "left": 153.6,
      "rotate": 90, "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led", "id": "led_red",
      "top": -96, "left": 249.6,
      "attrs": { "color": "red" }
    },
    {
      "type": "wokwi-led", "id": "led_green",
      "top": -96, "left": 297.6,
      "attrs": { "color": "green" }
    },
    {
      "type": "wokwi-led", "id": "led_blue",
      "top": -96, "left": 345.6,
      "attrs": { "color": "blue" }
    },
    {
      "type": "wokwi-resistor", "id": "r2",
      "top": -9.6, "left": 249.6,
      "rotate": 90, "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-resistor", "id": "r3",
      "top": -9.6, "left": 297.6,
      "rotate": 90, "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-resistor", "id": "r4",
      "top": -9.6, "left": 345.6,
      "rotate": 90, "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-servo", "id": "servo1",
      "top": 172.8, "left": -288, "attrs": {}
    }
  ],
  "connections": [
    [ "pot1:GND",    "uno:GND.1", "black",  ["v0"] ],
    [ "pot1:VCC",    "uno:5V",    "red",    ["v0"] ],
    [ "pot1:SIG",    "uno:A0",    "green",  ["v0"] ],
    [ "led1:A",      "r1:1",      "yellow", ["v0"] ],
    [ "r1:2",        "uno:9",     "yellow", ["v0"] ],
    [ "led1:C",      "uno:GND.2", "black",  ["v0"] ],
    [ "led_red:A",   "r2:1",      "red",    ["v0"] ],
    [ "r2:2",        "uno:3",     "red",    ["v0"] ],
    [ "led_red:C",   "uno:GND.2", "black",  ["v0"] ],
    [ "led_green:A", "r3:1",      "green",  ["v0"] ],
    [ "r3:2",        "uno:5",     "green",  ["v0"] ],
    [ "led_green:C", "uno:GND.2", "black",  ["v0"] ],
    [ "led_blue:A",  "r4:1",      "blue",   ["v0"] ],
    [ "r4:2",        "uno:6",     "blue",   ["v0"] ],
    [ "led_blue:C",  "uno:GND.2", "black",  ["v0"] ],
    [ "servo1:GND",  "uno:GND.3", "black",  ["v0"] ],
    [ "servo1:V+",   "uno:5V",    "red",    ["v0"] ],
    [ "servo1:PWM",  "uno:10",    "orange", ["v0"] ]
  ],
  "dependencies": {}
}

Open the Pre-Built Simulation

Circuit already wired with code loaded — just click ▶ Play and rotate the potentiometer dial.

▶ Launch Wokwi →
07 · Knowledge Check

Quick Quiz

Test your understanding of analog input and ADC conversion. Select an answer and click Check.

1 Why does analogRead() return values from 0 to 1023?

2 Which pin receives the potentiometer wiper output?

3 What colour does the RGB LED show when potValue = 200 (≈20%)?

4 If analogRead(A0) returns 768, what servo angle will be set?

5 Why must analogWrite() use PWM pins (3, 5, 6, 9, 10, 11)?

08 · FAQ

Frequently Asked Questions

Q1: Why does analogRead() give values from 0–1023?

Because the Arduino Uno uses a 10-bit ADC (2¹⁰ = 1024 discrete levels). The 5V supply is divided into 1024 steps, giving a resolution of about 4.9 mV per step.

Q2: Can I use this to control LED brightness?

Yes! Use map() to scale the ADC value to 0–255, then pass it to analogWrite() for smooth PWM brightness control.

Q3: Is this project beginner-friendly?

Absolutely. This is one of the first projects every Arduino learner should build. It teaches ADC, PWM, and the map() function — the three most fundamental analog skills.

Q4: What is the difference between analogRead() and digitalRead()?

digitalRead() returns only HIGH or LOW (1 or 0). analogRead() returns any value from 0 to 1023, capturing the exact voltage level — essential for variable sensors like potentiometers.

🧠 MakeMindz

Potentiometer Analog Input using Arduino Uno — Wokwi Simulation

Simulate free at wokwi.com · Visit makemindz.com

Comments

try for free