Smart Trash Bin Using an ESP32 Board

ESP32 14-06-26
224 0

Tutorial plan

1- Objective of the project

2- Required Components

3- Circuit Connections of system

4- MicroPython Program for the Smart Trash Bin System

 

 

Objective of the project

The objective of this project is to design an intelligent trash bin that automatically opens its lid when a user's hand approaches and closes it after the waste has been disposed of. This touchless operation improves hygiene, convenience, and user comfort while demonstrating the practical application of embedded systems and automation.

The system is built around an ESP32 development board, an HC-SR04 ultrasonic distance sensor, and an SG90 servo motor.

Operation

1- The HC-SR04 ultrasonic sensor continuously measures the distance between the trash bin and any nearby object.

2- When the sensor detects a hand or object within a predefined distance (for example, less than 20 cm), it sends the measured distance to the ESP32 board.

3- The ESP32 processes this information and determines whether the object is close enough to activate the opening mechanism.

4- If the detection condition is satisfied, the ESP32 commands the SG90 servo motor to rotate and open the trash bin lid automatically.

5- After a short delay, allowing the user to dispose of the waste, the ESP32 instructs the servo motor to return to its initial position, closing the lid.

6- The system then resumes monitoring the surroundings, waiting for the next detection event.

 

Required Components

1. Arduino UNO

The ESP32 is a powerful 32-bit microcontroller with built-in Wi-Fi and Bluetooth connectivity. It serves as the brain of the smart trash bin by processing data from the ultrasonic sensor and controlling the servo motor. Thanks to its high processing speed, low power consumption, and support for MicroPython, the ESP32 is widely used in IoT and automation projects.

2. HC-SR04 sensor

HC-SR04

The HC-SR04 is a non-contact distance sensor that measures the distance to an object using ultrasonic sound waves. It emits a high-frequency pulse and measures the time taken for the echo to return after reflecting from an object.

In this project, the sensor detects the presence of a user's hand near the trash bin and sends the distance information to the ESP32.

3. Servo motor

The SG90 is a compact and lightweight micro servo motor capable of rotating approximately 180 degrees. It receives control signals from the ESP32 and converts them into precise angular movements.

In the smart trash bin system, the SG90 servo motor is responsible for automatically opening and closing the lid.

4. Jumper Wires

Jumper wires

Jumper wires are used to establish electrical connections between the ESP32 board, the HC-SR04 sensor and the servo motor.

5. Breadboard

The breadboard is an essential prototyping tool used to assemble and test electronic circuits without soldering. In the smart trash bin system, it plays a key role in connecting and organizing the components such as the ESP32 board, HC-SR04 ultrasonic sensor, and SG90 servo motor.

 

Circuit Connections of system

 

1- Connection of HC-SR04 sensor to ESP32 board

HC-SR04 sensor ESP32 board
VCC 3V
GND GND
Trig GPIO 23
Echo GPIO 22

 

2- Connection of servo motor to ESP32 board

Servo motor ESP32 board
red wire (+) 5V
Brown wire (-) GND
Yellow wire (S) GPIO 21

 

MicroPython Program for the Smart Trash Bin System

This program controls an automatic smart trash bin using an ESP32 board, an HC-SR04 ultrasonic sensor, and an SG90 servo motor.

You must install this library : hc-sr04 for HC-SR04 sensor

Explanation of the program

At startup, the ESP32 board initializes serial communication and sets the servomotor to the closed position (0°). The ultrasonic sensor continuously measures the distance between the trash bin and any nearby object.

When a hand or an object is detected at a distance of less than 3 cm, the ESP32 board sends a command to the SG90 servomotor to rotate to 90°, automatically opening the lid of the trash bin. The lid remains open for 3 seconds to allow the user to dispose of waste.

If no object is detected within the specified distance, the servomotor returns to 0°, keeping the lid closed. The process is repeated continuously, allowing the trash bin to operate automatically without physical contact.

This program provides a simple and hygienic solution for automatic waste disposal by combining distance detection and servo motor control.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

Pictures of the articles

Robotic site created by Mohamed Ali Haj Salah - Teacher info