基于STC89C52RC单片机的智能气象站

前述:
QQ:961209458
V X:F9986858

演示视频

基于51单片机的智能气象站

主要内容

本次设计了一款基于单片机温湿度 大气压强pm2.5检测装置,该设计可以直接通过dc5v直流直接进行供电,采用STM32单片机作为核心处理器,SHT20温湿度传感器实时检测当前环境的温度和湿度,PM2.5灰尘颗粒传感器实时检测空气中的PM2.5浓度,采用bmp180检测当前的大气压强,按键用于设置pm2.5浓度值上限,。当检测pm2.5超标,,单片机控制蜂鸣器进行报警,进单片机将采集到的的pm2.5值,温度和湿度值显示在LCD1602液晶屏上,实时展示数据的动态变化,通过温湿度的采集显示当前天气下雨的概率。

系统硬件结构设计

硬件包含温湿度传感器、LCD1602显示屏、STM32F103、空气质量传感器Pm2.5、大气压强BMP180传感器实现温度、湿度、大气压强、空气质量的采集等。
基于STC89C52RC单片机的智能气象站_第1张图片

系统软件结构设计

基于STC89C52RC单片机的智能气象站_第2张图片
基于STC89C52RC单片机的智能气象站_第3张图片
基于STC89C52RC单片机的智能气象站_第4张图片

实物照片

基于STC89C52RC单片机的智能气象站_第5张图片
基于STC89C52RC单片机的智能气象站_第6张图片
基于STC89C52RC单片机的智能气象站_第7张图片
基于STC89C52RC单片机的智能气象站_第8张图片

部分代码

int main(void)
{
     		
	u8 i;
	u8 keynum = 0;
	delay_init();	    	 //延时函数初始化	  
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
	delay_ms(500);
	LCD_Init();  //1602初始化
	KEY_Init(); //按键初始化
	I2C_Configuration();//IIC初始化
	SHT2X_Init();//sht20初始化
	bh1750_Init();
	delay_ms(1000);
	IIC_Init(); //IIC初始化
	uart_init(2400);      //使能串口1 
	
	LCD_Write_String(0,0,"Wait GSM Init...");
	LCD_Write_String(0,1,"                ");

		
		while(1)//等待GSM模块连接到基站
		{
     
			delay_ms(500);
			count123=0;
			for(i=0;i<39;i++)
			RX_Buffer[i]=0;
			sprintf((char*)buff,"AT+CPIN?\r\n");
			UART3_SendString(buff);
			delay_ms(1000);
			if(lianwang==1)
			{
     
				LCD_Write_String(0,0,"GSM Success...  ");
				LCD_Write_String(0,1,"                ");
				delay_ms(1000);delay_ms(1000);
				Send_Message();
				BEEP = 1;delay_ms(200);
				break;
			}
		}
	    if(mode == 0)
		{
     
			count = 90;
			LCD_Write_String(0,0,"Tmp:  C  Hum:  %");
			LCD_Write_String(0,1,"P:     Kpa G:  %");
		}
		else
		{
     
			LCD_Write_String(0,0,"PM2.5:    ug/m3 ");
			LCD_Write_String(0,1,"max_P:    ug/m3 ");
		}
		while(1)
		{
     
			  keyscan();//按键扫描
			  if(count++ >= 150)//延时大概150ms读取一次
				{
     
					count = 0;
					if(mode == 0)//温湿度气压下雨概率
					{
     
							 BEEP = 0;
							if(SHT2x_Calc_T())//读取温度值
							{
     
								temperature = (short)temperatureC;
							}
							if(SHT2x_Calc_RH())//读取湿度值
							{
     
								humidity = (short)humidityRH;
							}
							//显示温度
							LCD_Write_Char(4,0,temperature/10+'0');
							LCD_Write_Char(5,0,temperature%10+'0');
							//显示湿度
							LCD_Write_Char(13,0,humidity/10+'0');
							LCD_Write_Char(14,0,humidity%10+'0');
							//根据湿度计算下雨概率
							if(humidity < 60)
								pro = 10;
							else if(humidity >= 60 && humidity < 80)
								pro = 20;
							else if(humidity >= 80 && humidity < 95)
								pro = 50;
							else if(humidity >= 95)
								pro = 99;
							//显示概率
							LCD_Write_Char(13,1,pro/10+'0');
							LCD_Write_Char(14,1,pro%10+'0');
							
							True_Press = Convert_UncompensatedToTrue((long)BMP085_Get_UT(),(long)BMP_UP_Read());//读取气压值
							//显示气压
							LCD_Write_Char(2,1,True_Press/10000000+'0');
							LCD_Write_Char(3,1,True_Press%10000000/1000000+'0');
							LCD_Write_Char(4,1,True_Press%1000000/100000+'0');
							LCD_Write_Char(5,1,'.');
							LCD_Write_Char(6,1,True_Press%100000/10000+'0');
					}
					else if(mode == 1)//pm2.5
					{
     
						  if(cnt++ > 200)
							{
     
								  cnt = 0;
									Get_PM();//读取PM2.5值
									if(PM25_Value > 999)//超过999,显示 ‘-’
									{
     
										  LCD_Write_Char(7,0,'-');
											LCD_Write_Char(8,0,'-');
											LCD_Write_Char(9,0,'-');
									}
									else
									{
     
										  //显示PM2.5
											LCD_Write_Char(7,0,PM25_Value%1000/100+'0');
											LCD_Write_Char(8,0,PM25_Value%100/10+'0');
											LCD_Write_Char(9,0,PM25_Value%10+'0');
									}
									
									if(PM25_Value >= PM25_Value_max && flag == 0)//PM2.5超限,蜂鸣器报警
									{
     
										if(duanxin==1)
										duanxin=2;
										
										flag = 1;
										if(beep_count++ < 2)
										{
     
											BEEP = 1;
										}
										else
										{
     
											BEEP = 0;
											if(beep_count > 10)
											{
     
												beep_count = 0;
											}
										}
										flag = 0;
									}
									else
									{
     
										duanxin=1;
										BEEP = 0;
									}
									//duanxin状态为  1  2  3     
									//               2:报警发短信  3:发送完一次短信为3   1:PM2.2低于报警值置1
									//     采用三个状态时为了在报警的时候避免重复多次发送短信
									if(duanxin==2)//进入发短信标志
										 Send_Message();
							}
					}
					else if(mode==2)
					{
     
						Get_BH1750_Value();//获取光强
						guangqiang=lux*100;
						LCD_Write_Char(6,1,guangqiang/1000000+'0');
						LCD_Write_Char(7,1,guangqiang%1000000/100000+'0');
						LCD_Write_Char(8,1,guangqiang%100000/10000+'0');
						LCD_Write_Char(9,1,guangqiang%10000/1000+'0');
						LCD_Write_Char(10,1,guangqiang%1000/100+'0');
						LCD_Write_Char(11,1,'.');
						LCD_Write_Char(12,1,guangqiang%100/10+'0');
						LCD_Write_Char(13,1,guangqiang%10+'0');
						LCD_Write_Char(14,1,'l');
						LCD_Write_Char(15,1,'x');
					}
				}
		}
}

你可能感兴趣的:(单片机,STM32,单片机,传感器,物联网,人工智能,嵌入式)