功能介绍:
0.本系统采用STM32F103RCT6作为单片机
1.采用的LCD1602液晶实时显示当前光强土壤湿度等参数信息
2.当土壤湿度超过设定的阈值,蜂鸣器报警,同时控制水泵工作状态
3.按键可更改环境参数的阈值
4.通过WiFi模块可以和手机端进行数据通信
5.温度传感器和光强传感器均采用高精度数字类传感器
原理图:
PCB:
主程序:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197#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" // 局部变量,用于保存转换计算后的电压值 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],最高是64MH HSI_SetSysClock(RCC_PLLMul_2); //使用内部8MHz晶振,并设置PLL输出为8MHz // 端口初始化 GPIO_Config(); GENERAL_TIM_Init(); USART_Config(); DelayMs(1000); printf("AT+CIPMUX=1rn"); //打开多连接 DelayMs(1000); printf("AT+CIPSERVER=1,8080rn"); //建立服务 端口号为8080 DelayMs(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) //在范围内 { 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; //温度转换 Single_Write_BH1750(0x01); // power on Single_Write_BH1750(0x10); // H- resolution mode Multiple_Read_BH1750(); //连续读出数据,存储在BUF中 lightBuf=BUF[0]; lightBuf=(lightBuf<<8)+BUF[1];//合成数据,即光照数据 f_light=(float)lightBuf/1.2; //计算光照数据 } void SendData(void) { printf("AT+CIPSEND=0,34rn"); //发送32位数据 DelayMs(100); printf("Hm:%2d%% T:%5.1f'CrnLight:%8.1flxrn", humidity, f_temp, f_light); //串口发送 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/
最后
以上就是爱笑皮卡丘最近收集整理的关于0343基于STM32单片机的茶园大棚环境土壤湿度光强WiFi监测系统proteus仿真原理图PCB的全部内容,更多相关0343基于STM32单片机内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复