51 single-chip microcomputer flower, farmland automatic watering irrigation system development, Proteus simulation, schematic diagram and C code

Design requirements
1. Design an automatic watering and irrigation system for flowers and farmland based on 51 single-chip microcomputer;

2. It can detect soil moisture, when it is lower than the set lower limit, start the water pump for watering and irrigation, and provide corresponding sound and light alarm indication;

3. The upper and lower limits of humidity can be set through the buttons;

4. The soil moisture data and the upper and lower limit values ​​of the humidity are displayed on the LCD1602 display screen;

5. Complete system component selection, circuit drawing and C program writing;

System overview The
design scheme of the automatic watering irrigation system uses the AT89C51 single-chip microcomputer as the control core and adopts a modular design method.

The components are: 5V power supply module, soil moisture sensor module, ADC0832 analog-to-digital conversion module, water pump control module, key input module, LCD display module and sound and light alarm module, the structure is as follows.
insert image description here
The working principle is: the soil moisture sensor measures the soil moisture analog signal, the analog signal is converted into a digital signal by the AD converter, and then transmitted to the 51 single-chip microcomputer, and the single-chip computer compares the soil moisture data with the set upper and lower limit values.

When the soil humidity is lower than the lower limit, the water pump is driven to work for irrigation and watering, and an audible and visual alarm is provided. When the soil moisture increases to exceed the lower limit, the sound and light alarm will be turned off, but the pump will continue to work until the soil moisture continues to increase and exceeds the set upper limit.

The user can set the upper and lower limit values ​​of humidity through the keys, and the soil moisture data and the upper and lower limit data are displayed in real time through the LCD display.
insert image description here
insert image description here
Schematic
insert image description here
Simulation Analysis
Open the Proteus simulation file with a .DSN extension. Double-click the microcontroller, load the AutoWater.hex file (located in the Keil C program folder), run the simulation, and the results are as follows.
insert image description here
As can be seen from the figure, the LCD shows that the currently measured soil humidity (Humidity) is 53%, the preset humidity upper limit (H: High abbreviation) is 60%, and the lower limit (L: Low abbreviation) is 30%, and the soil humidity is normal. , within the upper and lower limits.

At this time, the low humidity alarm light and buzzer are off, the relay RL1 switch is turned to the bottom, and the water pump is in a power-off state.

By adjusting the sliding rheostat RV2 (click the two red arrows up and down with the mouse), change the voltage input to ADC0832 sampling channel 0 to simulate the change of soil moisture.

Click on the red arrow pointing down on RV2 to simulate a decrease in soil moisture. For example, when the soil moisture decreases from 53% to 23%, and is lower than the lower limit of 30%, the red LED alarm light is on, the buzzer sounds, the relay RL1 switch is turned to the top, the water pump is powered on, and it starts to water automatically, and the green The working indicator of the pump is also lit.
insert image description here
Click on the red arrow pointing up on RV2 to simulate an increase in soil moisture.

When the soil moisture increases from 23% to 37% and exceeds the lower limit, the sound and light alarm will stop working, but the pump will continue to work until the soil moisture continues to increase above the upper limit. The process is shown below.
insert image description here
insert image description here
It should be noted that after the water pump stops working (that is, the soil humidity exceeds the upper limit), adjust RV2 to simulate the drop of soil humidity. When it falls within the upper and lower limits, the water pump will not start, only when the soil humidity continues to drop below the lower limit. will start.

The upper and lower limits of humidity can be preset by pressing the keys.

Click the "Set" button to enter the upper and lower limit setting mode. First, the cursor of the H upper limit value flashes. At this time, you can click the plus/minus button to change the upper limit value.
insert image description here
After the upper limit value is set, click the "Set" button, and the L lower limit value cursor will blink. Similarly, click the plus/minus button to change the size of the lower limit value.
insert image description here
After the upper and lower limits are set, click the "Set" button again to exit the upper and lower limit setting mode. For example, we set the humidity upper limit H as 75% and the lower limit L as 25%, and the result is shown in the figure below.
insert image description here
In summary, the simulation results meet the design requirements.

part of the code

void main()				//主函数
{
    
       
    
	Init1602();						 //初始化液晶函数
	init();							 //初始化定时器
	init_eeprom();  //开始初始化保存的数据
	while(1)						 //进入循环
	{
    
       
    
		for(m=0;m<50;m++)			//读50次AD值
			sum = adc0832(0)+sum;	//读到的AD值,将读到的数据累加到sum
		temp=sum/50;				//跳出上面的for循环后,将累加的总数除以50得到平均值temp
		sum=0; 						//平均值计算完成后,将总数清零
		temp = temp*0.390625;		//ADC0832存储数据为1个字节,湿度显示范围为0~100,因此1单位湿度=100/256=0.390625				
//		if(temp<=full_range)
//		temp=(temp*100)/full_range;
//		else
//		temp=100;
		if(set==0)					 //set为0,说明现在不是设置状态
			Display_1602(temp,MH,ML);//显示AD数值和报警值
		if(temp<ML&&set==0)	         //湿度值小于报警值
		{
    
       
    
			flag=1;					 //打开报警
			Relay=0;					 //继电器触点闭合,水泵工作
			LED_R=0;					  //红灯点亮
		}
		else if(temp>MH&&set==0)     //湿度值大于报警值
		{
    
       
    
			flag=0;					 //关闭报警
			Relay=1;					 //继电器触点打开,水泵停止
			LED_R=1;					  //红灯熄灭
		}
		else
		{
    
       
    
			flag=0;
			LED_R=1;			      //红灯熄灭
		}
		Key();						 //调用按键函数
	}
}

Data content
(1) Design paper based on 51 single-chip microcomputer flower and farmland automatic watering irrigation system;

(2) Proteus simulation file;

(3) C program files;

(4) Schematic file;

(5) Visio flowchart file;

(6) Reference materials;

(7) List of components;

Data Map
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
Important things to say again! ! !

Since the design of the flower and farmland automatic watering irrigation system of the 51 single-chip microcomputer is my original design, to obtain a complete set of information,

Please search to see my [public] (public *) "number": Jiaoyuan Xiaozhi

Related Posts