Control An Led With Potentiometer Aruino

7 min read

Controlling an LED with a potentiometer using Arduino is a practical way to adjust light brightness with a simple rotating or sliding control. This beginner-friendly project demonstrates how Arduino reads an analog signal, converts it into digital data, and uses pulse-width modulation to control an electronic component.

Introduction

A potentiometer is a variable resistor with three connection points. Turning its knob changes the resistance between its terminals and produces a variable voltage. An Arduino can measure that voltage through an analog input pin and use the reading to control an LED’s brightness.

This project is useful for learning several fundamental electronics and programming concepts:

  • Reading analog input with analogRead()
  • Converting sensor values with map()
  • Producing variable output with analogWrite()
  • Understanding pulse-width modulation, or PWM
  • Connecting LEDs, resistors, and potentiometers safely

No advanced components are required. A standard Arduino board, one LED, one potentiometer, one resistor, and a few jumper wires are enough to build the circuit Surprisingly effective..

Components Required

You will need the following components:

  • 1 × Arduino Uno, Nano, or compatible board
  • 1 × LED
  • 1 × 220 Ω to 330 Ω resistor
  • 1 × 10 kΩ potentiometer
  • Breadboard
  • Jumper wires
  • USB cable for powering and programming the Arduino

A 10 kΩ potentiometer is commonly used because it provides a suitable resistance range for Arduino analog inputs. Values between approximately 1 kΩ and 100 kΩ can work, but 10 kΩ is a reliable choice for this project.

How the Circuit Works

The potentiometer acts as a voltage divider. One outer terminal connects to the Arduino’s voltage supply, while the other outer terminal connects to ground. The middle terminal, called the wiper, connects to an analog input.

When the knob is turned:

  • The voltage at the wiper changes.
  • Arduino measures the voltage through the analog pin.
  • The measurement is converted into a number from 0 to 1023.
  • The program converts that number into a PWM value from 0 to 255.
  • The LED becomes brighter or dimmer depending on the potentiometer position.

The resistor connected to the LED limits electrical current. Without this resistor, too much current could flow through the LED and damage it or the Arduino.

Circuit Connections

Connect the components as follows:

Potentiometer

Potentiometer Terminal Arduino Connection
Left outer terminal 5V
Right outer terminal GND
Middle terminal A0

The left and right terminals may be exchanged. If the LED brightness changes in the opposite direction from what you expect, swap the two outer potentiometer connections Easy to understand, harder to ignore. Worth knowing..

LED Circuit

LED Component Arduino Connection
LED long leg, or anode Digital pin 9 through a 220 Ω resistor
LED short leg, or cathode GND

The resistor may be placed on either side of the LED, but placing it between digital pin 9 and the LED anode is a common arrangement Worth keeping that in mind..

Digital pin 9 is used because it supports PWM on Arduino Uno, Nano, and many compatible boards. On an Uno, PWM-capable pins are usually marked with a tilde symbol, such as ~ The details matter here. Still holds up..

Complete Arduino Code

Upload the following program to your Arduino:

const int potentiometerPin = A0;
const int ledPin = 9;

int potentiometerValue = 0;
int ledBrightness = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  potentiometerValue = analogRead(potentiometerPin);

  ledBrightness = map(potentiometerValue, 0, 1023, 0, 255);

  analogWrite(ledPin, ledBrightness);

  Serial.print("Potentiometer: ");
  Serial.Practically speaking, print(potentiometerValue);
  Serial. print(" | LED brightness: ");
  Serial.

  delay(10);
}

Explanation of the Code

The program begins by assigning names to the pins used by the circuit:

const int potentiometerPin = A0;
const int ledPin = 9;

Using named variables makes the program easier to read and modify. If the circuit changes later, the pin numbers only need to be updated in one location.

Two integer variables store the values read from the potentiometer and the brightness level sent to the LED:

int potentiometerValue = 0;
int ledBrightness = 0;

The setup() Function

The setup() function runs once when the Arduino starts:

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

pinMode(ledPin, OUTPUT) configures digital pin 9 as an output. This allows the Arduino to control the LED The details matter here..

Serial.Because of that, begin(9600) enables serial communication at a speed of 9600 bits per second. This allows readings to be displayed in the Arduino Serial Monitor Simple, but easy to overlook..

The loop() Function

The loop() function runs repeatedly:

potentiometerValue = analogRead(potentiometerPin);

analogRead() measures the voltage at analog pin A0. Most standard Arduino boards convert this voltage into a number between 0 and 1023:

  • 0 represents approximately 0 volts
  • 1023 represents approximately the reference voltage
  • Values between these limits represent intermediate voltages

The next line converts the reading into the range required for PWM output:

ledBrightness = map(potentiometerValue, 0, 1023, 0, 255);

The map() function changes a value from one numerical range to another. In this case, it converts the analog input range of 0–10

The map() function takes the raw analog reading—still in the 0‑to‑1023 range—and scales it down to the 0‑to‑255 interval that analogWrite() expects. Practically speaking, in practice, a reading of 0 (0 V) becomes a brightness of 0 (LED off), while a reading of 1023 (≈ 5 V) becomes a brightness of 255 (LED at full intensity). Intermediate values produce proportional PWM duty cycles, giving a smooth, linear relationship between the potentiometer’s rotation and the LED’s perceived brightness Most people skip this — try not to..

ledBrightness = map(potentiometerValue, 0, 1023, 0, 255);

Applying PWM Output

analogWrite(ledPin, ledBrightness);

analogWrite() does not produce true analog voltage; instead, it toggles the pin at a high frequency, holding the signal high for a fraction of each cycle determined by ledBrightness. On most Arduino boards, the PWM frequency on pin 9 is about 490 Hz, which is fast enough that the human eye perceives a steady light level. The higher the duty cycle (i.e., the larger ledBrightness), the longer the LED stays on during each cycle, and the brighter it appears That's the part that actually makes a difference. Practical, not theoretical..

Real talk — this step gets skipped all the time Most people skip this — try not to..

Serial Monitoring for Debugging

The Serial statements let you watch the raw potentiometer value and the resulting brightness in real time:

Potentiometer: 512 | LED brightness: 128

Because the data is printed every 10 ms, you’ll see updates quickly enough to confirm that the mapping works as expected and to spot any noise or erratic behavior in the analog input Simple as that..

Fine‑Tuning the Response

A delay(10) gives the loop a modest pause, preventing the Arduino from being overwhelmed by constant I/O. If you notice jitter in the LED brightness, consider adding a simple software filter:

potentiometerValue = (potentiometerValue * 0.9) + (analogRead(potentiometerPin) * 0.1);

This exponential smoothing reduces rapid fluctuations without sacrificing responsiveness Small thing, real impact..

Practical Tips and Extensions

  • Current Limiting: Always keep a series resistor (typically 220 Ω–330 Ω) between the Arduino pin and the LED anode to protect both the LED and the microcontroller.
  • Potentiometer Type: A linear‑taper potentiometer provides a more intuitive, proportional control, while a logarithmic‑taper version can be useful for audio‑related brightness adjustments.
  • Multiple LEDs: By adding another analogWrite() call on a different PWM pin, you can fade multiple LEDs in tandem or create a “breathing” effect by ramping the brightness up and down.
  • Non‑volatile Settings: If you want the last brightness level to survive a power cycle, store the mapped value in EEPROM and read it back in setup().
  • External Drivers: For higher‑current LEDs or multiple LEDs, replace the base resistor with a MOSFET or a dedicated LED driver (e.g., TPIC6C595) to avoid overloading the Arduino pins.

Conclusion

This simple circuit demonstrates how an Arduino’s analog‑to‑digital converter, combined with PWM output, can turn a mechanical knob into a precise dimmer for an LED. In practice, by mapping the 10‑bit potentiometer reading to an 8‑bit brightness value and feeding that into analogWrite(), you achieve smooth, controllable illumination with minimal code. The built‑in serial monitor provides instant feedback, while optional smoothing and storage enhancements make the project reliable for real‑world applications. Experiment further—swap LEDs, add more controls, or integrate sensors—to expand the possibilities of analog interaction with your Arduino projects.

Fresh Out

Fresh from the Writer

Readers Went Here

If This Caught Your Eye

Thank you for reading about Control An Led With Potentiometer Aruino. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home