LED Brightness control with potentiometer

LED Brightness control with Potentiometer

Introduction

This project we are going to do LED Brightness control with potentiometer. A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your board, it is possible to measure the amount of resistance produced by a potentiometer (or pot for short) as an analog value. in this project we will explore how to control LED using a potentiometer (POT) and an Arduino board. this project is a great starting point for beginners who want to learn the basics of analog & digital output using Arduino.

Components Required

1Arduino board (e.g., Arduino Uno)
2LED(s) – as many as you like
3Potentiometer (also known as a variable resistor)
4Resistors – appropriate for your LED(s)
5Breadboard
6Jumper wires

Step 1: Setting up the Circuit

LED Brightness control with potentiometer
A circuit diagram illustrating an LED controlled by a potentiometer, enabling adjustable brightness levels for the LED’s illumination.

To get started, let’s set up the circuit. Connect the components as follows

1Connect the positive leg (longer leg) of the LED to a current-limiting resistor (e.g., 220-ohm resistor).
2Connect the other end of the resistor to a digital pin on the Arduino board (e.g., pin 9).
3Connect the negative leg (shorter leg) of the LED to the ground (GND) pin on the Arduino board.
4Connect the wiper (middle terminal) of the potentiometer to the analog input pin (e.g., A0) on the Arduino board.
5Connect one of the outer terminals of the potentiometer to the 5V pin on the Arduino board.
6Connect the other outer terminal of the potentiometer to the ground (GND) pin on the Arduino board.

Step 2: Writing the Arduino Code

Once the circuit is set up, we need to write the code to control the LEDs based on the potentiometer’s position. Follow these steps:

1·  Open the Arduino IDE (Integrated Development Environment) on your computer.
2·  Create a new sketch.
3·  Begin by defining the LED pin and potentiometer pin:
const int ledPin = 9;    // Digital pin connected to LED
const int potPin = A0;   // Analog pin connected to potentiometer
4In the setup() function, set the LED pin as an output:
void setup() {
  pinMode(ledPin, OUTPUT);
}
5In the loop() function, read the value from the potentiometer and map it to a range suitable for the LED brightness:
void loop() {
  int potValue = analogRead(potPin);   // Read potentiometer value
  int brightness = map(potValue, 0, 1023, 0, 255);   // Map potentiometer value to LED brightness range

  analogWrite(ledPin, brightness);   // Set LED brightness
}

Step 3: Uploading the Code and Testing

Now that the code is ready! upload it to your Arduino board:

1Connect your Arduino board to your computer using a USB cable.
2Select the appropriate board and port in the Arduino IDE.
3Click on the “Upload” button to compile and upload the code to the Arduino board.

Once the code is uploaded you should see the LED brightness change according to the potentiometer position. turning the potentiometer(POT) clockwise direction will increase the LED brightness and turning counterclockwise will decrease the brightness.

Conclusion

Controlling LEDs with a potentiometer using Arduino is a fun and straightforward project that introduces you to analog input and digital output. by varying the potentiometer position you can adjust the LED brightness in real-time.

Download Arduino driver