Docs

Micro-controllers, wireless transmission and database

Head

Sound Sensor with Blue Pill using STM32CubeIDE

Prerequisites

This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic blink sketch with blue-pill using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=kXg467nVd_A

Wiring Diagram

Diagram

Image1

Image2

STM32CubeIDE Settings

Set PA1 to GPIO_Output

Set PB9 to GPIO_Input

Additional code on top of STM32CubeIDE generated code

/* USER CODE BEGIN PV */
int val = 0;
int toggle = 0;
/* USER CODE END PV */

  /* USER CODE BEGIN WHILE */
  while (1)
  {
    val = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9);
    if(val == 1 && toggle == 0)
    {
      HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);
      HAL_Delay(1000);
    }
    toggle = val;
    HAL_Delay(100);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */