Smart Dustbin Using ESP8266, Ultrasonic Sensor, Servo & KiwisIoT
by Varun_Prasad_07 in Circuits > Arduino
5 Views, 0 Favorites, 0 Comments
Smart Dustbin Using ESP8266, Ultrasonic Sensor, Servo & KiwisIoT
A conventional dustbin requires users to touch the lid, which can be inconvenient and unhygienic. This project solves that problem by building a touch-free Smart Dustbin using an ESP8266 NodeMCU, HC-SR04 ultrasonic sensor, SG90 servo motor, 16×2 I2C LCD, LED, and the KiwisIoT IoT platform.
The ultrasonic sensor detects when a hand or object comes close to the dustbin. When the detected distance is below 15 cm, the ESP8266 commands the servo motor to open the lid automatically. The LED indicates the open/closed state, while the LCD displays the measured distance and current dustbin status.
The ESP8266 also sends the dustbin status to KiwisIoT over Wi-Fi, allowing the status to be monitored remotely through a KiwisIoT dashboard.
This project demonstrates a practical combination of embedded systems, automation, servo control, ultrasonic sensing, LCD interfacing, Wi-Fi, and IoT cloud monitoring using KiwisIoT.
Supplies
Hardware Components Required
ESP8266 NodeMCU → 1
HC-SR04 Ultrasonic Sensor → 1
SG90 Servo Motor → 1
16×2 I2C LCD Display → 1
LED → 1
220Ω Resistor → 1
Breadboard → 1
Jumper Wires → As Required
USB Cable → 1
5V Power Supply / Power Bank → 1
Dustbin Container → 1
Wi-Fi Connection → Required
Software Components Required
Arduino IDE
ESP8266 Board Package
Required Arduino Libraries
Install these libraries through the Arduino IDE Library Manager:
KiwisIoT → Mugeshwaran R
Servo → Arduino
LiquidCrystal_I2C → Frank de Brabander
Wire → Arduino
The ESP8266 Wi-Fi functionality is provided through the ESP8266 board package.
Hardware Connection
Step 1 – Hardware Connections
Connect the components to the ESP8266 NodeMCU as shown below. Make sure all connections are secure before powering the circuit.
1. HC-SR04 Ultrasonic Sensor
The ultrasonic sensor detects the distance between the user's hand and the dustbin lid.
VCC → 5V / VIN
GND → GND
TRIG → D5
ECHO → D6 through a voltage divider / level shifter
Important: The HC-SR04 ECHO pin can output a 5V logic signal, while the ESP8266 GPIO is a 3.3V logic device. Use a suitable voltage divider or level shifter between ECHO and D6.
2. SG90 Servo Motor
The servo motor is responsible for opening and closing the dustbin lid.
Red Wire (VCC) → External 5V Supply
Brown Wire (GND) → GND
Orange Wire (Signal) → D7
Important: Do not power the SG90 from the ESP8266 3.3V pin. Use a suitable 5V supply capable of providing the servo's required current. Connect the external supply's GND to the ESP8266 GND.
3. LED
The LED provides a visual indication of the dustbin status.
LED Anode (+) → 220Ω Resistor → D4
LED Cathode (−) → GND
LED ON → Dustbin OPEN
LED OFF → Dustbin CLOSED
4. 16×2 I2C LCD
The LCD displays the measured distance and dustbin status.
VCC → VIN / 5V
GND → GND
SDA → D2
SCL → D1
The code uses the common I2C address:
If the LCD does not work, check its I2C address. Some modules use 0x3F instead of 0x27.
5. Common Ground
A common ground is essential for reliable operation.
Connect the grounds of:
ESP8266 → GND
HC-SR04 → GND
Servo Power Supply → GND
LCD → GND
LED → GND
All components should share the same ground reference.
Complete Connection Summary
HC-SR04
→ VCC → 5V/VIN
→ GND → GND
→ TRIG → D5
→ ECHO → Voltage Divider → D6
SG90 Servo
→ VCC → External 5V
→ GND → Common GND
→ Signal → D7
LED
→ Anode → 220Ω → D4
→ Cathode → GND
16×2 I2C LCD
→ VCC → VIN/5V
→ GND → GND
→ SDA → D2
→ SCL → D1
Hardware Flow
HC-SR04 → ESP8266 → Servo
HC-SR04 → ESP8266 → LED
HC-SR04 → ESP8266 → LCD
ESP8266 → Wi-Fi → KiwisIoT
This wiring gives the ESP8266 control over the automatic lid while KiwisIoT handles the remote monitoring.
Upload the Program
In this step, we will prepare the Arduino IDE, install the required ESP8266 board package and libraries, configure the Wi-Fi and KiwisIoT details, and upload the program to the ESP8266 NodeMCU.
Install ESP8266 Board Package
Open Arduino IDE and go to:
File → Preferences
Add the following URL under Additional Boards Manager URLs:
Then go to:
Tools → Board → Boards Manager
Search for ESP8266 and install:
ESP8266 by ESP8266 Community
After installation, select:
Tools → Board → ESP8266 Boards → NodeMCU 1.0 (ESP-12E Module)
Connect the ESP8266 NodeMCU to your computer using a USB cable and select the correct COM port from:
Tools → Port
Install Required Libraries
Open:
Sketch → Include Library → Manage Libraries
Install the following libraries:
- KiwisIoT — Mugeshwaran R
- Servo — Arduino
- LiquidCrystal_I2C — Frank de Brabander
- Wire — Arduino
The ESP8266WiFi library is included with the ESP8266 board package.
Configure Wi-Fi and KiwisIoT
Before uploading the program, replace the following values:
Replace:
Your_WiFi_Name → Your Wi-Fi network name
Your_WiFi_Password → Your Wi-Fi password
dash_xxxxxxxxxxxx → Your KiwisIoT Topic ID
The Topic ID must match the panel created in KiwisIoT.
Upload the Program
Copy and upload the following code to the ESP8266 NodeMCU:
Program Functions
The program performs the following operations:
- Connects the ESP8266 to Wi-Fi and KiwisIoT.
- Reads the distance using the HC-SR04 ultrasonic sensor.
- Opens the dustbin lid when an object is detected within 15 cm.
- Controls the SG90 servo motor.
- Turns the LED ON when the dustbin is open.
- Displays distance and dustbin status on the LCD.
- Sends dustbin status to the KiwisIoT dashboard.
- Updates the system every 2 seconds.
- Displays live distance and status information on the Serial Monitor.
After uploading the program successfully, the ESP8266 is ready to operate the Smart Dustbin and communicate with the KiwisIoT cloud platform.
Set Up the KiwisIoT Dashboard
After uploading the program to the ESP8266, the next step is to create a KiwisIoT dashboard for monitoring the Smart Dustbin status.
3.1 Create a KiwisIoT Panel
- Open your KiwisIoT account.
- Go to My Panels.
- Click Create New Panel.
- Enter a suitable panel name, such as Smart Dustbin.
- Create the panel.
- Copy the generated Topic ID.
The Topic ID will look similar to:
Update the Topic ID in your Arduino code:
Then upload the code to the ESP8266 again.
3.2 Add Dashboard Widgets
Add widgets to display the Smart Dustbin status.
Use the following channel mapping:
Configure the widgets according to the values sent by the ESP8266:
For example:
3.3 KiwisIoT Monitoring Flow
Once the ESP8266 connects to Wi-Fi and KiwisIoT, the dashboard will start receiving the dustbin status data automatically.
Test and Results
After completing the hardware connections, uploading the program, and configuring the KiwisIoT dashboard, power on the Smart Dustbin and test its operation.
4.1 Automatic Lid Opening
Place your hand or an object within 15 cm of the HC-SR04 ultrasonic sensor.
4.2 Automatic Lid Closing
Move the object away from the sensor beyond 15 cm.
4.3 Expected Output
The 16×2 LCD displays the measured distance and current dustbin status.
Example:
When the object is removed:
The KiwisIoT dashboard also updates the Dustbin Status and LED Status according to the sensor condition.
4.4 Final Result
The Smart Dustbin successfully detects a nearby object using the HC-SR04, automatically opens and closes the lid using the SG90 servo, displays the status on the LCD, indicates the active state using an LED, and sends the status to the KiwisIoT dashboard for remote monitoring.
Conclusion
The Smart Dustbin using ESP8266 provides a simple and practical approach to automatic waste-bin operation. The HC-SR04 detects nearby objects, the SG90 servo automatically opens and closes the lid, and the LCD displays the distance and current status.
The system also uses KiwisIoT to send the dustbin and LED status to an online dashboard, making it possible to monitor the system remotely. This project can be further improved by adding a fill-level monitoring system, buzzer alerts, notifications, and waste-level data logging.
Overall, the project demonstrates how IoT, sensors, and automation can be combined to build a simple smart waste-management system
Frequently Asked Questions (FAQ)
1. What is the purpose of this Smart Dustbin?
The system automatically opens the dustbin lid when an object or hand is detected nearby, reducing the need to touch the bin.
2. Why is an HC-SR04 ultrasonic sensor used?
The HC-SR04 measures the distance between the sensor and a nearby object. The ESP8266 uses this distance to determine when to open or close the lid.
3. At what distance does the lid open?
In this project, the lid opens when the detected object is less than 15 cm from the ultrasonic sensor.
4. Why is a servo motor used?
The SG90 servo provides controlled angular movement to open and close the dustbin lid.
5. Why is KiwisIoT used?
KiwisIoT is used to monitor the dustbin status remotely through an IoT dashboard. The ESP8266 sends the dustbin and LED status to the configured KiwisIoT channels.
6. Can I change the opening distance?
Yes. Change the threshold in the Arduino code:
For example, to open the lid below 20 cm:
7. Can I display the distance on KiwisIoT?
Yes. The project can be extended by sending the measured ultrasonic distance to an additional KiwisIoT channel and displaying it using a suitable widget.
8. Can this project work without Wi-Fi?
Yes. The automatic lid, servo, LED, and LCD functions can work locally. However, the KiwisIoT remote monitoring features require a Wi-Fi connection.
9. Can I use a different servo motor?
Yes. A compatible servo can be used, but make sure its operating voltage and current requirements are suitable for the power supply.
10. Can this project be expanded?
Yes. Possible upgrades include:
- Waste-level monitoring
- Buzzer alert when the bin is full
- Mobile notifications
- Automatic fill-level tracking through KiwisIoT
- Battery-powered operation
- Multiple dustbin monitoring
- Data logging and usage analytics