STM32 Project Sharing: Design of IoT Monitoring Node for Urban Noise and Air Quality Based on STM32 Microcontroller

We do not engage in one-time transactions; we aim to be long-term partners in technical growth!

01

Physical Video Display

See the end of the article for data sharing

02

Project Overview

Title: Design of IoT Monitoring Node for Urban Noise and Air Quality Based on STM32 Microcontroller

Main Control: STM32F103C8T6

Display: OLED Display

Sensors:

Sound Sensor

PM2.5 Sensor

Carbon Dioxide Sensor

Air Quality Sensor

Bluetooth Module

Three Buttons

DC Power Supply

Functions:

1. The screen displays the current sound level, PM2.5 data, carbon dioxide sensor data, and air quality data in real-time.

2. Can connect to the microcontroller via Bluetooth to retrieve current data on a mobile phone.

3. Bluetooth can control the microcontroller.

4. Buttons can adjust thresholds, including maximum noise threshold, PM2.5 threshold, carbon dioxide threshold, and air quality threshold.

5. When data is outside the threshold, an audible and visual alarm is triggered.

STM32 Project Sharing: Design of IoT Monitoring Node for Urban Noise and Air Quality Based on STM32 Microcontroller

03

Schematic Design

STM32 Project Sharing: Design of IoT Monitoring Node for Urban Noise and Air Quality Based on STM32 Microcontroller

04

PCB Hardware Design

STM32 Project Sharing: Design of IoT Monitoring Node for Urban Noise and Air Quality Based on STM32 MicrocontrollerSTM32 Project Sharing: Design of IoT Monitoring Node for Urban Noise and Air Quality Based on STM32 Microcontroller

05

Program Design

#include "stm32f10x.h"                  // Device header
#include "delay.h"
#include "lcd.h"
#include "IOput.h"
#include "usart.h"
#include "adc.h"
extern u8 res;
void wifi() {
	if(res=='a')
	{
		OLED_Clear();
		res=0;
		set_flag=1;
	}
	else if(res=='b')
	{
		res=0;
		add_flag=1;
	}
	else if(res=='c')
	{
		res=0;
		dec_flag=1;
	}
}
float pm;                                // PM2.5 concentration
float AD_PM;                             // PM2.5 concentration obtained from AD conversion
void GetGP2Y(void)                       // Function to get PM2.5 concentration
{
	LED = 1;                             // Turn off LED
	delay_us(280);                       // Delay 280 microseconds
	AD_PM = Get_Adc_Average(6, 10) * 3.3 * 2/ 4095; // Get and calculate AD conversion value
	delay_us(40);                        // Delay 40 microseconds
	LED = 0;                             // Turn on LED
	delay_us(9680);                      // Delay 9680 microseconds
	pm = AD_PM*100/0.37;              // Convert voltage to PM2.5 concentration value
}
u8 gz,sw;
u8 show_flag,show1_flag,max_wd=100,dec_gz=30,dec_ts=60,dec_sd=40,count=0;
int main (void){
	delay_init();
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	OLED_Init();
	delay_ms(1);
	OLED_Clear();
	Adc_Init();
	output_init();
	input_init();
	Usart2_Init(9600);
	Usart1_Init(9600);
	delay_ms(50);
	while(1)
	{
		wifi();
		GetGP2Y();
		count++;
		sw=100-Get_Adc_Average(1,10)*100/4096;
		gz=Get_Adc_Average(0,10)*100/4096;
		key_scan(1,0,0);
		if((set_flag==1 && show_flag!=1))
		{
			OLED_Clear();
			show1_flag=0;
			set_flag=0;
			show_flag++;
			if(show_flag>=2)
			{
				show_flag=0;
			}
		}
		if(show_flag==0)
		{
			OLED_ShowCH(0,0,"Urban Environmental Monitoring System");
			OLED_ShowCH(0, 4, "PM2.5:");        // Display PM2.5
			OLED_ShowNum(48, 4, pm, 4, 16);
			OLED_ShowCH(88, 4, "ug/m3");         // Display unit
			OLED_ShowCH(0,2,"Quality:");
			OLED_ShowNum(40,2,gz,2,16);
			OLED_ShowCH(64,2,"Noise:");
			OLED_ShowNum(104,2,sw,2,16);
			OLED_ShowCH(0,6,"C02:");
			OLED_ShowNum(40,6,co2_ppm,4,16);
		}
		if(show_flag==1)
		{
			OLED_ShowCH(0,0,"Air Quality:");
			OLED_ShowCH(0,2,"Max Noise:");
			OLED_ShowCH(0,4,"PM2.5:");
			OLED_ShowCH(0,6,"CO2:");
			OLED_ShowNum(72,0,dec_gz,2,16);
			OLED_ShowNum(72,2,dec_ts,2,16);
			OLED_ShowNum(72,4,max_wd,3,16);
			OLED_ShowNum(72,6,dec_sd,3,16);
			if((set_flag==1 && show_flag==1))
			{
				set_flag=0;
				show1_flag++;
				if(show1_flag>=4)
				{
					show_flag=0;
					OLED_Clear();
				}
			}
			if(show1_flag==0)
			{
				OLED_ShowCH(112,0,"←");
				if(add_flag==1)
				{
					add_flag=0;
					dec_gz++;
				}
				if(dec_flag==1)
				{
					dec_flag=0;
					dec_gz--;
				}
				if(dec_gz>=100 || dec_gz<=0){dec_gz=0;}
			}
			if(show1_flag==1)
			{
				OLED_ShowCH(112,2,"←");
				if(add_flag==1)
				{
					add_flag=0;
					dec_ts++;
				}
				if(dec_flag==1)
				{
					dec_flag=0;
					dec_ts--;
				}
				if(dec_ts>=100 || dec_ts<=0){dec_ts=0;}
			}
			if(show1_flag==2)
			{
				OLED_ShowCH(112,4,"←");
				if(add_flag==1)
				{
					add_flag=0;
					max_wd++;
				}
				if(dec_flag==1)
				{
					dec_flag=0;
					max_wd--;
				}
				if(max_wd>=200 || max_wd<=0){max_wd=0;}
			}
			if(show1_flag==3)
			{
				OLED_ShowCH(112,6,"←");
				if(add_flag==1)
				{
					add_flag=0;
					dec_sd++;
				}
				if(dec_flag==1)
				{
					dec_flag=0;
					dec_sd--;
				}
				if(dec_sd>=200 || dec_sd<=35){dec_sd=35;}
			}
		}
		if(gz>=dec_gz || sw>=dec_ts || pm>=max_wd || co2_ppm>=dec_sd*10)
			BEEP=0;
		else
			BEEP=1;
		if(count>=50)
		{
			count=0;
			//	UsartPrintf(USART1,"Temperature:%d\r\n",temp);
			//	UsartPrintf(USART1,"Humidity:%d\r\n",humi);
			UsartPrintf(USART1,"Air Quality:%d\r\n",gz);
			UsartPrintf(USART1,"Noise:%d\r\n",sw);
			UsartPrintf(USART1,"CO2:%d\r\n",co2_ppm);
			UsartPrintf(USART1,"PM2.5:%f\r\n",pm);
			UsartPrintf(USART1,"\r\n\r\n");
		}
	}}

06

Data Sharing

Baidu Cloud Link:

https://pan.baidu.com/s/1AfQvrhOPOSRqZ78t1_4I7Q?pwd=82aq Extraction Code: 82aq

If the link is invalid, please click on the public account to contact us!

Leave a Comment