Arduino Circuits

LED Brightness with a Potentiometer

Convert the analog value read from a potentiometer into a PWM output to adjust LED brightness.

November 22, 20264 min read
LED Brightness with a Potentiometer — Arduino circuit built on a breadboard, showing components and connections
LED Brightness with a Potentiometer circuit breadboard layout, components and jumper connections.

Interactive circuit guide

Run the simulation, follow the build steps one by one and try it in our real app.

Real screenshot of our circuit simulator Stopped
Open in our app →

Step-by-step build

What is it for?

In this project, the ends of a 10-kilohm potentiometer are connected to the board's 5-volt rail and to ground, and the middle leg goes to an analog input pin. As the potentiometer is turned, the voltage at the middle leg varies between 0 and 5 volts and the board converts this voltage into a numeric value. The software maps the analog reading to a PWM (pulse-width modulation) output. PWM adjusts the average voltage by switching the output pin on and off very rapidly; our eyes perceive this fast change as a difference in brightness. The LED is still driven through a 220-ohm series resistor. This circuit teaches the conversion between analog reading and digital output and the idea of adjustable control.

Parts list

The following components are used to build this project:

  • Arduino Uno — Reads the analog value and generates a PWM output.
  • 10kΩ Potentiometer — Acts as a voltage divider to produce an adjustable voltage.
  • 220Ω Resistor — Limits the current through the LED.
  • Red LED — The output element whose brightness is adjusted.
  • Ground — Common reference for the divider and the LED.

Step-by-step build

  1. Place the control board and put the potentiometer on the upper row.The potentiometer has three legs: two ends and one middle leg.
  2. Connect one end of the potentiometer to the 5-volt rail and the other end to ground.This creates a constant 5 volts across the two ends.
  3. Connect the middle leg to the board's analog input pin.As you turn it, the value read at this pin changes.
  4. Connect a 220-ohm resistor and the LED in series from the PWM output pin to ground.The LED anode goes to the resistor, the cathode to ground.
  5. Connect the board's GND pin to the common ground rail.The power source and signals need the same reference.
  6. Upload the code and turn the potentiometer to watch the brightness change.At the lowest value the LED goes out; at the highest it is brightest.

How it works

The potentiometer divides the 5 volts across its ends according to the position of the middle leg. The middle leg produces an analog voltage that continuously varies between 0 and 5 volts, and the board's analog converter translates this voltage into a numeric range. The software maps this number to the duty cycle of a PWM output. Since the PWM signal is a square wave switching at a fixed frequency, the longer the on-time, the more average current flows through the LED and the brighter it appears. Because the human eye cannot distinguish this rapid flicker, brightness appears to change smoothly. The 220-ohm resistor keeps the LED current in a safe range even at the brightest setting.

The potentiometer is on the upper row; one end goes to the power rail, the other to the ground rail, and the middle leg to the analog input pin. The LED and the 220-ohm resistor are on the right side, on the PWM output line. All cathodes and the lower end of the potentiometer meet at common ground.

What you will learn

  • Relates analog input reading to PWM output generation.
  • Explains the use of a potentiometer as a voltage divider.
  • Understands the role of pulse-width modulation in brightness control.
  • Interprets the conversion between analog and digital signals.

Tips

  • If the middle leg is left floating, the reading does not change; check the wires.
  • If the LED flickers, try increasing the PWM frequency.
  • Increasing LED brightness without a resistor can damage the component.

Try it yourself

  • Turn the potentiometer fully left and fully right and compare the LED brightness.
  • Observe the relationship between the analog reading and the PWM duty cycle.
  • Change the resistor value and interpret the current limit at the brightest setting.

Getting the parts

Frequently asked questions

What does this circuit do?

Convert the analog value read from a potentiometer into a PWM output to adjust LED brightness.

How does the circuit work?

The potentiometer divides the 5 volts across its ends according to the position of the middle leg. The middle leg produces an analog voltage that continuously varies between 0 and 5 volts, and the board's analog converter translates this voltage into a numeric range. The software maps this number to the duty cycle of a PWM output. Since the PWM signal is a square wave switching at a fixed frequency, the longer the on-time, the more average current flows through the LED and the brighter it appears. Because the human eye cannot distinguish this rapid flicker, brightness appears to change smoothly. The 220-ohm resistor keeps the LED current in a safe range even at the brightest setting.

What is the expected result?

As the potentiometer is turned, the LED gradually dims and brightens again.

You may also like

Try the circuit in the simulator

Open the diagram in your browser, inspect the connections and follow the steps.