項目成品圖片:
01
—
項目簡介
1.功能詳解
功能如下:
檢測功能:監(jiān)測環(huán)境溫濕度、煙霧濃度、一氧化碳、空氣質(zhì)量、光照強度、大氣壓強
顯示功能:將檢測到的數(shù)據(jù)顯示在OLED上
控制功能:系統(tǒng)可以控制LED燈、步進電機(窗戶)
手動模式:機智云APP遠程控制LED燈和步進電機。
自動模式:系統(tǒng)檢測到煙霧濃度/一氧化碳/空氣質(zhì)量超出閾值時、蜂鳴報警并開窗通風;光線低于閾值時,自動開啟LED燈
閾值調(diào)節(jié):按鍵調(diào)節(jié)系統(tǒng)閾值
手機APP:通過ESP8266 WIFI模塊連接網(wǎng)絡(luò),接入機智云服務(wù)器,實現(xiàn)數(shù)據(jù)上報和控制下發(fā)
2.材料清單
STM32F103C8T6單片機
OLED 屏幕
DHT11溫濕度傳感器
MQ-2煙霧傳感器
MQ-7一氧化碳傳感器
MQ-135空氣質(zhì)量傳感器
ESP8266-01S(WIFI模塊)
步進電機
有源蜂鳴器
02
—
原理圖設(shè)計
03
—
PCB硬件設(shè)計
PCB圖
04
—
程序設(shè)計
#include"stm32f10x.h" // Device header#include"oled.h"#include"adcx.h"#include"bmp280.h"#include"sensormodules.h"#include"dht11.h"#include"key.h"#include"tim2.h"#include"tim3.h"#include"flash.h"#include"motor.h"#include"led.h"#include"usart.h"#include"iwdg.h"
SensorModules sensorData;//聲明傳感器模塊的結(jié)構(gòu)體變量SensorThresholdValue Sensorthreshold;//聲明傳感器閾值結(jié)構(gòu)體變量
#defineKEY_Long111
#defineKEY_11#defineKEY_22#defineKEY_33#defineKEY_44
#defineFLASH_START_ADDR0x0801f000//寫入的起始地址
uint8_tmotorFlag =0;uint8_toledPages =1;//系統(tǒng)顯示頁面uint8_tmodel;//系統(tǒng)模式
typedefenum{DISPLAY_PAGE1 =1,DISPLAY_PAGE2,SETTINGS_PAGE} OLED_PAGES;
/** * @brief 顯示菜單1的固定內(nèi)容 * @param 無 * @retval 無 */voidOLED_Menu1(void){//顯示“溫度: C”O(jiān)LED_ShowChinese(1,1,48);OLED_ShowChinese(1,2,49);OLED_ShowChar(1,5,':');OLED_ShowChar(1,8,'C');
//顯示“濕度: %”O(jiān)LED_ShowChinese(1,5,50);OLED_ShowChinese(1,6,51);OLED_ShowChar(1,13,':');OLED_ShowChar(1,16,'%');
//顯示”光照強度: Lux“OLED_ShowChinese(2,1,8);OLED_ShowChinese(2,2,9);OLED_ShowChinese(2,3,10);OLED_ShowChinese(2,4,11);OLED_ShowChar(2,9,':');OLED_ShowString(2,14,"Lux");
//顯示“大氣壓強: ”O(jiān)LED_ShowChinese(3,1,12);OLED_ShowChinese(3,2,13);OLED_ShowChinese(3,3,14);OLED_ShowChinese(3,4,15);OLED_ShowChar(3,9,':');OLED_ShowString(3,14,"hPa");
//顯示“系統(tǒng)模式:”O(jiān)LED_ShowChinese(4,1,28);OLED_ShowChinese(4,2,29);OLED_ShowChinese(4,3,30);OLED_ShowChinese(4,4,31);OLED_ShowChar(4,9,':');}
/** * @brief 顯示菜單2的固定內(nèi)容 * @param 無 * @retval 無 */voidOLED_Menu2(void){//顯示“煙霧濃度: ppm”O(jiān)LED_ShowChinese(1,1,20);OLED_ShowChinese(1,2,21);OLED_ShowChinese(1,3,22);OLED_ShowChinese(1,4,23);OLED_ShowChar(1,9,':');OLED_ShowString(1,13,"ppm");
//顯示“一氧化碳: ppm”O(jiān)LED_ShowChinese(2,1,16);OLED_ShowChinese(2,2,17);OLED_ShowChinese(2,3,18);OLED_ShowChinese(2,4,19);OLED_ShowChar(2,9,':');OLED_ShowString(2,13,"ppm");
//顯示“空氣質(zhì)量: ppm”O(jiān)LED_ShowChinese(3,1,24);OLED_ShowChinese(3,2,25);OLED_ShowChinese(3,3,26);OLED_ShowChinese(3,4,27);OLED_ShowChar(3,9,':');OLED_ShowString(3,13,"ppm");}
/** * @brief 顯示菜單1的傳感器數(shù)據(jù) * @param 無 * @retval 無 */voidSensorDataDisplay1(void){//顯示溫度數(shù)據(jù)OLED_ShowNum(1,6, sensorData.temp,2);
//顯示濕度數(shù)據(jù)OLED_ShowNum(1,14, sensorData.humi,2);
//顯示光照強度數(shù)據(jù)OLED_ShowNum(2,10, sensorData.lux,4);
//顯示大氣壓強數(shù)據(jù)OLED_ShowNum(3,10,1020,4);
//顯示系統(tǒng)狀態(tài)數(shù)據(jù)if(!model){OLED_ShowChinese(4,6,36);OLED_ShowChinese(4,7,37);}else{OLED_ShowChinese(4,6,32);OLED_ShowChinese(4,7,33);}}
/** * @brief 顯示菜單2的傳感器數(shù)據(jù) * @param 無 * @retval 無 */voidSensorDataDisplay2(void){
//顯示煙霧濃度數(shù)據(jù)OLED_ShowNum(1,10, sensorData.smoke,3);
//顯示一氧化碳數(shù)據(jù)OLED_ShowNum(2,10, sensorData.CO,3);
//顯示空氣質(zhì)量數(shù)據(jù)OLED_ShowNum(3,10, sensorData.AQI,3);}
/** * @brief 顯示系統(tǒng)閾值設(shè)置界面1 * @param 無 * @retval 無 */voidOLED_SetInterfacevoid(void){//顯示“光照閾值”O(jiān)LED_ShowChinese(1,2,8);OLED_ShowChinese(1,3,9);OLED_ShowChinese(1,4,42);OLED_ShowChinese(1,5,43);OLED_ShowChar(1,11,':');
//顯示“煙霧閾值”O(jiān)LED_ShowChinese(2,2,20);OLED_ShowChinese(2,3,21);OLED_ShowChinese(2,4,42);OLED_ShowChinese(2,5,43);OLED_ShowChar(2,11,':');
//顯示“一氧化碳閾值”O(jiān)LED_ShowString(3,3,"CO");OLED_ShowChinese(3,4,42);OLED_ShowChinese(3,5,43);OLED_ShowChar(3,11,':');
//顯示“空氣質(zhì)量閾值”O(jiān)LED_ShowString(4,3,"AQI");OLED_ShowChinese(4,4,42);OLED_ShowChinese(4,5,43);OLED_ShowChar(4,11,':');
//顯示光照閾值數(shù)值OLED_ShowNum(1,12, Sensorthreshold.luxValue,4);
//顯示煙霧閾值數(shù)值OLED_ShowNum(2,12, Sensorthreshold.smokeValue,3);
//顯示一氧化碳閾值數(shù)值OLED_ShowNum(3,12, Sensorthreshold.COValue,3);
//顯示空氣質(zhì)量閾值數(shù)值OLED_ShowNum(4,12, Sensorthreshold.AQIValue,3);}
/** * @brief 記錄閾值界面下按KEY1的次數(shù) * @param 無 * @retval 返回次數(shù) */uint8_tSetSelection(void){staticuint8_tcount =1;if(KeyNum == KEY_1){KeyNum =0;count++;if(count >4){count =1;}}returncount;}
/** * @brief 顯示閾值界面的選擇符號 * @param num 為顯示的位置 * @retval 無 */voidOLED_Option(uint8_tnum){switch(num){case1:OLED_ShowChar(1,1,'>');OLED_ShowChar(2,1,' ');OLED_ShowChar(3,1,' ');OLED_ShowChar(4,1,' ');break;case2:OLED_ShowChar(1,1,' ');OLED_ShowChar(2,1,'>');OLED_ShowChar(3,1,' ');OLED_ShowChar(4,1,' ');break;case3:OLED_ShowChar(1,1,' ');OLED_ShowChar(2,1,' ');OLED_ShowChar(3,1,'>');OLED_ShowChar(4,1,' ');break;case4:OLED_ShowChar(1,1,' ');OLED_ShowChar(2,1,' ');OLED_ShowChar(3,1,' ');OLED_ShowChar(4,1,'>');break;default:break;}}
/** * @brief 對閾值界面的傳感器閾值進行修改 * @param num 為當前用戶需要更改的傳感器閾值位置 * @retval 無 */voidThresholdModification(uint8_tnum){switch(num){case1:if(KeyNum == KEY_3){KeyNum =0;Sensorthreshold.luxValue +=10;if(Sensorthreshold.luxValue >2000){Sensorthreshold.luxValue =0;}}elseif(KeyNum == KEY_4){KeyNum =0;Sensorthreshold.luxValue -=10;if(Sensorthreshold.luxValue >2000){Sensorthreshold.luxValue =2000;}}break;
case2:if(KeyNum == KEY_3){KeyNum =0;Sensorthreshold.smokeValue +=10;if(Sensorthreshold.smokeValue >500){Sensorthreshold.smokeValue =0;}}elseif(KeyNum == KEY_4){KeyNum =0;Sensorthreshold.smokeValue -=10;if(Sensorthreshold.smokeValue >500){Sensorthreshold.smokeValue =500;}}break;case3:if(KeyNum == KEY_3){KeyNum =0;Sensorthreshold.COValue +=10;if(Sensorthreshold.COValue >500){Sensorthreshold.COValue =0;}}elseif(KeyNum == KEY_4){KeyNum =0;Sensorthreshold.COValue -=10;if(Sensorthreshold.COValue >500){Sensorthreshold.COValue =500;}}break;case4:if(KeyNum == KEY_3){KeyNum =0;Sensorthreshold.AQIValue +=10;if(Sensorthreshold.AQIValue >500){Sensorthreshold.AQIValue =0;}}elseif(KeyNum == KEY_4){KeyNum =0;Sensorthreshold.AQIValue -=10;if(Sensorthreshold.AQIValue >500){Sensorthreshold.AQIValue =500;}}break;default:break;}}
/** * @brief 根據(jù)標志位控制步進電機的運行 * @param 無 * @retval 無 */voidMotorOperation(void){if(motorFlag ==1){MOTOR_Direction_Angle(1,0,90,1);MOTOR_STOP();motorFlag =0;}elseif(motorFlag ==2){MOTOR_Direction_Angle(0,0,90,1);MOTOR_STOP();motorFlag =0;}
}
/** * @brief 傳感器數(shù)據(jù)掃描 * @param 無 * @retval 無 */voidSensorScan(void){DHT11_Read_Data(&sensorData.humi, &sensorData.temp);Get_Average_LDR_LUX(&sensorData.lux);Get_Average_MQ2_PPM(&sensorData.smoke);Get_Average_MQ7_PPM(&sensorData.CO);Get_Average_MQ135_PPM(&sensorData.AQI);sensorData.hPa = (uint32_t)BMP280_Get_Pressure();}
intmain(void){ADCX_Init(); Timer2_Init(9,14398);Uart2_Init(9600);Uart1_Init(115200);IWDG_Init();
OLED_Init();Bmp_Init();DHT11_Init();Key_Init();MOTOR_Init();LED_Init();Buzzer_Init();
Sensorthreshold.luxValue =FLASH_R(FLASH_START_ADDR);//從指定頁的地址讀FLASHSensorthreshold.smokeValue =FLASH_R(FLASH_START_ADDR+2);//從指定頁的地址讀FLASHSensorthreshold.COValue =FLASH_R(FLASH_START_ADDR+4);//從指定頁的地址讀FLASHSensorthreshold.AQIValue =FLASH_R(FLASH_START_ADDR+6);//從指定頁的地址讀FLASH
GENERAL_TIM_Init();userInit();//完成機智云初始賦值gizwitsInit();//開辟一個環(huán)形緩沖區(qū)while(1){
IWDG_ReloadCounter();//使能重裝載寄存器計數(shù)SensorScan();//獲取傳感器數(shù)據(jù)
switch(oledPages){caseDISPLAY_PAGE1:OLED_Menu1();//顯示主頁面1固定信息SensorDataDisplay1();//顯示傳感器1數(shù)據(jù)MotorOperation();
/*按鍵按下時進入主頁面2*/if(KeyNum == KEY_2){KeyNum =0;oledPages = DISPLAY_PAGE2;OLED_Clear();}
/*按鍵按下時切換模式*/if(KeyNum == KEY_1){KeyNum =0;
model = !model;if(!model){LED_OFF();Buzzer_OFF();}}
/*按鍵按下時進入閾值設(shè)計界面*/if(KeyNum == KEY_Long1){KeyNum =0;oledPages = SETTINGS_PAGE;OLED_Clear();}break;
caseDISPLAY_PAGE2:OLED_Menu2();SensorDataDisplay2();MotorOperation();
/*按鍵按下時進入主頁面2*/if(KeyNum == KEY_2){KeyNum =0;oledPages = DISPLAY_PAGE1;OLED_Clear();}break;
caseSETTINGS_PAGE:OLED_SetInterfacevoid();//顯示閾值設(shè)置界面的固定內(nèi)容OLED_Option(SetSelection());//實現(xiàn)閾值設(shè)置頁面的選擇功能ThresholdModification(SetSelection());//實現(xiàn)閾值調(diào)節(jié)功能
//判斷是否退出閾值設(shè)置界面if(KeyNum == KEY_2){KeyNum =0;oledPages = DISPLAY_PAGE1;//跳轉(zhuǎn)到主界面OLED_Clear();//清屏
//存儲修改的傳感器閾值至flash內(nèi)FLASH_W(FLASH_START_ADDR, Sensorthreshold.luxValue, Sensorthreshold.smokeValue,Sensorthreshold.COValue, Sensorthreshold.AQIValue);}break;default:break;}
userHandle();//更新機智云數(shù)據(jù)點變量存儲的值gizwitsHandle((dataPoint_t *)¤tDataPoint);//數(shù)據(jù)上傳至機智云}}
05
—
實驗效果
-
STM32
+關(guān)注
關(guān)注
2292文章
11027瀏覽量
363824 -
智能家居
+關(guān)注
關(guān)注
1934文章
9785瀏覽量
190276 -
機智云
+關(guān)注
關(guān)注
3文章
616瀏覽量
26803
發(fā)布評論請先 登錄
物聯(lián)網(wǎng)智能家居方案-基于Nucleo-STM32L073&機智云 項目實例
物聯(lián)網(wǎng)智能家居方案-基于Nucleo-STM32L073&機智云實例項目打包下載
【GoKit申請】+基于wifi的智能家居
【GoKit申請】小型智能家居系統(tǒng)
【云智易申請】智能家居寶設(shè)計
[活動] 智能設(shè)計(智能家居的研發(fā)實戰(zhàn)實操)專項技能培訓通知
基于機智云的智能家居系統(tǒng)設(shè)計與實現(xiàn)
機智云2016~2017優(yōu)秀項目盤點
【IoT畢業(yè)設(shè)計】基于機智云平臺的智能家居系統(tǒng)
【IoT畢設(shè)】機智云AIoT+esp8266+物聯(lián)網(wǎng)智能家居控制系統(tǒng)
基于gokit3微信寵物屋與機智云的物聯(lián)網(wǎng)智能家居
【IoT畢業(yè)設(shè)計】基于機智云平臺的智能家居系統(tǒng)

STM32項目分享:機智云智慧農(nóng)業(yè)系統(tǒng)

STM32項目分享:智能臺燈(機智云)系統(tǒng)

評論