Formaldehyde concentration detection alarm simulation design based on STM32 (simulation + program + explanation)

Simulation diagram proteus 8.9

Program compiler: keil 5

Programming language: C language

Design number: C0083

Formaldehyde concentration detection alarm simulation

1. Main functions

Function Description:

1. Design formaldehyde concentration detection and alarm design using STM32 microcontroller and control core;

2. Display the formaldehyde concentration through the LCD screen LCD1602 and the serial port host computer, MV represents the detection value, and ALM represents the alarm value;

3. The formaldehyde concentration ALM alarm value can be set by pressing the button.

4. When the formaldehyde concentration is monitored to be 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 formaldehyde concentration is detected to be higher than 0.100mg/m3.

Main hardware equipment: STM32F103 microcontroller

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 input AD value of the simulated formaldehyde 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 formaldehyde concentration sensors such as MQ-3. This design uses a sliding rheostat to simulate changes in formaldehyde concentration and cannot be directly used in physical design. If necessary, it must be debugged according to the physical object.

This test looks like this:

Simulation running status:

After starting the simulation, LCD1602 displays the detected formaldehyde 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 formaldehyde concentration is higher than the alarm value, and there is a beeping alarm sound, and it does not start when the concentration is lower than the alarm value.

This design uses an electromagnetic buzzer. The electromagnetic buzzer consists of an oscillator, electromagnetic coil, magnet, vibrating diaphragm and shell. After the power is turned on, the audio signal current generated by the oscillator passes through the electromagnetic coil, causing the electromagnetic coil to generate a magnetic field. The vibrating diaphragm periodically vibrates and produces sound under the interaction of the electromagnetic coil and the magnet. Therefore, a certain current is required to drive it. The current output by the I/O pin of the microcontroller is small. The TTL level output by the microcontroller basically cannot drive the buzzer, so a current amplification circuit needs to be added. The positive electrode of the buzzer is connected to the VCC (+5V) power supply, the negative electrode of the buzzer is connected to the collector C of the triode, and the base B of the triode is controlled by the BEEP pin of the microcontroller after passing through the current limiting resistor. When the BEEP output is low When BEEP outputs a high level, the triode QS is turned off, no current flows through the coil, and the buzzer does not sound; when BEEP outputs a high level, the triode is turned on, so that the current of the buzzer forms a loop and makes a sound.

The gas concentration detected in the picture below is 0.090mg/m3, which is lower than the alarm value of 0.100mg/m3, and the buzzer circuit does not work.

img

In the picture below, the formaldehyde concentration detected is 0.110 mg/m3, which is greater than or equal to the alarm value. The transistor is turned on and the buzzer alarms.

img

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.

 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*(1.0/4095);		
	
		sprintf(str,"%4.3fmg/m3",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, 10, 10);		 //串口1发送字符串,数组长度为5,超时10ms
		HAL_UART_Transmit(&huart1, (uint8_t *)&"\n\r", 2, 10); //串口1发送字符串,数组长度为2,超时10ms	
		
		if(set_flag){
    
    //设置模式
			sprintf(str,"%4.3fmg/m3^ ",warming_val);
			LCD_ShowString(1,0,"ALM:");	
			LCD_ShowString(1,4,str);
		}else{
    
    
			sprintf(str,"%4.3fmg/m3  ",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, 10, 10);								//串口1发送字符串,数组长度为5,超时10ms
		HAL_UART_Transmit(&huart1, (uint8_t *)&"\n\r", 2, 10);						//串口1发送字符串,数组长度为2,超时10ms	
		
		if(temp>warming_val&&!set_flag){
    
    //如果超过报警值
			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

Altium Designer Software Information

KEIL software information

MS1100 sensor module manual.doc

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 (clickable):

Guess you like

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