Design of automatic watering system based on single chip microcomputer

Publisher:AningmengLatest update time:2019-10-25 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Automatic watering, humidity detection, adjustable upper and lower limits of humidity, automatic and manual modes!

The physical picture produced is as follows:
 
Functional introduction

Single-chip soil humidity detection automatic watering system The system is designed with STC89C52 single-chip microcomputer + ADC0832 + LCD1602 liquid crystal + soil humidity sensor + waterproof temperature sensor + pumping motor + button + buzzer. The

first line of the LCD displays the actual humidity .
The second line of the LCD displays the upper limit of humidity and the lower limit of humidity.
Button description:
     From the first one on the left, minus key, plus key, set key.

1. Single-chip microcomputer model: STC89C52/51, AT89C52/51, AT89S52/51 are optional.

2. The product comes with a single-chip microcomputer power-on reset circuit, a manual reset circuit (reset button), and a crystal oscillator circuit (providing a clock cycle for the single-chip microcomputer).

3. The LCD1602 liquid crystal displays soil humidity and temperature, and the alarm parameters can also be displayed at the same time, which is intuitive and clear.

4. The upper and lower limit alarm ranges of humidity and temperature can be set, and the function of power-off saving is available. The alarm is saved in the STC microcontroller and does not need to be reset when powered on.

5. When the humidity is lower than the lower limit, the water pump is turned on for automatic irrigation with sound and light alarm. When the humidity is higher than the upper limit, the water pump is automatically turned off to stop irrigation.

6. When the temperature is higher than the upper limit, the water pump is turned on for automatic irrigation with sound and light alarm. When the temperature is lower than the lower limit, the water pump is automatically turned off to stop irrigation.

7. With manual mode, press the minus key to manually turn on the pumping motor, and press the plus key to manually turn off the pumping motor.

8. A water pipe for the matching water pump is provided.


Back:
 
The simulation schematic diagram is as follows (the proteus simulation project file can be downloaded in the attachment of this post)
 


The circuit schematic diagram is as follows:
 
D0 on the sensor does not need to be connected to AO connected to the 0832 chip.

Note: The contents of the above four folders are the same, but they are opened with different software.

1. .SchDoc is in Altium Designer format: Altium Designer software needs to be installed.
2. .sch is in Protel 99SE format: you need to install Protel 99SE software.
3. PDF format: you can open it with PDF software, such as Foxit PDF Reader, Adobe Reader, etc.
4. Word format: you can open it with Word or WPS software.


Component list of automatic watering system version 2:            
No. "Comment
" "Description
" "Quantity
"
1 BUZZER Buzzer 1
2 10uF direct-plug electrolytic capacitor 1
3 30pf direct-plug ceramic capacitor 2
4 104 direct-plug ceramic capacitor 1
5 220uF direct-plug electrolytic capacitor 1
6 Light-emitting diode 5mm direct-plug light-emitting diode 1
7 LCD1602 LCD1602 liquid crystal display 1
8 Header 2 pin 2-Pin 1
9 POWER DC power socket 1
10 Header 3 pin 3-Pin 1
11 S9012 PNP transistor 2
12 2.2K color ring resistor 1
13 1K color ring resistor 3
14 10K color ring resistor 2
15 SW-PB button 6X6X5MM 4
16 SWITCH Self-locking switch 1
17 MCU 51 single-chip microcomputer 1
18 ADC0832 analog-to-digital conversion chip 1
19 12M crystal oscillator 1
Supporting equipment            
1 Wire XXcm 1
2 Solder XXcm 1
3 USB to DC3.5mm power cable System power supply 1
4 9*15 multi-purpose board 1
5 Single-chip microcomputer socket 40-pin IC socket 1
6 IC socket 8-pin IC socket 1
7 LCD1602 socket 16P female header 1
8 LCD1602 lead pin 16P pin header 1

The single-chip microcomputer source program is as follows:

#include //Call the MCU header file

#define uchar unsigned char //unsigned character macro definition variable range 0~255

#define uint unsigned int //Unsigned integer macro definition variable range 0~65535


#include


sbit SCL=P1^4; //SCL is defined as the 3rd pin of P1 port, connected to ADC0832 SCL pin

sbit DO=P1^5; //DO is defined as the 4th pin of P1 port, connected to ADC0832DO pin

sbit CS=P1^3; //CS is defined as the 4th pin of P1 port, connected to ADC0832 CS pin


sbit beep = P3^3; //Buzzer IO port definition

uint temperature,s_temp; //temperature variable

uchar shidu; //humidity level

uchar s_high = 70,s_low = 25; //Humidity alarm parameters


sbit dianji = P1^6; //Motor IO definition


bit flag_300ms;

uchar key_can; //Key value variable

uchar menu_1; //Menu design variables


//These three pin references

sbit rs=P1^0; //1602 data/command selection pin H: data L: command

sbit rw=P1^1; //1602 read and write pin H: data register L: instruction register

sbit e =P1^2; //1602 enable pin falling edge trigger

uchar code table_num[]="0123456789abcdefg";


/********************************************************************

* Name: delay_uint()

* Function: small delay.

* Input: None

* Output: None

***************************************************************************/

void delay_uint(uint q)

{

        while(q--);

}


/********************************************************************

* Name: write_com(uchar com)

* Function: 1602 command function

* Input: Input command value

* Output: None

***************************************************************************/

void write_com(uchar com)

{

        e=0;

        rs=0;

        rw=0;

        P0=com;

        delay_uint(3);

        e=1;

        delay_uint(25);

        e=0;

}


/********************************************************************

* Name: write_data(uchar dat)

* Function: 1602 write data function

* Input: Data to be written to 1602

* Output: None

***************************************************************************/

void write_data(uchar dat)

{

        e=0;

        rs=1;

        rw=0;

        P0=dat;

        delay_uint(3);

        e=1;

        delay_uint(25);

        e=0;        

}


/********************************************************************

* Name: write_sfm2(uchar hang,uchar add,uchar date)

* Function: Display a 2-digit decimal number. If you want the fifth character of the first line to display "23", call this function as follows

                  write_sfm1(1,5,23)

* Input: row, column, need to enter 1602 data

* Output: None

***************************************************************************/

void write_sfm2(uchar hang,uchar add,uint date)

{

        if(hang==1)   

                write_com(0x80+add);

        else

                write_com(0x80+0x40+add);

        write_data(0x30+date/10%10);

        write_data(0x30+date%10);        

}


/********************************************************************

* Name: write_string(uchar hang,uchar add,uchar *p)

* Function: Change the value of a certain bit in the LCD. If you want the fifth character in the first line to start displaying "ab cd ef", call this function as follows

                  write_string(1,5,"ab cd ef;")

* Input: row, column, need to enter 1602 data

* Output: None

***************************************************************************/

void write_string(uchar hang,uchar add,uchar *p)

{

        if(hang==1)   

                write_com(0x80+add);

        else

                write_com(0x80+0x40+add);

                while(1)

                {

                        if(*p == '') break;

                        write_data(*p);

                        p++;

                }        

}


/********************************************************************

* Name: init_1602()

* Function: Initialize 1602 LCD 

* Input: None

* Output: None

***************************************************************************/

void init_1602()

{

        write_com(0x38);

        write_com(0x38);

        write_com(0x0c);

        write_com(0x06);

        delay_uint(1000);

        write_string(1,0," shidu:00% ");

        write_string(2,0," SH:00% SL:00% ");

        write_sfm2(2,4,s_high); //Display humidity upper limit

        write_sfm2(2,12,s_low); //Display humidity lower limit

}



/**************************1ms delay function********************************/

void delay_1ms(uint q)

{

        uint i,j;

        for(i=0;i                for(j=0;j<120;j++);

}


/***********Reading analog conversion data************************************************************/        

//Please first understand the serial protocol of ADC0832 analog-to-digital conversion, and then read this function. It is mainly to understand the corresponding timing diagram. This function simulates the serial protocol of 0832

                                                // 1 0 0 channel

                                                // 1 1 1 channel 

unsigned char ad0832read(bit SGL,bit ODD)

{

        unsigned char i=0,value=0,value1=0;                

                SCL=0;

                DO=1;

                CS=0; //Start

                SCL=1; //first rising edge        

                SCL=0;

                DO=SGL;

                SCL=1; //Second rising edge

                SCL=0;

                DO=ODD;

                SCL=1; //The third rising edge

                SCL=0; //The third falling edge

                DO=1;

                for(i=0;i<8;i++)

                {

                        SCL=0;

                        SCL=1; //Start receiving data from the fourth falling edge

                        value<<=1;

                        if(DO)

                                value++;                                                

                }

                for(i=0;i<8;i++)

                { //Receive verification data

                        value1>>=1;

                        if(DO)

                                value1+=0x80;

                        SCL=1;

                        SCL=0;

                }

                SCL=1;        

                if(value==value1) //Compare with the verification data, return the data if it is correct, otherwise return 0        

                        return value;

        return 0;

[1] [2]
Keywords:MCU Reference address:Design of automatic watering system based on single chip microcomputer

Previous article:Communication program between ESP8266 module and microcontroller (detailed explanation of hardware and software)
Next article:MCU+ADC0832+MQ2 temperature and smoke alarm control

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号