Alcohol concentration detection alarm and anti-drunk driving simulation design based on STM32 (simulation + program + explanation video)

Alcohol concentration detection alarm and anti-drunk driving simulation design based on STM32

Alcohol concentration detection alarm and anti-drunk driving simulation design based on STM32 (simulation + program + explanation)

Simulation diagram proteus 8.9

Program compiler: keil 5

Programming language: C language

Design number: C0082

Explainer video

Alcohol concentration detection alarm and anti-drunk driving proteus simulation design based on STM32 (simulation + program + explanation)

1. Main functions

Function Description:

1. Design an alcohol concentration detection and alarm design using STM32 microcontroller and MQ-3 as the control core;

2. Display the alcohol concentration through the LCD screen LCD1602 and the serial port host computer;

3. The alcohol concentration alarm value can be set by pressing the buttons.

4. When the monitored alcohol concentration is greater than the alarm value, the buzzer alarm circuit is turned on and the buzzer alarms.

5. By default, the buzzer alarm will sound when the alcohol concentration is higher than 20mg/100ml.

Main hardware equipment: STM32F103 microcontroller

The following is a display of this design information:

2. Simulation

Overall design plan

This experiment uses the ADC, GPIO, timer and other resources of the STM32 microcontroller to organically combine the software and hardware, so that the system can correctly identify the AD value input to the simulated alcohol sensor, the LCD1602 can display it correctly, and the buzzer can be displayed according to the gas Concentration alarm value works. It should be noted that proteus does not have alcohol concentration sensors such as MQ-3. This design uses a sliding rheostat to simulate changes in alcohol concentration and cannot be directly used in physical design. If necessary, it must be debugged according to the physical object.

This experiment aims to use the analog-to-digital converter (ADC), general-purpose input/output (GPIO) and timer resources of the STM32 microcontroller to organically combine software and hardware to realize the AD value input to the analog alcohol sensor. Correctly identified and displayed through the LCD1602 display. In addition, the system is also equipped with a buzzer that can work according to the preset gas concentration alarm value.

In this experiment, it should be noted that the Proteus simulation software does not include common alcohol concentration sensors such as MQ-3. Therefore, to simulate changes in alcohol concentration, we used a sliding rheostat instead. This does not mean that this design can be directly applied to actual hardware. If physical design is required, it needs to be debugged and modified according to the actual situation.

During the entire experiment, we not only made in-depth use and debugging of various resources of the STM32 microcontroller, but also comprehensively understood and practiced software programming and hardware circuit design. Through this experiment, we further understood the important position of STM32 microcontroller in IoT applications, and how to effectively combine software and hardware to achieve system intelligence and automation.

This test looks like this:

Simulation running status:

After starting the simulation, LCD1602 displays the detected alcohol concentration in real time, and the measured value can be changed through the sliding rheostat. The alarm value concentration can be set by pressing the button, press the setting button to enter the setting mode, increase the alarm value through setting +, and decrease the alarm value through setting -. The buzzer alarm circuit starts when the alcohol concentration is higher than the alarm value, and there is a beeping alarm sound, and it does not start when the alcohol concentration is lower than the alarm value.

In the picture below, the detected gas concentration is 3mg/100mL, which is lower than the alarm value of 20mg/100mL, and the buzzer circuit does not work.

img

The following picture detects that the alcohol concentration is 23mg/100mL, which is greater than or equal to the alarm value. The transistor is turned on and the buzzer alarms.img

During the simulation process, the alcohol concentration alarm value can be set through buttons.

3. Procedure

The program is opened with the keil5 mdk version. If there are problems opening it, check the keil version. The program is written in the HAL library version, and there are comments that can be understood in conjunction with the explanation video.

main function

int main(void)
{
    
    
  /* USER CODE BEGIN 1 */
	ADC_ChannelConfTypeDef sConfig = {
    
    0};  //建立sConfig结构体
	char str[20];  //字符串的存放数组
	uint32_t adcv; //存放ADC转换结果
	float temp;
	set_flag = 0;


  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */
	sConfig.Rank = ADC_REGULAR_RANK_1;
	sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;   //采样周期为1.5个周期
  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_USART1_UART_Init();
  MX_TIM3_Init();
  /* USER CODE BEGIN 2 */
	LCD_Init();  //初始化LCD1602
	HAL_TIM_Base_Start_IT(&htim3);//开启定时器3
//	LCD_ShowString(0,0,dis_str);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    
    
		sConfig.Channel = ADC_CHANNEL_1;   //选择通道1
		HAL_ADC_ConfigChannel(&hadc1, &sConfig);  //选择ADC1的通道道1
		HAL_ADC_Start(&hadc1);										//启动ADC1
		HAL_ADC_PollForConversion(&hadc1, 10);		//等待ADC1转换结束,超时设定为10ms
		adcv = HAL_ADC_GetValue(&hadc1);					//读取ADC1的转换结果
		
		
		temp=(float)adcv*(3.3/4095)*100;		
	
		sprintf(str,"%4.0fmg/100ml",temp);
		LCD_ShowString(0,0,"MV:");	
		LCD_ShowString(0,4,str);	
	  HAL_UART_Transmit(&huart1, (uint8_t *)&"MV=", 3, 10);  //串口1发送字符串,数组长度为12,超时10ms
		HAL_UART_Transmit(&huart1, (uint8_t *)str, 12, 10);		 //串口1发送字符串,数组长度为5,超时10ms
		HAL_UART_Transmit(&huart1, (uint8_t *)&"\n\r", 2, 10); //串口1发送字符串,数组长度为2,超时10ms	
		
		if(set_flag){
    
    //设置模式
			sprintf(str,"^%3.0fmg/100ml",warming_val);
			LCD_ShowString(1,0,"ALM:");	
			LCD_ShowString(1,4,str);
		}else{
    
    
			sprintf(str,"%4.0fmg/100ml",warming_val);
			LCD_ShowString(1,0,"ALM:");	
			LCD_ShowString(1,4,str);			
		}
		
	  HAL_UART_Transmit(&huart1, (uint8_t *)&"ALM=", 4, 10);  //串口1发送字符串,数组长度为12,超时10ms
		HAL_UART_Transmit(&huart1, (uint8_t *)str, 12, 12);								//串口1发送字符串,数组长度为5,超时10ms
		HAL_UART_Transmit(&huart1, (uint8_t *)&"\n\r", 2, 10);						//串口1发送字符串,数组长度为2,超时10ms	
		
		if(temp>warming_val){
    
    //如果超过报警值
			HAL_GPIO_WritePin(GPIOA,BEEP_Pin, GPIO_PIN_RESET);//BEEP引脚拉低
		}else{
    
    
			HAL_GPIO_WritePin(GPIOA,BEEP_Pin, GPIO_PIN_SET);
		}

		HAL_ADC_Stop(&hadc1);											//停止ADC1
		HAL_Delay(300);
    /* USER CODE END WHILE */

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

img

4. Information list & download link

0. Common usage problems and solutions – a must-read! ! ! !

1. Program code

2. Proteus simulation

3. Functional requirements

4. Explanation video

5. MQ-3 sensor description

Altium Designer Software Information

KEIL software information

Proteus software information

Microcontroller learning materials

Defense skills

Common descriptions for design reports

Double-click the mouse to open and find more 51 STM32 Microcontroller Course Graduation Project.url

img

Data download link

Guess you like

Origin blog.csdn.net/weixin_52733843/article/details/132550823