51 MCU – automatic flower watering system (including all codes)

Table of contents

text

aim of design

feature design

required components

Design method

main code

Detailed code

text

aim of design

In life, you will inevitably forget to water your lovely flowers. This design will solve this problem for us.

feature design

It can realize automatic watering of flowers, remote-controlled watering of flowers, key-pressed watering of flowers, and you can view soil moisture, water flow, etc. at any time.

required components

51 [single chip microcomputer] , humidity detection module, PCF8591, LCD1602, water pump, infrared remote control, button, AT24C02

Design method

Based on 51 MCU

Humidity detection module detects humidity

PCF8591 performs AD conversion on the collected humidity

LCD1602 displays the current humidity, water flow size

Set the lower limit of the threshold to control the water pump for automatic watering

Press the button to manually water flowers at close range and adjust the water flow

Infrared remote control for long-distance manual remote control of watering flowers, adjusting the size of water flow

AT24C02 for power-down save

main code

main()
{
    Init_all(); //initialize 
    while ( 1 )
    {
/*********Infrared remote control for watering flowers*************/ 
        if (IRok) //Determine whether the 33 pulse width extraction is complete
        {
            IRcordpro(); //Decode 4 bytes of data according to 33 pulse widths 
            IRok= 0 ; //Clear the pulse width check completion flag and wait for the next pulse width check
        }

        if(IRpro_ok) 
            {
                IR_Work();
                IRpro_ok=0;
            }

/**********Key to water flowers******************/ 
        Key(); //Key to water flowers

/**********Humidity detection + AD conversion *********/    
        EA = 0 ;    
        num = PCF8591Read(3);
        EA = 1;
        delay(5);

        AD_num=ADC_num(num); //AD normalization

/**********Threshold setting + automatic watering*******/       
        VPT=(shi -48 )* 10 +(ge -48 );

        if(AD_num<VPT)
        {
          flag1= 1 ;
        }
        else
        {
          flag1= 0 ;
        }

        if(flag==0)
        {
          switch(flag1)
          {
             case 0: ET1=0;TR1=0;PWM=0; break;
             case 1: ET1=1;TR1=1;break;
          }
        }

        shi1=AD_num/10;

        ge1=AD_num-shi1*10;

/********LCD1602 display ********/      
        LCD1602_Work(); 


/********AT24C02**********/
        AT24_write(2,shi);
        AT24_write(3,ge);
        AT24_write(4,M);
    }
}

Detailed code

Link: https://pan.baidu.com/s/1wbrABMEA1BS28ZBpyF76-w 
Extraction code: 1234

Leave a Comment

Your email address will not be published. Required fields are marked *