51 microcontroller DHT11 temperature and humidity control system simulation design (proteus simulation + program + schematic diagram + report + explanation video)


51 microcontroller DHT11 temperature and humidity control system simulation design (proteus simulation + program + schematic diagram + report + explanation video)

Simulation diagramproteus8.9及以上

Program compiler: keil 4/keil 5

Programming language: C language

Design number: S0044

1. Main functions:

Use the knowledge you have learned to create a temperature and humidity controller proteus simulation design based on 51 microcontroller

1. If the buttons adjust the upper and lower limits of temperature and humidity, the corresponding circuit works when the temperature and humidity are not within the upper and lower limits. The system simulates the cooling module, heating module, dehumidification module, and humidification module through relays. Realize automatic control of temperature and humidity.

2. The system uses DHT11 sensor.

3. Use LCD1602 to display the current temperature, humidity and setting values.

4. The default lower temperature limit is 20°C, and the upper temperature limit is 30°C. The lower limit of humidity is 30%, and the upper limit of humidity is 80%.

It should be noted that the 51 microcontroller chip in the simulation is universal. AT89C51 and AT89C52 are specific models of the 51 microcontroller, and the cores are compatible. 原理图不变情况下, whether stc or at are the same, the pin functions are the same, and the program is the same. The chip can be replaced with 51 microcontroller chips such as STC89C52/STC89C51/AT89C52/AT89C51.

The following is a display diagram of this design information:

2. Simulation

Start simulation

Open the simulation project, double-click the microcontroller in proteus, select the hex file path, and then start simulation. After starting the simulation, LCD1602 displays the temperature and humidity.

img

During the simulation, adjust the value of the DHT11 temperature and humidity module by pressing the buttons to change the displayed value.

img

imgThe up and down arrows are used to change the temperature/humidity value. The down arrow decreases the value, and the up arrow increases the value. imgUse this arrow to change whether the adjusted value is temperature or humidity.

imgThe changed icon displays the values ​​of humidity and temperature. The humidity value is on the first line and the temperature value is on the second line.

After starting the simulation, press the Set/Switch button to adjust the upper and lower thresholds. The default lower temperature limit is 20°C and the upper temperature limit is 30°C. The lower limit of humidity is 30%, and the upper limit of humidity is 80%.

img

After starting the simulation and adjusting the humidity to exceed 80% of the upper humidity threshold, the dehumidification module starts working and the red indicator light turns on when the humidity exceeds the upper limit.

img

After starting the simulation and adjusting the humidity to be 30% lower than the lower humidity threshold, the humidification module starts to work and the red indicator light turns on.

img

After starting the simulation and adjusting the temperature to exceed the upper temperature threshold of 30°C, the cooling module starts to work and the red indicator light turns on.

img

After starting the simulation and adjusting the temperature to 20°C lower than the lower temperature threshold, the module starts working and the red indicator light turns on.

img

3. Program code

Use keil4 or keil5 to compile, the code has comments, and you can understand the meaning of the code in conjunction with the report.

img
Main program code

#include "reg51.h"
#include "lcd1602.h"
#include "DHT11.h"
#define uchar unsigned char
#define uint unsigned int
sbit k1=P1^0;//按钮
sbit k2=P1^1;
sbit k3=P1^2;
sbit out1=P1^3;//输出控制
sbit out2=P1^4;
sbit out3=P1^5;
sbit out4=P1^6;

uchar time=0,mode=0;//系统变量
uchar disp1[]="00 ";
uchar lim1=20,lim2=30,lim3=30,lim4=80;//阀值

void main()//主函数
{
    
    
	init_1602();
	TMOD|=0X01;
	TH0=0X3C;
	TL0=0XB0;	
	ET0=1;//打开定时器0中断允许
	EA=1;//打开总中断
	TR0=1;//打开定时器
	while(1)
	{
    
    
		if(!k1)//设置
		{
    
    
			if(mode<4)
				mode++;
			else
				mode=0;
			write_com(1);
			while(!k1);
		} 
		if(!k2)//加
		{
    
    
			switch(mode)
			{
    
    
				case 1:
					if(lim1<lim2)
						lim1++;
					break;
				case 2:
					if(lim2<99)
						lim2++;
					break;
				case 3:
					if(lim3<lim4)
						lim3++;
					break;
				case 4:
					if(lim4<99)
						lim4++;
			}
			while(!k2);
		}
		if(!k3)//减
		{
    
    
			switch(mode)
			{
    
    
				case 1:
					if(lim1>0)
						lim1--;
					break;
				case 2:
					if(lim2>lim1)
						lim2--;
					break;
				case 3:
					if(lim3>0)
						lim3--;
					break;
				case 4:
					if(lim4>lim3)
						lim4--;
			}
			while(!k3);
		}
	}
}
//定时器中断
void Timer0() interrupt 1
{
    
    
	if(time<10)//0.5s
		time++;
	else
	{
    
    
		time=0;
		dht11_recive();//测量温湿度
		if(dht11_dat[2]<lim1)//加热
			out2=0;
		else
			out2=1;
	   	if(dht11_dat[2]>lim2)//散热
			out1=0;
		else
			out1=1;
		if(dht11_dat[0]<lim3)//加湿
			out4=0;
		else
			out4=1;
	   	if(dht11_dat[0]>lim4)//除湿
			out3=0;
		else
			out3=1;
		//显示
		write_com(0x0c);
		if(mode==0)//正常模式
		{
    
    
			disp1[0]=dht11_dat[2]/10+0x30;
			disp1[1]=dht11_dat[2]%10+0x30;
			disp1[2]='C';
			write_string(1,0,"Temp:");
			write_string(1,5,disp1);
			disp1[0]=dht11_dat[0]/10+0x30;
			disp1[1]=dht11_dat[0]%10+0x30;
			disp1[2]='%';
			write_string(2,0,"Humi:");
			write_string(2,5,disp1);
		}
		else	//设置模式
		{
    
    
			disp1[0]=lim1/10+0x30;
			disp1[1]=lim1%10+0x30;
			disp1[2]='C';
			write_string(1,0,"TL:");
			write_string(1,3,disp1);
			disp1[0]=lim2/10+0x30;
			disp1[1]=lim2%10+0x30;
			disp1[2]='C';
			write_string(1,8,"TH:");
			write_string(1,11,disp1);

			disp1[0]=lim3/10+0x30;
			disp1[1]=lim3%10+0x30;
			disp1[2]='%';
			write_string(2,0,"HL:");
			write_string(2,3,disp1);
			disp1[0]=lim4/10+0x30;
			disp1[1]=lim4%10+0x30;
			disp1[2]='%';
			write_string(2,8,"HH:");
			write_string(2,11,disp1);
			//设置光标
			switch(mode)
			{
    
    
				case 1:write_sfm(1,4);break;
				case 2:write_sfm(1,12);break;
				case 3:write_sfm(2,4);break;
				case 4:write_sfm(2,12);
			}
			write_com(0x0e);
		}
	}
	TH0=0X3C;
	TL0=0XB0;
}

4. Schematic diagram

The schematic diagram is drawn using AD and can be used as a reference for linking to the physical object. Simulation is different from the physical object. If you are inexperienced, do not easily create the physical object. Novices will make many stupid mistakes when making physical objects, which will take a lot of time. This design does not provide answers to questions about physical objects.

The difference between Proteus simulation and physical works:

1. Running environment: Proteus simulation runs on the computer, while the real thing runs on the hardware circuit board.

2. Debugging method: In Proteus simulation, you can easily perform single-step debugging and observe changes in variable values, while in real objects, you need to debug through a debugger or serial port output.

Circuit connection method: In Proteus simulation, the circuit connection can be modified through software settings, but in the real thing, it needs to be modified through the hardware circuit board and connecting wires.

3. Running speed: Proteus simulation usually runs faster than the real thing, because the simulation is based on computer operation, while the real thing needs to consider factors such as the physical limitations of the circuit board and the response time of the device.

4. Function realization: In Proteus simulation, different functions can be realized through software settings, but in real objects, they need to be realized according to the circuit design and device performance.

Insert image description here

Parts list

Number of component models Microcontroller
AT89C51 1
capacitor 10uf 1
capacitor 30pf 2
crystal oscillator 12MHZ 1
resistor 10k 1
button 4
temperature and humidity sensor DHT11 1
potentiometer 1k 2
LED red 4
resistors 100 ohms 4
resistors 1k 4
transistor PNP 4
relay 5V 4
display LCD1602 1 row
resistor 10k 1

Stabilized power supply part
Pin header 2P 1
Capacitor 0.1uf 2
Capacitor 100uf 2
Voltage regulator 7805 1

5. Design report

7386-word design report, including design block diagram, introduction, hardware design introduction, software design introduction, simulation debugging, summary and references.

img

6. Design information content list & download link

Material design materials include simulation, program code, explanation videos, functional requirements, design reports, software and hardware design block diagrams, etc.

0. Common usage problems and solutions – a must-read! ! ! !

1. Simulation diagram

2. Program source code

3. Proposal report

4. Schematic diagram

5. Functional requirements

6. Components list

7. Design report

8. Software and hardware flow chart

9. Explanation video

Altium Designer Software Information

KEIL software information

Proteus software information

Microcontroller learning materials

Defense skills

Common descriptions for design reports

Double-click the mouse to open and find more 51 STM32 Microcontroller Course Graduation Project.url

img

Data download link (clickable):

Guess you like

Origin blog.csdn.net/weixin_52733843/article/details/132672318