The automatic watering system is designed with 51 single-chip microcomputer + LCD1602 liquid crystal + soil sensor + relay + ADC0832 + water pump.
The three system buttons are: system reset button, setup button, plus button, and minus button.
1. The soil dryness and humidity sensor transmits signals to the microcontroller in real time.
2. Press the button to set the soil dryness and humidity thresholds to achieve dynamic control of soil moisture.
3. The LCD displays soil moisture conditions in real time, and the set thresholds are intuitive and clear.
4. ADC0832 converts the analog signal into a digital signal and transmits it to the microcontroller.
Press the button to adjust the upper and lower limits, LCD1602 displays the soil moisture value in real time and displays the upper and lower limits. When the soil detection sensor detects that the humidity value is lower than the lower limit, the buzzer alarms and drives the water pump to water. When the humidity value is higher than the upper limit, watering stops.
The microcontroller source program is as follows:
#include #include "intrins.h" #define uint unsigned int #define uchar unsigned char #define long unsigned long #define LCDIO P0 //LCD screen data port //ADC0832 pins sbit ADCLK =P1^1; //ADC0832 clock signal sbit GOODBYE =P1^3; //ADC0832 k in sbit ADCS =P1^4; //ADC0832 chip seclect sbit rs=P1^0; //define 1602 RS sbit lcden = P1^2; //define 1602 EN sbit key1=P3^0; //Set sbit key2=P3^1; //add sbit key3=P3^2; //subtraction sbit motor=P3^7; //Relay interface sbit speak=P1^5; //Buzzer interface uchar key; //Set pointer uint RH=400,RL=200; // water level upper and lower limits float temp_f; head temp; fly v; float count,s1num; uchar code table[]= " moisture: "; uchar code table1[]="RH: % "; uchar getdata; //Get the value converted by ADC /*********************************************/ void delay(uint z) //delay { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } /**********************************************/ void write_com(uchar com) { rs=0; // rd=0; lcden=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; } /*********************************************/ void write_date(uchar date) { rs=1; // rd=0; lcden=0; P0=date; delay(5); lcden=1; delay(5); lcden=0; } void lcdinit() { lcden=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); } /***********************************************/ void init() { flying number; for(num=0;num<15;num++) { write_date(table[num]); delay(5); } write_com(0x80+0x40); for(num=0;num<15;num++) { write_date(table1[num]); delay(5); } } //****************************************************************************/ /************ Read ADC0832 function ************/ //Collect and return /**************************************************************************** Function: AD conversion subroutine Entry parameter: CH (if reading CH0, the channel value is 0x01, if reading CH1, the channel value is 0x03) Export parameter: adval ****************************************************************************/ uchar Adc0832() //AD conversion, return result { flying i; fly dat=0; ADCLK=0; GOODBYE=1; ADCS=0; //Pull CS end low ADCLK=1; ADCLK=0; //Pull down the CLK end to form a falling edge 1 ADDIO=1; //Specify whether the conversion channel is CH1 or CH2, specify the value bit and 0x1, and take the value of the last bit ADCLK=1; ADCLK=0; //Pull down the CLK end to form a falling edge 2 ADDIO=0; //Shift the specified value right by one digit, and then take the value of the last digit ADCLK=1; ADCLK=0; //Pull down the CLK end to form a falling edge 3 GOODBYE=1; for(i=0;i<8;i++) { ADCLK=1; ADCLK=0; //Form a clock pulse if(GOODBYE) dat|= 0x80>>i; //Receive data } ADCS=1; //Pull CS terminal low ADCLK=1; ADDIO=1; //Pull up the data terminal and return to the initial state return(that); //return that } /***************************************************************************/ /********************************************************/ void displayRH() //lower limit display {write_com(0xc0+3); write_date(RH/100%10+0x30); //upper limit hundreds digit write_date(RH/10%10+0x30); //Upper limit 10 digits //write_date('.'); //write_date(RH%10+0x30); } void displayRL() //lower limit display {write_com(0xca); write_date('R'); write_date('L'); write_date(':'); write_date(RL/100%10+0x30);//lower limit hundreds write_date(RL/10%10+0x30);//lower limit 10 digits write_date('%'); } /**************************************************/ /********************************************************/ void keyscan() //key processing {bit kk1=0,kk2=0; if(key1==0) {delay(30); while(key1==0); if(key>=2) {key=0; } else {key++; } switch(key) {speak=1;kk2=motor;motor=1; case 1:{write_com(0x0f);write_com(0xce); // cursor flashes while(key1!=0) //Wait for the key to be released { if(key2==0) //key2 is pressed {delay(30); //Key delay to eliminate jitter if(key2==0) //Confirm key2 is pressed { while(key2==0); //Wait for release if(RL>=998) {RL=999; //The maximum lower limit of RL is set to 99 } else {RL+=10; //RL加1 } } displayRL(); //Call RL lower limit display function write_com(0xce); } if(key3==0) //key3 is pressed {delay(30); //Key delay to eliminate jitter if(key3==0) //Confirm key3 is pressed { while(key3==0); //Wait for key3 to be released if(RL<=1) //RL is set to 1 at minimum {RL=0; } else {RL-=10; //RL lower limit minus 1 } } displayRL(); //Call RL lower limit display function write_com(0xce); } }while(key1==0); } case 2:{write_com(0x0f);write_com(0xc4); //RH setting data, cursor flashing while(key1==1) { if(key2==0) //key2 is pressed {delay(30); //Key delay to eliminate jitter if(key2==0) //Confirm key2 is pressed { while(key2==0); //Wait for release if(RH>=998) //RH is set to 99 at most {RH=999; } else {RH+=10; //RH加1 } } displayRH(); //RH upper limit display function write_com(0xc4); } if(key3==0) //key3 is pressed {delay(30); //Key delay to eliminate jitter if(key3==0) //Confirm the press { while(key3==0);//Wait for release if(RH<=1) //RH minimum setting is 1 {RH=0; } else {RH-=10; //RH minus 1 } } displayRH(); //Call RH display function write_com(0xc4); } } while(key1==0); } case 0:{write_com(0x0c); motor=kk2; break;} } } } /**************************************************/ void Conut(void) //Soil detection data conversion { v=Adc0832(); temp=v; temp_f=temp*9.90/2.55; temp=temp_f; temp=1000-temp; write_com(0x80+10); write_date(temp/100%10+0x30);//thousands write_date(temp/10%10+0x30);//hundreds digit write_date('.'); write_date(temp%10+0x30); write_date('%');//display sign bit } /********************************************************/ void main(void) { lcdinit(); heat(); displayRH(); //Display upper limit displayRL(); //Display lower limit delay(50); //Start waiting, wait for LCD to enter working state delay(50); //delay for a moment (optional) delay(50); //delay delay(50); Conut(); //Display function delay(150); while(1) { Conut(); //Display current humidity keyscan(); if(temp>RH) //If the humidity is greater than the upper limit, stop watering {motor=1; //Turn off the relay } else if(temp } if(temp delay(150); //delay speak=1; } keyscan(); //key detection delay(150); //delay 50MS } }
Previous article:STC12C5A60S2 MCU AD sampling program and register explanation
Next article:51 MCU PID motor speed control Proteus simulation and source code
Recommended ReadingLatest update time:2024-11-15 15:15
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- In the LLC circuit, when the operating frequency fs is less than the resonant frequency fr, there is a problem with the secondary rectifier diode voltage waveform.
- bq40z50 series thermistor resistance coefficient calculator
- How should a fast charging decoy be evaluated?
- "Python Programming: From Beginners to Practice"
- The hierarchical wordline structure can improve the SRAM read and write speed and reduce the circuit dynamic power consumption
- What is your career plan for electronic engineering?
- The Differences and Working Principles of Digital Oscilloscopes and Analog Oscilloscopes
- TMS320F28335 ADC Learning Notes
- RGB Hexagonal Keyboard
- 3D Printer Project - Introduction to the Main Modules of STM32F750 (Part 4)