Potentiometer LED Dimmer with Arduino

This tutorial will guide you through using a potentiometer to control the brightness of an LED using an Arduino. This project introduces the concept of analog input and PWM (Pulse Width Modulation) output.

Materials Needed

  • Arduino board (e.g., Arduino Uno)
  • LED
  • 220-ohm resistor
  • Breadboard
  • Potentiometer (10k ohm recommended)
  • Jumper wires
  • USB cable
required materials

Circuit Setup

schematic potentiometer
Circuit layout
  1. Insert the potentiometer into the breadboard. The three terminals of the potentiometer will be connected as follows:
    • The left pin to 5V on the Arduino
    • The middle pin to analog input A0 on the Arduino
    • The right pin to GND on the Arduino
  2. Insert the LED into the breadboard. The longer leg (anode) is the positive terminal, and the shorter leg (cathode) is the negative terminal.
  3. Connect a 220-ohm resistor to the cathode leg of the LED and then to the ground (GND) pin on the Arduino.
  4. Connect the anode leg of the LED to digital pin 9 on the Arduino.

Writing the Code

  • Open the Arduino IDE on your computer.
  • Create a new sketch and paste the following code:
int potPin = A0; // Potentiometer connected to A0
int ledPin = 9; // LED connected to pin 9
int potValue = 0; // Variable to store potentiometer value

void setup() {
    pinMode(ledPin, OUTPUT); // Set pin 13 as an output
}
void loop() {
    potValue = analogRead(potPin); // Read potentiometer value
    int brightness = map(potValue, 0, 1023, 0, 255); // Map value to 0-255 range
    analogWrite(ledPin, brightness); // Adjust LED brightness
}
  • Click the “Verify” button to check for errors.
  • Connect the Arduino to your computer using the USB cable.
  • Click the “Upload” button to send the code to the Arduino.

You have successfully built a potentiometer-controlled LED dimmer using Arduino. This project demonstrates how to read analog input and control output intensity using PWM, an essential concept for many electronics applications!