11. LED Blinking Patterns

First, we need to connect four LEDs to the microcontroller. And we need a proper resistor for each LED to limit the current flowing through them to 10mA.

Calculating the Resistor Value

To ensure a 10 mA current through the LED, we need to select an appropriate resistor based on the supply voltage.

Case 1: 5V Supply

Register-calculation
  • 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 Ω.

Interfacing the push button switch

To change the LED blinking pattern, use a push-button switch. When connecting the switch, ensure it correctly provides GPIO levels (LOW and HIGH). For reliable detection of voltage levels, use either a pull-up or pull-down resistor configuration.

  • Case 1: 5V supply
Pullup-pulldown-configuration
  • Case 2: 3.3V supply: The approach is the same as above; simply use a 3.3V supply instead of 5V where applicable.

However, most microcontrollers’ GPIO pins include an internal pull-up resistor, which can be used for interfacing with the switch.

Therefore, it is recommended to enable the internal pull-up resistor in your microcontroller’s settings.

So, by selecting a proper resistor, LED, and push-button switch correctly, 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!