Intelligent flowerpot design based on 51 microcontroller

Publisher:知识的海洋Latest update time:2024-03-18 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Item name:

Intelligent flowerpot design based on microcontroller


Microcontroller: STC89C52

Function:

1. Display the temperature and humidity of the soil in the flower pot and the light intensity outside the flower pot through the display screen;

2. Use the buttons to switch the display interface and set the minimum soil temperature value, minimum humidity value, light intensity value outside the flowerpot, infusion countdown, and soil loosening countdown;

3. Detect soil moisture through soil moisture sensor and soil temperature through DS18B20;

4. Control the heating plate, water pump, infusion, and fill light through relays;

5. Realize soil loosening through stepper motor;

wKgaomTH5tqAV4B0AAQ1lveAWqA823.png

Part of the program:

#include "main.h"

#include "lcd1602.h"

#include "key.h"

#include "ds18b20.h"

#include "adc.h"

#include "motor.h"

#include "timer.h"



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

Variable definitions

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

uchar key_num = 0; //key scan flag

uchar flag_display = 0; //Display mode flag bit

bit flag_display_cut = 0; //Switch interface flag bit

uint time_num = 0; //10ms count variable

uint temp_value = 0; //Temperature value

uchar temp_min = 10; //Minimum temperature value

uint humi_value = 0; //Humidity value

uchar humi_min = 30; //Minimum humidity value

uint light_value = 0; //Light intensity value

uchar light_min = 50; //Minimum light intensity value

uchar time_songtu = 0; // loosening time

uint time_minus_songtu = 0; //Loose soil countdown time

uchar time_shuye = 0; //Infusion time

uint time_minus_shuye = 0; //Infusion countdown time

extern bit flag_songtu_begin; //Songtu start flag bit

extern bit flag_songtu_finish; //Songtu completion flag bit

extern bit flag_shuye_begin; //Infusion start flag bit

extern bit flag_shuye_finish; //Infusion completion flag bit



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

function declaration

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

void Delay_function(uint x); //Delay function

void Key_function(void); //Key function

void Monitor_function(void); //Monitoring function

void Display_function(void); //Display function

void Manage_function(void); //processing function



/****

******* Main function

*****/

void main()

{

Lcd1602_Init(); //LCD1602 initialization

Delay_function(50);

lcd1602_clean(); //Clear screen

Delay_function(50);

Ds18b20_Init(); //DS18B20 initialization

Delay_function(50);

Timer0_Init(); //Initialize timer 0

Delay_function(50);


while(1)

{

Key_function(); //Key function

Monitor_function(); //Monitoring function

Display_function(); //Display function

Manage_function(); //processing function


Delay_function(10); //Delay 10ms

time_num++; //10ms interval timing variable +1

if(time_num >= 5000) //The timer accumulates to 5000, and then starts accumulating from 0 again

{

time_num = 0;

}

}

}


/****

******* Delay x ms function

*****/

void Delay_function(uint x)

{

uint m,n;

for(m=x;m>0;m--)

for(n=110;n>0;n--);

}


/****

*******Key function

*****/

void Key_function(void)

{

key_num = Chiclet_Keyboard_Scan(0); //Key scan

if(key_num != 0) //A key is pressed

{

switch(key_num)

{

case 1: //Button 1, switch interface

flag_display++;

if(flag_display >= 6) //A total of 6 interfaces

flag_display = 0;


lcd1602_clean(); //Click once to clear the screen once

break;


case 2:

switch(flag_display)

{

case 0: //When the interface is 0, manually loosen the soil

Motor_Foreward();

break;


case 1: //When the interface is 1, modify the minimum temperature value +1

if(temp_min < 99)

temp_min++;

break;

case 2: //When the interface is 2, modify the minimum humidity value +1

if(humi_min < 99)

humi_min++;

break;

case 3: //When the interface is 3, modify the minimum lighting value +1

if(light_min < 99)

light_min++;

break;

case 4: //When the interface is 4, modify the loosening time +1

time_songtu++;

time_minus_songtu = time_songtu*60;

break;

case 5: //When the interface is 5, modify the infusion time +1

time_shuye++;

time_minus_shuye = time_shuye*60;

break;


default:

break;

}

break;

case 3: //Button 3

switch(flag_display)

{

case 0: //When the interface is 0, manual infusion

RELAY_SHUYE = 0; //Close the infusion relay and start infusion

Delay_function(3000); //Infusion for three seconds

RELAY_SHUYE = 1; //Disconnect the infusion relay and stop the infusion

break;


case 1: //When the interface is 1, modify the minimum temperature value -1

if(temp_min > 0)

temp_min--;

break;

case 2: //When the interface is 2, modify the minimum humidity value -1

if(humi_min > 0)

humi_min--;

break;

case 3: //When the interface is 3, modify the minimum lighting value to -1

if(light_min > 0)

light_min--;

break;

case 4: //When the interface is 4, modify the loosening time by -1

if(time_songtu > 0)

{

time_songtu--;

time_minus_songtu = time_songtu*60;

}

break;

case 5: //When the interface is 5, modify the infusion time by -1

if(time_shuye > 0)

{

time_shuye--;

time_minus_shuye = time_shuye*60;

}

break;


default:

break;

}

break;

case 4: //Button 4, switch interface

flag_display_cut = ~flag_display_cut;

lcd1602_clean(); //Click once to clear the screen once

break;


default:

break;

}

}

}

wKgZomTH5tuACJthAAJgjJJ9BdU096.png


wKgZomTH5tyASY-JAAZ65dpYf3o323.png


Reference address:Intelligent flowerpot design based on 51 microcontroller

Previous article:Simple clock design based on 51 microcontroller
Next article:Summary of issues related to crystal oscillators for 51 microcontrollers

Recommended ReadingLatest update time:2024-11-16 12:02

A must-read for beginners (STC89C52) A simple implementation of a single-chip Bluetooth four-wheeled car that can track and avoid obstacles
1. Material selection            1. L289 drive motor x2 2.1.5V battery (you can buy rechargeable batteries, I have used dozens of batteries!!!) I use 8 1.5v batteries to form a 12v battery to power 4 motors separately, and another 3 1.5v batteries to power the microcontroller. 4.5v is similar to 5v. 3. Base plate plus
[Microcontroller]
STC89C52RC MCU + Serial Port + Infrared Control 16-channel Servo Program
There is only a program to control 16-channel servos. I am posting it here for reference. The servos can be controlled via the serial port or infrared. The microcontroller source program is as follows: #include "PCA9685_TJ.h" #include stdio.h #include math.h /*Instructions for use:         In the main program  
[Microcontroller]
STC89C52RC MCU + Serial Port + Infrared Control 16-channel Servo Program
Design of electronic code lock with STC89C52 microcontroller as the core
introduction Electronic code lock is a commonly used encryption tool in modern life. It overcomes the shortcomings of mechanical password locks with small passwords and poor security performance, especially the smart electronic password locks with microcontrollers; it not only has the function of an electronic passwor
[Microcontroller]
Design of electronic code lock with STC89C52 microcontroller as the core
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号