Design and Realization of Temperature and Humidity Control System for Greenhouse Based on Single Chip Microcomputer

 Features

  • With 51 single-chip microcomputer as the main control system;
  • LCD display current temperature and humidity
  • Press the button to set the upper and lower limits of the temperature and humidity alarm;
  • When the temperature is lower than the lower limit, the relay closes the heating sheet for heating;
  • When the temperature exceeds the upper limit, the relay closes and turns on the fan to cool down
  • When the humidity is lower than the lower limit, the relay closes the humidifier for humidification
  • When the humidity is higher than the upper limit, the relay closes and turns on the fan for dehumidification
  • When the temperature and humidity are not within the setting range, the buzzer will remind you of the quotation and the LED lights on the relay will form an audible and visual alarm
  • The whole circuit is powered with 5v;

 circuit diagram

PCB


source code

#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);//读取上限值
}

void Get_PM(void)//读取PM2.5值,具体的数据帧意思,请自行查阅芯片手册
{
    char i = 0;
    char j = 0;
    char k = 0;

	  COM.RX_Cnt = 0;
    if(COM.B_RX_OK == 1)//串口数据接收完成
    {
        for(i = 0; i<8; i++)
        {
            if((RX_Buffer[i] == 0xAA)&&(RX_Buffer[i+6]==0xFF))//判断接收的数据是否正确
            {
                goto find2;
            }
        }
        goto end2;
find2:
        for(j = 0; j<7; j++)
        {
            pmBuf[j] = RX_Buffer[i+j];//数据获取
        }

        PM25_Value = (unsigned int)((pmBuf[1]*256)+pmBuf[2])*5/2048.0*RATIO;//计算PM2.5值
        COM.B_RX_OK = 0;
    }
end2:
    return;
}



void main(void)
{
    unsigned int test;

	  EEPROM_READ();//开机读取存储值
    LCD_init();//1602初始化
    Uart_Init(2400);//串口初始化波特率2400
  
    LCD_write_string(0,0,"Pm2.5:    ug/m3 ");
    LCD_write_string(0,1,"PmMax:    ug/m3 ");
	  //显示上限值
	  LCD_write_char(7, 1, PM25_ValueMax % 1000 / 100 + 0x30);
		LCD_write_char(8, 1, PM25_ValueMax % 100 / 10 + 0x30);
		LCD_write_char(9, 1, PM25_ValueMax % 10 + 0x30);
    while(1)
    {
			if (test ++ > 250)//大约250ms读取一次
			{
					test = 0 ;

					Get_PM();//获取PM2.5
					if(PM25_Value > 999)//限值,最大999
					 PM25_Value = 999;
					//显示PM2.5
					LCD_write_char(7, 0, PM25_Value % 1000 / 100 + 0x30);
					LCD_write_char(8, 0, PM25_Value % 100 / 10 + 0x30);
					LCD_write_char(9, 0, PM25_Value % 10 + 0x30);
					
					if(PM25_Value >= PM25_ValueMax)//超过上限,蜂鸣器报警
					{
							beep = ~beep;
						  Fan = 0;
						  delay_ms(100);
					}
					else
					{
							beep = 1;
						  Fan = 1;
					}
			}
			if(key1 == 0)//加键按下
			{
					delay_ms(10);//消抖
				  if(key1 == 0)
					{
						  beep = 0;
						  delay_ms(100);
						  beep = 1;
							while(key1 == 0);
						  if(PM25_ValueMax<999)PM25_ValueMax+=10;//上限最大到999,每次加10
						  //显示
						  LCD_write_char(7, 1, PM25_ValueMax % 1000 / 100 + 0x30);
							LCD_write_char(8, 1, PM25_ValueMax % 100 / 10 + 0x30);
							LCD_write_char(9, 1, PM25_ValueMax % 10 + 0x30);
						  EEPROM_WRITE();//保存
					}
			}
			if(key2 == 0)//减键按下
			{
					delay_ms(10);
				  if(key2 == 0)
					{
						  beep = 0;
						  delay_ms(100);
						  beep = 1;
							while(key2 == 0);
						  if(PM25_ValueMax>=10)PM25_ValueMax-=10;//上限最小到0,每减10
						  //显示
						  LCD_write_char(7, 1, PM25_ValueMax % 1000 / 100 + 0x30);
							LCD_write_char(8, 1, PM25_ValueMax % 100 / 10 + 0x30);
							LCD_write_char(9, 1, PM25_ValueMax % 10 + 0x30);
						  EEPROM_WRITE();//保存
					}
			}
			delay_ms(1);
    }
}


        

Components list

Design and Realization of Temperature and Humidity Control System for Greenhouse Based on Single Chip Microcomputer
name model quantity
single chip microcomputer STC89C52 1
IC seat P40 1
Universal board 9*15cm 1
crystal oscillator 11.0592M 1
electrolytic capacitor 10uF 1
electrolytic capacitor 1000uf 1
Ceramic Capacitor 22pF 2
resistance 10K 3
resistance 1K 4
resistance 2k 1
LED red 5MM 1
LED green 5MM 1
buzzer active 1
Triode S9012 1
button 5
display screen LCD1602 1
Pin 16P 1
row mother 16P 1
Human body infrared module HC-SR501 1
row mother 3P 1
Temperature Sensor DS18B20 1
smoke sensor MQ-2 1
Analog to Digital Converter ADC0832 1
IC seat 8p 1
GSM module SIM800c 1
power base 5MM 1
power cable 5V2A 1
Self-locking switch 1
relay 1
small water pump 1
wire Slightly
Solder wire Slightly

references

参考文献
[1]王德保.GPS在城市控制网中的应用研究[D].山东:山东科技大学,2005.
[2]何立民.从现代计算机视角看嵌入式系统(4)嵌入式系统40年发展史[J].单片机与嵌入式系统应用,2016,16(04):77-79.
[3]康桂霞,刘达.FPGA应用技术教程[M].北京:人民邮电出版社:201306.229.
[4]朴德慧,衣英刚.液晶显示器驱动板MCU电路介绍(上)[J].家电检修技术,2012(11):53.
[5]段廷魁.全球卫星定位系统(GNSS)在工程测量中的实践运用探索0[J].科技创新与应用,2021(05):182-184.
[6]宋戈,黄鹤松.51单片机应用开发范例大全[M].北京:人民邮电出版社:国家信息技术紧缺人才培养工程系列丛书,201206.558.
[7]罗小青.单片机原理及应用教程[M].北京:人民邮电出版社,201409.180.
[8]沈庆阳.单片机实践与应用[M].北京:清华大学出版社,2002.
[9]杜深慧.温湿度检测装置的设计与实现[M].北京:机械工业出版社,2004.
[10]林嘉.基于89S52的LCD1602程序设计[J].电脑知识与技术,2012(26):6376-6378.
[11]刘光伟.基于单片机的温室温湿度监测系统设计与实现[D].秦皇岛市:燕山大学,2012.
[12]褚福强,董学仁.单片机的网络接入技术研究[J].仪器仪表用户,2006(05):4-5.
[13]陈英俊.基于单片机的温湿度监测和报警系统设计[J].广东石油化工学院学报,2013(04):42-46.
[14]廖丽媛.基于应变式扭矩传感器的测量系统的设计[D].上海市:东华大学,2013.
[15]刘九庆.温室环境工程技术[M].吉林:东北林业大学出版社,2002.
[16]王明喜,崔世茂.大棚型日光温室光照、温度及湿度等性能的初步研究[J].农业工程技术(温室园艺),2008(05):19-21.
[17]张迎辉.单片微型计算机键盘接口设计[J].信息技术,2004(07):68-69+91.
[18]张友德,赵志英.单片微型机原理应用与实验[M].上海市:复旦大学出版社,2003.
[19]赵芝芸.温室智能监控系统[D].江苏:江苏科技大学,2010.
[20]张宏伟.基于STM32的智能环境监测系统设计与实现[J].大庆师范学院学报,2020(05):32-35.
[21]王世伟,杨越.基于STM32的多型号舵机调试器设计[J].九江学院学报(自然科学版),2020,35(02):33-36.
[22]Pengcheng Zhao,Meijun Ni,Chao Chen,Chenxi Wang,PingpingYang,Xiahui Wang,Chunyan Li,Yixi Xie,Junjie Fei. A Novel Self-protection Hydroquinone Electrochemical Sensor Based on Thermo -sensitive Triblock Polymer PS-PNIPAm-PS[J].
[23]Jian Wang,Jing Chen,Xiaofu Xiong,Xiaofeng Lu,ZhengLiao,Xiaobo Chen.Temperature safety analysis and backup protectionscheme improvement for overhead transmission line in poweroscillation condition[T].Electric Power Systems Research,2019,166.
[24]Fuji Electric Co.Ltd.;Patent Issued for SeiconductorDevice And Method Of Outputting Temperature Alarm (USPTO10,164,626)[J].Electronics Newsweekly,2019.
[25]VERSID,INC;Patent Issued for Refrigeration UnitTemperature Alarm Using Thermal Properties of Food to Eliminate FalseAlarms (USPTO 9752810)[J].Computers,Networks &Communications,2017.
[26]Fuji Electric Co.Ltd;Patent Application Titled"Semiconductor Device and Method of Outputting Teperature Alarm"Published Online (USPTO 20170077919)[J]. Technology & BusinessJournal,2017.
[27]su Yuanping,Xu Lihong,Goodman Erik D.Multi-layerhierarchical optimisation of greenhouse climate setpoints for energyconservation and improvement of crop yield[J].Biosystems
[28]黄松茂.基于STM32的家庭环境监测系统的设计与实现[D].甘肃兰州.西北师范大学,2018.:23-30.
[29]李大琳.智能车内温度监测系统设计[J].山东工业技术,2014(12):80-81.
[30]郭雯,王海涛. 智能输液系统的发展与应用.医疗卫生装备,2012

  

Guess you like

Origin blog.csdn.net/u013253075/article/details/131721141