基于51单片机的烟雾检测+温度检测+蜂鸣器报警+光耦+风扇+LCD4602液晶显示(含仿真/原理图/PCB/代码/模块资料)
讲在前面:
51单片机是大多数电子爱好者的入门级单片机,这款设计是一个比较综合的单片机设计。本文介绍了一个典型的51单片机设计,希望对各位有帮助。
本人也在其他平台开源了一些项目和分享:
点击进入B站传送门
概述
1)产品功能:
使用51单片机作为控制器,与ADC0832(ADC芯片)经行I2C通信,
采集烟雾检测模块和温度传感器模块的电压信号,实现烟雾浓度,锅具温度检测。
(锅具检测)检测锅具是否放置,人员暂离保护,锅具加减火控制(四档),排气扇控制,蜂鸣器提醒。
具体功能:
2)使用元器件:
电源降压芯片:L7805
单片机型号:STC89C52
ADC芯片:ADC0832
三极管:S8050直插
LCD1602显示屏
按键:直插6*6轻触开关
直插3mmLED
3)实物电路:
电源电路:
D1为防反接二极管,CE1和C2为输入滤波电容,CE2和C1为输出滤波电容。后接LED做电源指示灯。
单片机最小系统:
ADC:
烟雾传感器和温度传感器:
人员检测和锅具检测的红外对管模块:
风扇和蜂鸣器:
LCD1602显示屏:
6个按键:
指示灯:
PCB效果图:
实物:
4)Proteus实物电路:
由于Proteus没有传感器模块,所以用滑动变阻器模拟传感器模块输出的电压,红外对管模块用自锁开关来模拟
5)程序:
变量声明:
//****************************** 基于 51 单片机的简易厨房安全检测控制系统 *******************************
#include <reg52.h>
#include <intrins.h>/*已知数据类型重新定义*/
#define uchar unsigned char
#define uint unsigned int
/*引脚定义*/
//LCD1602
#define LCD1602_DB P0 //LCD1602数据总线
//sbit LCD1602_RS = P2^0; //RS端
//sbit LCD1602_RW = P2^1; //RW端
//sbit LCD1602_EN = P2^2; //EN端
sbit LCD1602_RS = P2^4; //RS端
sbit LCD1602_RW = P2^5; //RW端
sbit LCD1602_EN = P2^6; //EN端//ADC0832
sbit cs = P1^0;//片选使能,低电平有效
sbit clk = P1^1;//芯片时钟输入
sbit dio = P1^2;//数据输入DI与输出DO//四个按键输入
sbit key_temth_r = P3^0; //增加温度阈值的按键
sbit key_temth_f = P3^1; //减小温度阈值的按键
sbit key_gasth_r = P3^2; //增加气体浓度阈值的按键
sbit key_gasth_f = P3^3; //减小气体浓度阈值的按键
sbit key_fir_r = P3^4; //加火按键
sbit key_fir_f = P3^5; //减火按键sbit Beep = P3^7; //蜂鸣器
sbit FAN = P3^6; //风扇
sbit GuangOu_Guo = P2^5; //光耦检测锅具
sbit GuangOu_People = P2^6; //光耦检测人
sbit Guo = P2^7; //控制锅具烧火的引脚//挡位指示的4个灯
sbit Guo1 = P1^4;
sbit Guo2 = P1^5;
sbit Guo3 = P1^6;
sbit Guo4 = P1^7; uchar adc = 0; //ADC读取的原始值
uint voltage = 0; //ADC读取的原始值转换得到的电压值uint gas = 0; //创建气体浓度值
uint gas_th = 70; //创建气体浓度阈值
uint tem = 0; //创建温度值
uint tem_th = 270; //创建温度阈值uint fir = 0; // fir = 1,允许锅具使用,fir = 0,禁止锅具使用uchar LED_buffer1[16] = {"Gas: "};//ADC显示缓冲
uchar LED_buffer2[16] = {"Tem: "};//电压显示缓冲uint num = 0; //延时计数值
uint GuangOu_Guo_falg = 1; //锅具检测光耦标志位
uint GuangOu_People_falg = 1; //人员检测光耦标志位
主程序:(挺简单的,没用定时器,全程用if else…)
void main()
{//初值设定Beep = 0; //蜂鸣器FAN = 0; //风扇Guo = 0; //锅具使能Guo1 = 1; Guo2 = 1; Guo3 = 1; Guo4 = 1; //初始挡位全为0, 1:挡位灯不亮,0:挡位灯亮Init_LCD1602();//1602初始化LCD1602_Dis_Str(0, 0, " System Init "); //显示字符串LCD1602_Dis_Str(0, 1, " Please Wait "); //显示字符串DelayMS(1000); //显示初始化字符串1swhile(1) // 一直循环{LCD1602Display(); //一直循环读取电压和显示数值GuangOu_Guo_falg = GuangOu_Guo; //将光耦值赋值给标志位GuangOu_People_falg = GuangOu_People; //将光耦值赋值给标志位if(GuangOu_Guo == 0) //有锅{if(GuangOu_People == 0) //有人{if(tem <= tem_th) //温度未超过阈值,即没有烧锅{ Guo = 1; Beep = 0; //满足以上3个条件才开启锅具使能} }}if(GuangOu_Guo_falg == 1) //无锅{ //等待一段时间后num ++; //num自加if(num >= 1000) //进行多次实验,一个while循环大约是10ms,1000就是10s{num = 0; //记得清零,方便下次使用Beep = 1; //蜂鸣器报警Guo = 0;} } if(GuangOu_People_falg == 1) //无人{ //等待一段时间后num ++;if(num >= 1000){num = 0;Beep = 1;Guo = 0;} }if(gas >= gas_th){ FAN = 1; }else if(gas <= gas_th){ FAN = 0; } //气体浓度超标反应和正常反应if(tem >= tem_th){ Guo = 0; } //温度过高,烧锅反应//6个按键if(key_temth_r == 0){DelayMS(10); //消抖if(key_temth_r == 0){while(key_temth_r == 0); //按下按键,松开后才算数tem_th += 10; //温度阈值 +10if(tem_th >= 500){ tem_th = 500; } //温度阈值限幅}}if(key_temth_f == 0){DelayMS(10);if(key_temth_f == 0){while(key_temth_f == 0);tem_th -= 10;if(tem_th <= 0){ tem_th = 0; }}}if(key_gasth_r == 0){DelayMS(10);if(key_gasth_r == 0){while(key_gasth_r == 0);gas_th += 10;if(gas_th >= 500){ gas_th = 500; }}}if(key_gasth_f == 0){DelayMS(10);if(key_gasth_f == 0){while(key_gasth_f == 0);gas_th -= 10;if(gas_th <= 0){ gas_th = 0; }}}// 加火减火if(key_fir_r == 0){DelayMS(10);if(key_fir_r == 0){while(key_fir_r == 0);fir += 1;if(fir >= 4){ fir = 4; }}}if(key_fir_f == 0){DelayMS(10);if(key_fir_f == 0){while(key_fir_f == 0);fir -= 1;if(fir <= 0){ fir = 0; }}}if(Guo == 1) //如果锅具使能,才能进行加减火控制{if(fir ==0){ Guo1 = 1; Guo2 = 1; Guo3 = 1; Guo4 = 1; }if(fir ==1){ Guo1 = 0; Guo2 = 1; Guo3 = 1; Guo4 = 1; }if(fir ==2){ Guo1 = 0; Guo2 = 0; Guo3 = 1; Guo4 = 1; }if(fir ==3){ Guo1 = 0; Guo2 = 0; Guo3 = 0; Guo4 = 1; }if(fir ==4){ Guo1 = 0; Guo2 = 0; Guo3 = 0; Guo4 = 0; }}else if(Guo == 0) //如果锅具没有被使能,则所有挡位关闭{Guo1 = 1; Guo2 = 1; Guo3 = 1; Guo4 = 1;}}
}
演示视频:
待发布
主要内容差不多都在上面了,相信大家可以根据此文设计制作出属于自己的51单片机设计。
全部文件: