19. Seesaw Effect Using LEDs

After analyzing the task,
We need to connect five LEDs and a potentiometer to the microcontroller. The idea is to make their brightness change based on the potentiometer’s position so that it creates a seesaw effect.

How will the LED brightness adjust as per the potentiometer?

The potentiometer value (0%–100%) is mapped to PWM duty cycles of each LED so that each LED follows the required brightness pattern to create a seesaw effect:
LED brightness for the full range of potentiometer(0% → 100%):

  • LED0: 0% → 100%
  • LED1: 25% → 75%
  • LED2: fixed at 50%
  • LED3: 75% → 25%
  • LED4: 100% → 0%

We’ll use PWM to control each LED’s brightness, and the ADC value from the potentiometer will be mapped to the duty cycle for each LED.

For example,  consider a 10-bit PWM resolution (0–1023) and the potentiometer spanning the same range (0–1023):

  • LED1 is restricted between 25% and 75% duty cycle, i.e., 256 to 767 PWM counts.
  • As the potentiometer moves from 0 to 1023, LED1’s duty cycle only varies within 25% and 75% range, ensuring its brightness stays between 25% and 75%.

We have to interface a potentiometer and five LEDs with a microcontroller.

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Ω.

Five LEDs Interfacing

Connect each PWM GPIO pin to an anode of a separate LED, and the cathode of each LED to GND with a current-limiting resistor in series to protect LEDs and GPIO pins.

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 connections, 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!