功能描述
1、检测宿舍温湿度、光线强度、烟雾浓度
2、设定烟雾浓度阈值,超过则开窗通风-舵机
3、设定光线强度阈值,低于则开灯-USB灯
4、设置温度阈值,超过则打开风扇-
5、oled显示屏显示温湿度、光线强度、烟雾浓度
6、使用app控制开关锁/窗/灯和模式切换。并显示温湿度、光线强度、烟雾浓度(wifi)设置阈值
实物可做,其他功能实物也可以!
电路图

PCB

源代码
#include <reg52.h>
#include <intrins.h>
#include <stdio.h>//printf串口输出头文件
#define uchar unsigned char
#define ushort unsigned int
#define uint unsigned long
#include "lcd1602.h"
#include "uart_trx.h"
#include "eeprom52.h"
#define RATIO 800 //系数,建议选择800-1000
sbit key1 = P1^0;//加键
sbit key2 = P1^1;//减键
sbit beep = P2^0;//蜂鸣器
sbit Fan = P1^3;//风扇
unsigned char pmBuf[7] = 0;//数据接收数组
uint PM25_Value = 0; //PM = ((pmBuf[1]<<8)+pmBuf[2])/1024*8*ratio
uint PM25_ValueMax = 200; //上限初始值
void EEPROM_WRITE()//EEPROM写入
{
SectorErase(0x2000);//擦除扇区
byte_write(0x2001, (PM25_ValueMax>>8)&0xFF);//存储高8位
byte_write(0x2002, (PM25_ValueMax>>0)&0xFF);//存储低8位
byte_write(0x2009, 111);//存储校验值
}
void EEPROM_READ()//EEPROM读出
{
if(byte_read(0x2009)!=111)//开机检测单片机是不是第一次使用,如果不是第一次使用,则先把数据存储一遍,再读取,数据就不会乱码
{
EEPROM_WRITE();//存储
delay_ms(100);
}
PM25_ValueMax = byte_read(0x2001)<<8 | byte_read(0x2002)

最低0.47元/天 解锁文章
578

被折叠的 条评论
为什么被折叠?



