A dimmer is just another type of potentiometer. We’ve already explored how to use one to control a servo, but this guide will show how to use it to control an LED. Since LEDs (like most lights) burn out if too much power is pushed through them, this will help you understand how to calibrate potentiometers to limit the voltage output by your Arduino.
For most projects, an LED is used either to test a circuit or indicate that something is working. However, for this project, we want to control the brightness of the LED directly. We’ll do this in two ways to show how potentiometers can be used to directly control the voltage passing through an LED, as well as indirectly using programming from an Arduino.
First, it’s important to understand how LEDs work. As a current passes through the LED, it emits light. The amount of current that passes through it will determine how bright it is, but too much and the LED will burn out. This is why most projects that use an LED require a 220-ohm resistor to impede the current flowing through.
A potentiometer is also a type of resistor with variable resistance. The further the dial turns, the more resistance it adds to the circuit. In the first part of the wiring section, we’ll show how this can directly turn down the brightness of the LED, without using an Arduino at all. Then, we’ll add the dimmer to a circuit to gain more control over the brightness within our sketch.
Both versions of the project we’ll be doing here are fairly simple, so you might have most of the parts you need, especially if you’ve ever bought a basic electronics kit. Either way though, you’ll need the following components, as well as a power source:
Arduino Uno | ![]() |
![]() |
|
![]() |
|
One 220 ohm resistor |
![]() |
Any potentiometer will work, but if you have a slider version, it might feel more natural for dimming a light than the dial style.
|
![]() |
The Arduino and IDE are only required for the second version of this circuit; however we’ll use it to supply power to the breadboard for the first version. You can also use a power module like this one to add power that will match what you’d get with an Arduino to a breadboard directly. Keep in mind if you use another power supply (such as a 9V battery), the first circuit may not work and could burn out your LED.
The first wiring model we’ll use doesn’t require the Arduino at all, so we’ll start with that. With this circuit, you’ll be able to see how a potentiometer directly affects its resistance. To get started, use a breadboard to connect the following wires:
● First, connect a power and ground wire to the rails on the side of the breadboard and to the 5V and GND pins on your Arduino, respectively.
● Connect the power rail to one side pin of the potentiometer.
● Connect the center pin on the potentiometer to the long pin of the LED.
● Connect the short pin of the LED to the 220-ohm resistor.
● Connect the other end of the resistor to the ground rail.
Supply power to your Arduino or power module and the LED will turn on. Now, you can slide the potentiometer and the resistance of the circuit will change, adjusting the current running through the LED and thus making the light brighter or darker.
This demonstrates, in a small-scale way, how most dimming circuits work. The 220-ohm resistor is added to the circuit to prevent the current from overloading and burning out the light. With the resistor in place, the potentiometer further limits the current on an adjustable basis.
However, directly modifying the current in the circuit isn’t the only way to adjust a light’s brightness. To demonstrate this, we’ll expand the circuit to read the potentiometer’s resistance and assign a value to the LED using a sketch (which we’ll explain in the next section).
Once you’re done with this first version of the circuit, make the following changes:
● Plug the long end of the LED into pin 6 on your Arduino (instead of the center pin on the potentiometer as it was before)
● Connect the center pin of the potentiometer to pin A0 on the Arduino.
● Connect the third pin on the potentiometer to the ground rail (the first pin should still be connected to the power rail).
In this circuit, the resistance of the potentiometer doesn’t directly affect the brightness of the LED, but instead is read as an analog value by the Arduino. Then, that value can be scaled and adjusted in the sketch, which we’ll look at below.
First, here’s the full code you can upload to your Arduino. It should behave almost identically to the original circuit, but with a lot more control in the software.
int blueLED = 6;
int dimmerPIN = A0;
int dimmerValue = 0;
int ledValue = 0;
void setup() {
pinMode(dimmerPIN, INPUT);
pinMode(blueLED,OUTPUT);
Serial.begin(9600);
}
void loop(){
dimmerValue = analogRead(dimmerPIN);
ledValue = map(dimmerValue, 0, 1023, 0, 255);
analogWrite(blueLED, ledValue);
}
Most of this code is fairly basic – declaring variables, assigning pins, and so on – but there are three lines in the loop() section we want to call attention to;
dimmerValue = analogRead(dimmerPIN);
ledValue = map(dimmerValue, 0, 1023, 0, 255);
analogWrite(blueLED, ledValue);
The first line here reads the value of the potentiometer from pin A0, which will be measured on a scale of 0 to 1023. From there, we can convert this value to an output for pin 6, which controls the LED. The second line of this code will remap the value from the potentiometer to a new value between 0 and 255 (the full range of outputs for the PWM pin). Finally, the last line will write that value to pin 6.
However, we can modify the second line to set a minimum or maximum brightness by adjusting the final two numbers. The second 0 sets the minimum brightness level (which in this case would be entirely off). Raising this level will ensure that, no matter how far down you turn the dimmer, the light will stay on at whatever level you set. Likewise, the 255 in this line sets the maximum level. If you want to reduce the maximum brightness level – an LED can get quite bright after all – lowering this number will ensure the light never gets too bright, even when the dimmer is turned all the way up.
In this particular example, writing the value to the LED pin outputs somewhere between 0V and 5V (depending on what limits you set), and the 220-ohm resistor further limits the current running through a light. This concept is important to keep in mind when you deal with larger and more complex lights like LED strips, lamp bulbs, or anything with a higher voltage than the 5V the Arduino can put out.