To Implement a Sequence Where Three LEDs Blink in Various Combinations

by qwes11_4522 in Circuits > Microcontrollers

25 Views, 0 Favorites, 0 Comments

To Implement a Sequence Where Three LEDs Blink in Various Combinations

Screenshot 2024-04-25 095441.png


With STM32 black pill and STM cube IDE to implement a sequence where three LEDs blink in various combinations

In this tutorial, we will delve into programming the STM32 "Black Pill" development board using STM32CubeIDE to create diverse LED blinking patterns. The Black Pill board employs the STM32F103C8T6 microcontroller, while STM32CubeIDE serves as a robust integrated development environment tailored for STM32 microcontrollers.


Supplies

  1. STM32 Blackpill
  2. 3Led's
  3. Breadboard
  4. Jumper Wire
  5. USB type C cable
  6. STM 32 Cube ide
  7. STM 32 Cube Programmer

Setting Up Stm Cube IDE

Screenshot 2024-04-25 132835.png
  1. Download and install STM32CubeIDE on your computer.
  2. Launch STM32CubeIDE and initiate a new project. a. Select "New STM32 Project" from the Quick Start menu. b. Choose your board or microcontroller (STM32F103C8) and proceed with the Next option. c. Configure project name and location, then click Finish.


Configuring the GIPO'S and LED

  1. In STM32CubeIDE, navigate to the "Pinout & Configuration" tab.
  2. Configure three GPIO pins for controlling LEDs (e.g., GPIOA Pin 0, Pin 1, Pin 2 for Red, Green, Blue LEDs).
  3. Set these pins as GPIO Output and enable GPIO clock.


Write the Led Blinking Code

  1. Navigate to the "Core" folder in the project explorer and open main.c.
  2. Include necessary libraries and header files.
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,0);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,0);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);

HAL_Delay(1000);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);

HAL_Delay(1000);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);

HAL_Delay(1000);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);

HAL_Delay(1000);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,1);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,0);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);

HAL_Delay(1000);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);

HAL_Delay(1000);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);

HAL_Delay(1000);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);

HAL_Delay(1000);



Building the Project

  • Connect your STM32 Black Pill board to your computer using a USB cable.
  • Build the project by clicking on the hammer icon in the toolbar.
  • Once the build is successful, click the play (debug) button to flash the code onto the board.


Testing the Led Blinking Pattern

  1. Navigate to the "Core" folder in the project explorer and open main.c.
  2. Include necessary libraries and header files.


Led Blinking Results

Downloads

Conclusion

The STM32 Black Pill board to control LEDs in different blinking patterns using STM32CubeIDE. we can do further by adding new patterns or modifying the existing code to create more complex LED sequences.