17. LED Brightness Control Using Potentiometer

Analyzing the task above, we need to vary the LED's brightness as the potentiometer rotates

To control LED brightness, both the potentiometer and the LED must be properly interfaced with the microcontroller. Here’s how this is typically done:

Potentiometer & LED Interfacing

Potentiometer Interfacing

potentiometer-pinout
  • Connection: Connect the potentiometer terminals 1 and 3 to VCC and GND or vice versa. Terminal 2 (wiper) to the MCU ADC pin.

Note: We can use any of the potentiometers with values between 1kΩ and 10kΩ.

LED Interfacing

  • Connection:
    • Connect the microcontroller’s PWM-capable GPIO pin to the LED anode, the cathode to one end of a current-limiting resistor, and the other end of the resistor to GND.
  • Function:
    • The microcontroller reads the potentiometer’s ADC value, maps it to a PWM duty cycle, and adjusts the LED brightness smoothly as the knob is turned.

Calculating the current-limited Resistor Value

Case 1: 5V Supply

  • LED forward voltage (Vf) = 1.8V (from datasheet)
  • Voltage across resistor (VR) = Supply voltage – Vf = 5V – 1.8V = 3.2V
  • Resistor value (R) = VR / I = 3.2V / 10 mA = 320 Ω

Standard resistor values near 320 Ω: 330 Ω or 300 Ω (whichever is available).

Similarly, Case 2: 3.3V Supply

  • Voltage across resistor (VR) = 3.3V – 1.8V = 1.5V
  • Resistor value (R) = 1.5V / 10 mA = 150 Ω

Standard resistor value: 150 Ω.

So, by selecting a proper resistor, LED, and potentiometer, we can implement the task.

Below are the solutions to the given task using different microcontrollers

  1. STM32
  2. ESP32
  3. Arduino UNO

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!