The objective of this project is to design and build a smart trash can that opens its lid automatically when a hand or an object approaches it.
The system uses a Micro:bit board, an HC-SR04 ultrasonic sensor, and a servo motor to provide a touch-free and hygienic waste disposal solution.
Functioning
The HC-SR04 ultrasonic sensor continuously measures the distance between the trash can and nearby objects.
When a hand or an object is detected within a predefined distance, the sensor sends the distance information to the Micro:bit board.
The Micro:bit processes the received data and determines whether the lid should be opened.
If an object is detected nearby, the Micro:bit sends a control signal to the servo motor.
The servo motor rotates and opens the lid of the trash can automatically.
After a short delay, when no object is detected, the servo motor returns to its initial position, closing the lid.
This automatic system improves hygiene, reduces physical contact with the trash can, and demonstrates the practical use of sensors and actuators in robotics and smart-home applications.
1. Micro:bit board

The Micro:bit is a programmable microcontroller board that acts as the brain of the smart trash can. It receives data from the ultrasonic sensor, processes the information, and controls the servo motor to open and close the lid automatically.
2. Micro:bit GPIO Extension Board

The Micro:bit GPIO extension board simplifies the connection between the Micro:bit board and external electronic components. It provides easy access to GPIO pins, power supply pins, and communication interfaces, making circuit assembly more convenient and reliable.
3. HC-SR04 sensor

The HC-SR04 is an ultrasonic distance sensor used to detect the presence of a hand or an object near the trash can. It measures the distance by sending ultrasonic waves and receiving their echoes.
4. Servo motor

The SG90 servo motor is responsible for moving the trash can lid. It receives control signals from the Micro:bit and rotates to a specific angle to open the lid, then returns to its original position to close it.
5. Jumper Wires

Jumper wires are used to establish electrical connections between the Micro:bit, the HC-SR04 sensor and the servo motor.
6. Breadboard

The breadboard is used to connect the electronic components without soldering. It simplifies circuit assembly and testing.


1- Connection of HC-SR04 sensor to Micro:bit
| HC-SR04 sensor | Micro:bit board |
|---|---|
| VCC | 5V of Micro:bit GPIO Extension Board |
| GND | GND |
| Trig | P2 |
| Echo | P1 |
2- Connection of servo motor to Micro:bit
| Servo motor | Micro:bit board |
|---|---|
| red wire (+) | 5V |
| Brown wire (-) | GND |
| Yellow wire (S) | P0 |
1- Open the MakeCode editor at https://makecode.microbit.org/.
2- Create a new project by clicking on "New Project."
3- Add the HC-SR04 extension:
Look for "Extensions" and click on it.

In the search box, type "sonar" to find the HC-SR04 extension.

4- Go to advanced :

5- Go to Pin and choose 'servo write pinP0 to 180' instruction :

This MakeCode program controls the automatic opening and closing of a smart trash can using an ultrasonic sensor and a servo motor.

Explanation of the program
1- At startup, the servo motor is set to 0°, which keeps the bin lid closed.

2- The ultrasonic sensor continuously measures the distance between the bin and a nearby object (such as a hand).

3- When an object is detected at a distance of less than 3 cm, the servo motor rotates to 90°:This action opens the bin lid which remains open for 3 seconds.

4- If no object is detected within 3 cm, the servo motor returns to 0°, causing the lid to close automatically.

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.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
Robotic site created by Mohamed Ali Haj Salah - Teacher info