ESP8266 NodeMCU smart trash bin system

ESP8266 16-06-26
244 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 ESP8266 NodeMCU Smart Trash Bin System is designed to create an intelligent and contactless waste management solution using IoT technology. Its main objective is to automatically open the trash bin lid when a user approaches, reducing the need for physical contact and improving hygiene. This system demonstrates how embedded systems can be applied to solve real-life problems in a simple and efficient way.

The functioning of the system is based on three main components: the ESP8266 NodeMCU, the HC-SR04 ultrasonic sensor, and the SG90 servo motor. The ultrasonic sensor is responsible for continuously measuring the distance between the bin and any approaching object by sending and receiving ultrasonic waves. This allows the system to detect the presence of a user near the bin in real time.

Once the distance data is collected, the NodeMCU processes the information and compares it with a predefined threshold value. If an object (such as a hand) is detected within a certain range, the microcontroller triggers the servo motor. This decision-making process is the core of the smart behavior of the system.

When the condition is met, the SG90 servo motor automatically rotates to open the lid of the trash bin, allowing the user to dispose of waste without touching the bin. After a short delay, and when no object is detected near the sensor, the system sends another command to the servo motor to return the lid to its closed position.

 

Required Components

1. ESP826 NodeMCU

The ESP8266 NodeMCU Smart Trash Bin System is built using three main electronic components: the ESP8266 NodeMCU, the HC-SR04 ultrasonic sensor, and the SG90 servo motor. Each component plays an important role in making the system smart and automatic.

2. HC-SR04 sensor

HC-SR04

The HC-SR04 ultrasonic sensor is used to detect the presence of a user near the trash bin. It works by sending ultrasonic waves and measuring the time taken for the echo to return after hitting an object. Based on this time, the sensor calculates the distance between the bin and the object. This information is then sent to the NodeMCU, allowing the system to know when someone is close enough to trigger the lid opening.

3. Servo motor

he SG90 servo motor is responsible for the mechanical movement of the trash bin lid. When it receives a signal from the NodeMCU, it rotates to a specific angle to open the lid and allows the user to throw waste inside. After a short delay, it returns to its original position to close the lid automatically. This makes the system fully automated and contactless.

4. Jumper Wires

Jumper wires

Jumper wires are used to establish electrical connections between the ESP8266 NodeMCU, 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 ESP8266 NodeMCU, HC-SR04 ultrasonic sensor, and SG90 servo motor.

 

Circuit Connections of system

 

1- Connection of HC-SR04 sensor to ESP8266 NodeMCU

HC-SR04 sensor ESP8266 NodeMCU
VCC 3V
GND GND
Trig D0
Echo D1

 

2- Connection of servo motor to EESP8266 NodeMCU

Servo motor ESP8266 NodeMCU
red wire (+) 5V
Brown wire (-) GND
Yellow wire (S) D2

 

MicroPython Program for the Smart Trash Bin System

This program controls an automatic smart trash bin using an ESP8266 NodeMCU, 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

This program is designed to create an automatic smart system using an ESP-based microcontroller, an HC-SR04 ultrasonic sensor, and a servo motor. Its main goal is to detect the presence of an object or a hand near the sensor and automatically trigger a mechanical action, such as opening a lid or door.

At the beginning of the program, the required libraries are imported. The HCSR04 library is used to communicate with the ultrasonic sensor, while the Servo library is used to control the servo motor. The time module is also included to manage delays in the system, ensuring smooth and stable operation.

The ultrasonic sensor is then initialized using two GPIO pins: one for triggering the ultrasonic signal and another for receiving the echo. The sensor works by sending an ultrasonic wave and measuring the time it takes for the wave to bounce back after hitting an object. This time is converted into a distance value in centimeters.

Next, the servo motor is initialized and connected to a specific GPIO pin. It is first set to position 0 degrees, which represents the closed or resting state of the system. This ensures that the mechanism starts in a stable and known position before entering the main loop.

Inside the main loop, the program continuously measures the distance between the sensor and any nearby object. This allows the system to react in real time. If the detected distance is less than 5 cm, the program considers that an object or hand is close enough to activate the system.

When this condition is met, the servo motor rotates to 90 degrees, simulating an opening action such as lifting a trash bin lid. The system then keeps this position for 3 seconds to allow the user enough time to interact with it. After this delay, or if no object is detected, the servo returns to its original 0-degree position, closing the lid.

Finally, a short delay is added in each loop iteration to avoid excessive sensor readings and to ensure stable performance. Overall, this program demonstrates a simple but effective automatic detection and 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