Brightness Control of LED By Using Potentiometer and ESP32

This article focuses on the implementation of a brightness control system for an LED using a potentiometer and the ESP32 microcontroller. Leveraging the ESP32’s analog-to-digital conversion capabilities, the potentiometer serves as a user-friendly interface for adjusting the LED’s brightness in real-time. The integration of Pulse Width Modulation (PWM) allows the digital control of analog signals, enabling smooth and dynamic brightness adjustments.

Components Used: 

  • ESP32 Microcontroller: The ESP32 is a versatile and powerful microcontroller that integrates Wi-Fi and Bluetooth capabilities. It’s well-suited for IoT projects and offers analog-to-digital conversion for reading signals like those from a potentiometer. 
  • Potentiometer: A potentiometer, or pot, serves as a variable resistor, allowing users to adjust the electrical resistance manually. In this project, we leverage a potentiometer to control the brightness of the LED. 
  • LED: Light Emitting Diodes (LEDs) are used for visual indication. By varying the voltage supplied to the LED, we can control its brightness. 

Hardware Setup: 

  • Connect the potentiometer to the ESP32: 
  • Connect one end of the potentiometer to 3.3V on the ESP32. 
  • Connect the other end of the potentiometer to GND on the ESP32. 
  • Connect the middle pin (wiper) of the potentiometer to an analog pin on the ESP32 (e.g., A6). 

 

  • Connect the LED to the ESP32: 
  • Connect the anode (longer lead) of the LED to the GPIO pins on the ESP32 (e.g., GPIO 5). 
  • Connect the cathode (shorter lead) of the LED to the GND on the ESP32. 

Software Code (Arduino IDE): 

const int potPin = A6;  // Potentiometer pin

  const int ledPin = 13;   // LED pin

  void setup() {

  pinMode(potPin, INPUT);

pinMode(ledPin, OUTPUT);

  }

 

void loop() {

  int potValue = analogRead(potPin); // Read potentiometer value (0-1023)

  int brightness = map(potValue, 0, 1023, 0, 255); // Map to LED brightness (0-255)

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

  delay(20); // Optional delay for smoother operation

  }

 

 

 

Leave a comment

Your email address will not be published. Required fields are marked *