0343基于STM32单片机的茶园大棚环境土壤湿度光强WiFi监测系统proteus仿真原理图PCB
生活随笔
收集整理的這篇文章主要介紹了
0343基于STM32单片机的茶园大棚环境土壤湿度光强WiFi监测系统proteus仿真原理图PCB
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
功能介紹:
0.本系統(tǒng)采用STM32F103RCT6作為單片機
1.采用的LCD1602液晶實時顯示當前光強土壤濕度等參數(shù)信息
2.當土壤濕度超過設定的閾值,蜂鳴器報警,同時控制水泵工作狀態(tài)
3.按鍵可更改環(huán)境參數(shù)的閾值
4.通過WiFi模塊可以和手機端進行數(shù)據(jù)通信
5.溫度傳感器和光強傳感器均采用高精度數(shù)字類傳感器
原理圖:
PCB:
主程序:
#define __MIAN_C #include "main.h" #include "stm32f10x.h" #include "stm32f10x_gpio.h" #include "bsp_gpio.h" #include "bsp_clkconfig.h" #include "bsp_delay.h" #include "bsp_lcd1602.h" #include "bsp_key.h" #include "bsp_GeneralTim.h" #include "bsp_adc.h" #include "bsp_18b20.h" #include "bsp_bh1750.h" #include "bsp_usart.h"// 局部變量,用于保存轉(zhuǎn)換計算后的電壓值 CreatByte Flag; enum _MODE_DF_ dispMode;char dis[16]; char dis1[16]; u32 humidity = 0; volatile uint16_t hmMin= 25; volatile uint16_t hmMax= 35; uint16_t tempBuf = 0; volatile uint16_t tempMin = 25; volatile uint16_t tempMax = 40; float f_temp = 0; int lightBuf; float f_light; volatile uint16_t lightMin = 30; volatile uint16_t lightMax = 1000; u8 volatile setIndex = 0;int main(void) {// 使用HSI,SYSCLK = 4M * RCC_PLLMul_x, x:[2,3,...16],最高是64MHHSI_SetSysClock(RCC_PLLMul_2); //使用內(nèi)部8MHz晶振,并設置PLL輸出為8MHz// 端口初始化GPIO_Config();GENERAL_TIM_Init();USART_Config();DelayMs(1000);printf("AT+CIPMUX=1\r\n"); //打開多連接DelayMs(1000);printf("AT+CIPSERVER=1,8080\r\n"); //建立服務 端口號為8080DelayMs(1000);Key_GPIO_Config();DelayMs(200);DS18B20_GPIO_Init();BH1750_GPIO_Init();Init_BH1750();LCD_GPIO_Init();LCD_Init();LCD_Clear();DelayMs(200);ADCx_Init();while (1){if (refreshFlag == 1){refreshFlag = 0;RefreshData();if (humidity <= hmMax && humidity >= hmMin\&& f_temp <= tempMax && f_temp >= tempMin \&& f_light <= lightMax && f_light >= lightMin) //在范圍內(nèi){BUZZER_OFF;}else{BUZZER_ON;}if (humidity < hmMin) //土壤濕度低時,開啟水泵{RELAY_ON;}else{RELAY_OFF;}if (dispMode == NORMAL){DispNormal();}}if (sendFlag == 1){sendFlag = 0;TIM_ITConfig(GENERAL_TIM2, TIM_IT_Update, DISABLE);SendData();TIM_ITConfig(GENERAL_TIM2, TIM_IT_Update, ENABLE);}KeyProcess();} }void RefreshData(void) {u8 i;for (i = 0; i < 20; i++){humidity = humidity + ADC_ConvertedValue[i];}humidity = humidity / 20; //取20次平均humidity = 100 - humidity * 100 / 4096; //讀取土壤濕度信息DS18B20_GetTemp(&tempBuf); //采集溫度f_temp = tempBuf * 0.0625; //溫度轉(zhuǎn)換Single_Write_BH1750(0x01); // power onSingle_Write_BH1750(0x10); // H- resolution modeMultiple_Read_BH1750(); //連續(xù)讀出數(shù)據(jù),存儲在BUF中lightBuf=BUF[0];lightBuf=(lightBuf<<8)+BUF[1];//合成數(shù)據(jù),即光照數(shù)據(jù)f_light=(float)lightBuf/1.2; //計算光照數(shù)據(jù) }void SendData(void) {printf("AT+CIPSEND=0,34\r\n"); //發(fā)送32位數(shù)據(jù)DelayMs(100);printf("Hm:%2d%% T:%5.1f'C\r\nLight:%8.1flx\r\n", humidity, f_temp, f_light); //串口發(fā)送DelayMs(100); }void DispNormal(void) {sprintf(dis, "Hm:%2d%% T:%5.1f", humidity, f_temp);LCD_DispStr(0, 0, dis);LCD_DispOneChar(14, 0, 0xdf);LCD_DispOneChar(15, 0, 'C');sprintf(dis, "Light:%8.1flx", f_light);LCD_DispStr(0, 1, dis); }void DispSetHm(u8 setIndex) {LCD_DispStr(0, 0, " Set Humidity ");sprintf(dis, " H:%2d%% L:%2d%% ", hmMax, hmMin);LCD_DispStr(0, 1, dis);switch (setIndex){case 1: LCD_SetCursor(6, 1, 1); break;case 2: LCD_SetCursor(12, 1, 1); break;default:;} }void DispSetTemp(u8 setIndex) {LCD_DispStr(0, 0, "Set Temperature ");sprintf(dis, " H:%3d L:%3d ", tempMax, tempMin);LCD_DispStr(0, 1, dis);switch (setIndex){case 1: LCD_SetCursor(7, 1, 1); break;case 2: LCD_SetCursor(13, 1, 1); break;default:;} }void DispSetLight(u8 setIndex) {LCD_DispStr(0, 0, " Set LightLimit ");sprintf(dis, "H:%5d L:%5d", lightMax, lightMin);LCD_DispStr(0, 1, dis);switch (setIndex){case 1: LCD_SetCursor(6, 1, 1); break;case 2: LCD_SetCursor(15, 1, 1); break;default:;} } /*********************************************END OF FILE**********************/實物演示視頻:
https://www.bilibili.com/video/BV1ou411r75L/
總結(jié)
以上是生活随笔為你收集整理的0343基于STM32单片机的茶园大棚环境土壤湿度光强WiFi监测系统proteus仿真原理图PCB的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为od机考题目-幼儿园找出同班的小朋友
- 下一篇: ESP32学习11:PWM