Single-chip microcomputer design Garbage classification system design based on single-chip microcomputer

Summary

This article designs an intelligent garbage classification and identification garbage bin control system based on STC89C52RC. At present, the style and structure of trash cans are relatively simple and cannot perform the role of classification and recycling well. Moreover, disadvantages such as mosquito and fly breeding, sewage spillage, and odors are also exposed during use, which has a serious impact on people’s lives and the environment. Therefore, it is important to design an intelligent garbage classification and identification bin control system that integrates multiple functions. The system is mainly composed of functional modules such as relay drive circuit, infrared sensing module, metal detection and humidity detection module.
With metal detection composed of cmos digital integrated circuit, RPR220 infrared sensor, HC-SR04 ultrasonic monitoring and STC89C52 microcontroller as the core, distance information is collected through the sensor. LCD1602 displays the current trash can status. If someone puts garbage in the infrared sensor, the humidity of Sensors and cmos six-inverter digital integrated circuit metal sensors are used for inspection. This system solves the problem of people using their hands to open the lid that is covered with many bacteria. The relay simulates the control to open and close the trash can. It detects that someone is approaching and automatically opens the lid after leaving. Automatically shuts down. If metal, wet garbage or other different relays are detected, the simulation will be opened to sort the garbage. This design has the function of garbage classification, and has found a feasible solution to the current environmental garbage pollution problem by garbage classification.

Keywords: microcontroller; metal detection; infrared sensor; trash can; ultrasonic

1. Function introduction

This design chooses to use STC89C52 microcontroller as the core component. The main functions include: intelligent lid opening, full alarm, and specific classification of garbage types. In the development process of the garbage classification system, the reliability and cost of the system design run through the entire development process [4]. While a well-designed system meets requirements, it also needs applicability. When the system can operate effectively, consider the practicality, ease of operation, and scalability of the design system. If the above functions are implemented, it will be more convenient for users to throw away garbage. At the same time, garbage and people can also be initially isolated, which can effectively prevent bacteria from growing in the trash can.
After the system functions are confirmed, the functions need to be further refined. Are there correlations and special connections between functions? Select key components and determine the plan based on the functions implemented. For example, the main key components in this article are MCU and peripherals. What kind of architectural model and key technologies should be selected based on the system functions for the circuit minimum system, power conversion circuit, and signal acquisition and processing circuit.
feature design:
1) Ultrasonic detection of overfilling level, the first level for measuring obstacles below 8 cm, the second level for 8-16 cm, and the fifth level for obstacles up to 48 cm.
2) LCD1602 displays the current trash can status and related parameter information.
3) If someone is throwing garbage, the infrared sensor will detect the current bunker. When it detects someone throwing away garbage, the sensor starts detecting and the LCD counts down for 6 seconds.
4) The humidity detection module is responsible for detecting whether the garbage is wet garbage. If it is wet garbage, relay No. 2 will be turned on for 5 seconds and then automatically closed.
5) The metal detection module detects whether it is metal type.
6) When an item is detected as metal waste, the system will alarm through a buzzer. If it is not detected as wet garbage or metal garbage, the system determines it as dry garbage, and at the same time, the No. 1 relay is turned off automatically after 5 seconds [5].
7) When it is detected that the garbage is metal garbage, you need to use the button module to turn on the No. 3 relay for forced recycling to prevent other unrelated personnel from turning over and causing garbage and pollution.
8) When garbage with different attributes is detected, a single device provides a low level to the relay. At this time, the relay will be opened to simulate the garbage input operation.

2. System simulation and debugging

5.1 System debugging environment setup

5.1.1 Things to note when setting up a test environment

(1) The test environment of the hardware system should be set up to ensure that the components are not too close or too far when connected to the universal board. The filter capacity should be as close as possible to the power supply to make the power output more stable. The same components can maintain functional integrity and reduce resource consumption as much as possible.
(2) When welding, be sure to pay attention to the temperature and try not to weld repeatedly.
5.1.2 System debugging environment setup
After the design of the hardware system and software system is completed, the objects designed based on the system hardware equipment are welded on the universal board. After the design system meets the design requirements, the PCB is sampled and welded. The hardware debugging environment mainly includes welding objects and functional objects. , power module, oscilloscope, multimeter. Physical welders include the following aspects:
(1) Determine the components needed to classify the functional modules in the design of this project, install the components used at the positions on the design drawing, and use a multimeter to detect the polarity of the diode, the five-color ring resistance and the capacitance. value.
(2) Determine the overall structural layout of the system and create a template. According to the design requirements, the minimum system of the single-chip microcomputer uses the input signal near the bottom of the board in the middle and vertical directions. The top of the board is the output signal terminal. The horizontal left side is the signal input terminal, the middle is the signal processing terminal, and the right side is the signal output terminal.
(3) After the layout of the garbage classification system is completed, insert the components of each functional module into the board in sequence. After observing whether the overall configuration is reasonable or unreasonable, recheck whether the panel meets the requirements before welding.
(4) Before using the soldering iron, first fix the components on the board, use a knife to cut off the excessively long part of the electrical components, and finally weld the circuit lines of the system according to the electrical relationship with the soldering iron. After welding, further inspection is mainly Check whether there are incorrect solder joints, missing components, short circuits, electrical relationships, functional module circuits, etc.

Figure 5.1 No power display

Figure 5.2 Power-on display
After powering on the circuit board, each module starts to work. The ultrasonic ranging module monitors the garbage overflow status in real time through the LCD display module and displays the current garbage overflow level.

Figure 5.3 Trash can overflow display
When the ultrasonic ranging module detects that the trash can is full, the program stops working and displays “Trash full”.

Figure 5.4 Working of infrared sensing module
When the infrared sensing module senses that someone is approaching to throw garbage, it starts to detect the current type of garbage and counts for 6 seconds.

Figure 5.5 Detecting garbage as dry garbage

Figure 5.6 Detecting garbage as wet garbage
During the detection process, if the humidity detection module detects that the current garbage is wet garbage, the wet garbage bin in the middle will automatically open, and the opening time is 5 seconds. If wet garbage or metal garbage is not detected before the timer expires, the dry garbage bin will automatically open when the timer expires, and the opening time is also 5 seconds.

Figure 5.7 Detection of garbage as metal garbage
If metal garbage is detected during the detection process, the buzzer will alarm and you need to manually press the recycling button to open the metal garbage bin for forced recycling to prevent scavengers or other unrelated persons from turning over the garbage and causing pollution.

3. PCB diagram

4. Circuit diagram

Core program

#include <reg52.h> //Call the microcontroller header file #include <intrins.h>
#include "lcd1602.h"
#define uchar unsigned char //Unsigned character type Macro definition variable range 0~255 #define uint unsigned int //Unsigned
Integer macro definition variable range 0~65535
//Button pin definition
sbit KEY1 = P1^3;//Metal garbage button sbit ShiDu = P1^1;//Humidity detection sbit HW = P1^2;//Infrared probe
sbit TRIG = P2^1;//Ultrasonic transmitter sbit ECHO = P2^0;//Ultrasonic receive sbit Relay1 = P3^5;//Dry garbage relay sbit Relay2 = P3^6;//Wet garbage relay
sbit Relay3 = P3^7;//Metal garbage relay float distance; //Distance
bit openFlag = 0;//Open flag bit handleFlag=0;//Processing flag bit shuaxin = 0;//Refresh flag bit Man = 0;//Garbage full flag uchar miao = 0;//Waiting time
uchar Classification=0;//1 is dry garbage, 2 is wet garbage, 3 is metal garbage
//Capacity bar displays array
uchar code lcdTable1[]={0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; uchar code lcdTable2[]= {0x10, 0x18, 0x1F, 0x1F, 0x1F, 0x1F, 0x18, 0x10}; uchar code lcdTable3[]={0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F};
/*------------------------------------------------
The uS delay function contains the input parameter unsigned char t, and has no return value. unsigned char is an unsigned character variable defined, and its value range is 0~255. A 12M crystal oscillator is used here. Please use assembly for accurate delay. The approximate delay length is as follows: T =tx2 + 5uS
----------------------------------------*/
void DelayUs2x(unsigned char t)
{
while(--t);
}
float Get_S(void)
{
long i = 0;
float S; //distance variable
TRIG=1; //The trigger signal is a high-level pulse with a width greater than 10us DelayUs2x(10);
TRIG=0;
while(!ECHO & amp; & amp; i < 300000) i + + ; //wait for high level
TR0=1; i = 0;
while(ECHO & amp; & amp; i < 300000) i + + ; //Wait for low level TR0=0;
S=TH0*256 + TL0; //Get the high 8 bits and the low 8 bits of the timer value and combine them (unit time is us) S=S/58; //Read out in centimeters
TH0=0;
TL0=0; //Clear the value in the timer 0 register return S;
}
/************************Timer 0, timer 1 initialization******************/ void time_init() {
TMOD |= 0X11; //Timer 0, timer 1 working mode 1 TH0=0;
TL0=0;
TH1=0x4c;//Timing 50ms TL1=0x00;
ET0 = 1; //Enable timer 0 interrupt ET1 = 1;
TR1 = 1; //Turn on timing EA = 1; //Turn on total interrupt
}


void keyscan()
{
if(KEY1 == 0 & amp; & amp; Classification==0 & amp; & amp; handleFlag)//Metal junk key pressed
{
delay_ms(10);
if(KEY1 == 0 & amp; & amp; Classification==0 & amp; & amp; handleFlag)
{
while(!KEY1); lcd_write_str(0, 1, " T: s"); Classification=3;
miao = 5; //Relay turns on for 5 seconds openFlag = 1;
handleFlag = 0;
}
}
}
void displayCapacity(uint temp)//Display the status of the container
{
if(temp < 8)//Display 5 cells
{
Lcd_Custom_Char(0, 7, 0, lcdTable1); Lcd_Custom_Char(0, 8, 1, lcdTable1); Lcd_Custom_Char(0, 9, 2, lcdTable1); Lcd_Custom_Char(0, 10, 3, lcdTable1);
Lcd_Custom_Char(0, 11, 4, lcdTable1); Man = 1; //The garbage is full
}
else if(temp >= 8 & amp; & temp <16)//Display 4 cells
{
Lcd_Custom_Char(0,7,0,lcdTable1); Lcd_Custom_Char(0,8,1,lcdTable1); Lcd_Custom_Char(0,9,2,lcdTable1); Lcd_Custom_Char(0,10,3,lcdTable1); Lcd_Custom_Char(0,11, 4, lcdTable3); Man = 0; }
else if(temp >= 16 & amp; & temp <24)//Display 3 cells
{
Lcd_Custom_Char(0,7,0,lcdTable1); Lcd_Custom_Char(0,8,1,lcdTable1); Lcd_Custom_Char(0,9,2,lcdTable1); Lcd_Custom_Char(0,10,3,lcdTable3); Lcd_Custom_Char(0,11, 4, lcdTable3); Man = 0; }
else if(temp >= 24 & amp; & temp <32)//Display 2 cells
{
Lcd_Custom_Char(0,7,0,lcdTable1); Lcd_Custom_Char(0,8,1,lcdTable1); Lcd_Custom_Char(0,9,2,lcdTable3); Lcd_Custom_Char(0,10,3,lcdTable3); Lcd_Custom_Char(0,11, 4, lcdTable3); Man = 0; }
else if(temp >= 32)//display 1 grid
{
Lcd_Custom_Char(0,7,0,lcdTable1); Lcd_Custom_Char(0,8,1,lcdTable3); Lcd_Custom_Char(0,9,2,lcdTable3); Lcd_Custom_Char(0,10,3,lcdTable3); Lcd_Custom_Char(0,11, 4, lcdTable3); Man = 0;
}
}
void main()
{
float temp; //Distance variable time_init();//Timer initialization lcd_init();//1602 initialization lcd_write_str(0, 0, "STATE:
"); lcd_write_str(0, 1, " CLOSE ");
Lcd_Custom_Char(0, 12, 5, lcdTable2); //Display special graphics while(1)


{
if(Man == 0)//Garbage is not full
{
keyscan();//key scan
if(HW == 0 & amp; & amp; Classification==0)//Someone is detected
{
if(handleFlag==0)
{
lcd_write_str(0, 1, "Testing... T: s"); handleFlag = 1;
miao = 6; //The waiting time is assigned a value of 6 seconds
}
}
if(handleFlag==0 & amp; & amp; openFlag==0)lcd_write_str(0, 1, "CLOSE");//Display is closed, no one will throw garbage else
//Under detection
{
if(ShiDu == 1 & amp; & amp; handleFlag)//Wet garbage detected
{
Classification=2; handleFlag = 0;
openFlag = 1;
miao = 5; //Relay turns on for 5 seconds
}
lcd_write_char(14, 1, miao + 0x30); //Display seconds
}
switch(Classification)//Display junk information
{
case(1):
lcd_write_str(0, 1, "Dry garbage");Relay1=0;break;//Dry garbage case(2):
lcd_write_str(0, 1, "Wet garbage");Relay2=0;break;//Wet garbage case(3):
lcd_write_str(0,1,"Metal waste");Relay3=0;break;//Metal waste default:Relay1=1;Relay2=1;Relay3=1;
break;
}
}
else
{
lcd_write_str(0, 1, "Trash full! ");//Shows that the trash can is full Relay1=1;Relay2=1;Relay3=1;//All relays are turned off
Classification=0;
handleFlag = 0;
openFlag = 0;
miao = 0;
}
if(shuaxin == 1)//Read the data in about 100ms
{
shuaxin = 0;
temp = Get_S();//Get distance
distance = temp > 400? 400 : temp;//The maximum distance is 400cm displayCapacity(((uint)(distance)));//Capacity bar
Display based on distance
}
}
}
void zd0() interrupt 1 using 0 //T0 interrupt is used for counter overflow and exceeding the ranging range
{
ECHO = 0; //Interrupt overflow flag
}
void zd1() interrupt 3
{
static uchar cnt=0,cnt1=0; TH1=0x4c;
TL1=0x00;
if(cnt + + >= 1)//100ms
{
cnt = 0;
shuaxin = 1;
}
if(cnt1 + + >= 20)//1s
{
cnt1 = 0;
if(miao > 0)
{
miao --;
}
else
{
if(openFlag == 1)
{
openFlag = 0; //5 seconds are up, close Classification=0;
}
if(handleFlag == 1 & amp; & amp; Classification==0)//It is neither wet garbage nor metal garbage, indicating that it is dry garbage
{
Classification=1;
miao = 5; //Relay turns on for 5 seconds handleFlag = 0;
openFlag = 1;
}
}
}

4. Conclusion

This design fully considers the environment and recycling facilities characteristics of the garbage recycling area in the city, comprehensively considers the design principles of public facilities, further enriches the functions of urban trash cans, and is more intelligent in design than traditional trash cans. And humane. The “smart city” of the future will have a complete set of supporting facilities of the “intelligent garbage classification system”. By then, garbage disposal will no longer be a headache, but a clean and convenient effort.
Compared with the current “garbage dumping facilities”, we can rely on technology to eliminate the source of pollution and solve a major problem of garbage recycling. The previous “big pot” garbage collection phenomenon in the community no longer occurs. The identification system automatically classifies recyclable waste (dry waste), non-recyclable waste (wet waste) and hazardous waste (metal waste), further improving the scientific recycling of domestic waste classification.
The classification of domestic waste treatment tests the environmental awareness and resource awareness from manufacturers to consumers. Only by enhancing environmental awareness in all aspects can it be implemented smoothly. Compared with developed countries, we have a longer road to go. However, we believe that this “smart garbage disposal system”, although it does not use sophisticated technological means in terms of implementation, will play a major role in the construction of smart cities and environmentally friendly cities by virtue of its ease of implementation and promotion. . The ultimate “zero waste” and “zero pollution”.

5. Article directory

Table of contents
Chapter 1 Introduction 1
1.1 Research background 1
1.2 Current situation at home and abroad 1
1.3 Purpose and significance of the research 3
Chapter 2 Overall System Design 4
2.1 System solution selection 4
2.2 System function analysis 5
Chapter 3 System Hardware Circuit Design 7
3.1 Introduction to STC89C52RC microcontroller 7
3.2 Reset circuit design 8
3.3 Crystal oscillator circuit design 8
3.4 Humidity sensing module design 9
3.5 Infrared sensing module design 10
3.6 Relay drive module design 11
3.7 Metal detection module design 12
3.8 Power module 14
3.9 LCD chip 14
3.10 Ultrasonic ranging module 15
3.11 Button module 16
3.12 Alarm module 17
Chapter 4 System Software Design 19
4.1 System software development environment and tools 19
4.1.1 Software development environment 19
4.1.2 Software development tools 19
4.2 Software workflow 19
4.3 Sensor module programming 20
4.3.1 Ultrasonic ranging software design 20
4.3.2 Metal detection program design 22
4.3.3 Button module programming 23
Chapter 5 System Simulation and Debugging 25
5.1 System debugging environment setup 25
5.1.1 Things to note when setting up a test environment 25
5.1.2 System debugging environment setup 25
5.2 Debugging of garbage classification system 29
5.2.1 System software debugging 29
5.2.2 System hardware debugging 29
Chapter 6 Conclusion and Outlook 31
Reference 32
Acknowledgments 34
Appendix 35