top of page
Writer's pictureSanskruti Ashtikar

Introduction to Smart Dustbin with 8051 Microcontroller

Updated: 2 days ago

With the rise of smart technologies, everyday objects are becoming more intelligent and efficient. One such innovation is the smart dustbin, which automates waste management processes. A smart dustbin can automatically open its lid when waste is detected nearby, providing a touch-free experience, which is especially useful for maintaining hygiene in public places and homes. In this article, we will explore how to create a smart dustbin using the 8051 microcontroller, discussing the components required, working principles, and interfacing techniques.





Components Required


  1. 8051 Microcontroller Development Board

  2. Ultrasonic Sensor (HC-SR04)

  3. Servo Motor

  4. LCD Display (16x2)

  5. Resistors and Capacitors (if necessary)

  6. Connecting Wires

  7. Power Supply


Understanding the Components


Ultrasonic Sensor (HC-SR04)

The ultrasonic sensor is used to detect the presence of an object (in this case, a hand) near the dustbin. It sends out ultrasonic waves and measures the time taken for the waves to bounce back, thus calculating the distance of the object from the sensor.

Servo Motor

A servo motor is used to open and close the lid of the dustbin. The servo motor can be controlled to rotate to a specific angle, allowing precise control over the lid's movement.

LCD Display

An LCD display is used to provide feedback or information, such as when the dustbin is open or closed, or to display a welcome message.

Working Principle

When an object (such as a hand) is detected within a certain range by the ultrasonic sensor, the 8051 microcontroller triggers the servo motor to open the lid of the dustbin. After a few seconds, the lid closes automatically. The LCD display can be used to show messages indicating the status of the dustbin.


Interfacing Smart Dustbin with 8051 Microcontroller


Circuit Diagram



Connections


  1. VCC and GND of the Ultrasonic Sensor are connected to the 5V and GND pins of the 8051 microcontroller, respectively.

  2. Trigger and Echo Pins of the Ultrasonic Sensor are connected to P1.0 and P1.1 of the 8051 microcontroller, respectively.

  3. Control Pin of the Servo Motor is connected to P2.0 of the 8051 microcontroller.

  4. LCD Display is connected to the appropriate pins of the 8051 microcontroller to display messages.


Code Implementation


Here is an example code to control the smart dustbin using the 8051 microcontroller.


#include <reg51.h>
#include "lcd.h"
sbit Trigger = P1^0; // Trigger pin of Ultrasonic Sensor
sbit Echo = P1^1;    // Echo pin of Ultrasonic Sensor
sbit Servo = P2^0;   // Servo motor control
void delay_ms(unsigned int ms) {
    unsigned int i, j;
    for (i = 0; i < ms; i++)
        for (j = 0; j < 1275; j++);
}


unsigned int measure_distance() {
    unsigned int time = 0;
    unsigned int distance = 0;
    Trigger = 1;   // Send a pulse
    delay_ms(10);
    Trigger = 0;
    while (!Echo); // Wait for Echo high
    while (Echo) {
        time++; // Measure time for which Echo is high
        delay_ms(1);
    }
    distance = (time * 0.034) / 2; // Calculate distance in cm
    return distance;
}
void servo_rotate(unsigned int angle) {
    unsigned int pulse_width;
    pulse_width = (angle * 2000 / 180) + 500; // Calculate pulse width for given angle
    Servo = 1;
    delay_ms(pulse_width / 1000);
    Servo = 0;
    delay_ms(20 - (pulse_width / 1000));
}
void main() {
    unsigned int distance;
    // Initialize LCD
    lcd_init();
    lcd_clear();
    lcd_gotoxy(1, 1);
    lcd_puts("Smart Dustbin");
    while (1) {
        distance = measure_distance();
        lcd_gotoxy(1, 2);
        lcd_puts("Dist: ");
        lcd_putnum(distance);
        lcd_puts(" cm");
        if (distance < 10) { // Object detected within 10 cm
            servo_rotate(90); // Open lid
            lcd_gotoxy(1, 2);
            lcd_puts("Lid Open      ");
            delay_ms(5000);   // Wait for 5 seconds
            servo_rotate(0);  // Close lid
            lcd_gotoxy(1, 2);
            lcd_puts("Lid Closed    ");
        }
        delay_ms(1000); // Sampling delay
    }
}




Explanation of the Code


  1. Header File Inclusion: The reg51.h header file includes the necessary definitions for working with the 8051 microcontroller. The lcd.h header file includes functions to control the LCD.

  2. Pin Definitions: The trigger and echo pins of the ultrasonic sensor and the servo motor control pin are defined as bit-addressable variables.

  3. Delay Function: A delay function is implemented to provide delays in milliseconds.

  4. Measure Distance Function:

  5. The measure_distance function sends a trigger pulse to the ultrasonic sensor and measures the time for which the echo pin is high.

  6. It calculates the distance based on the time taken for the ultrasonic waves to travel to the object and back.

  7. Servo Rotate Function:

  8. The servo_rotate function generates the appropriate pulse width to control the servo motor to a specific angle.

  9. Main Function:

  10. The LCD is initialized and displays the initial message.

  11. In the infinite loop (while(1)), the code continuously measures the distance using the ultrasonic sensor.

  12. If an object is detected within 10 cm, the servo motor rotates to open the lid, waits for 5 seconds, and then closes the lid.

  13. The LCD displays the distance and the status of the lid (open or closed).


Conclusion


Building a smart dustbin using the 8051 microcontroller demonstrates the practical application of sensor integration and automation in everyday objects. This project provides a hands-free, hygienic solution for waste disposal, making it especially useful in public places and homes. By following the steps and code provided in this article, you can create your own smart dustbin and explore further enhancements such as wireless notifications, integration with IoT platforms, or solar power for energy efficiency.


Additional Tips


  • Sensor Calibration: Ensure proper calibration of the ultrasonic sensor to accurately detect objects within the desired range.

  • Power Supply: Use a stable power supply to avoid erratic behavior of the sensor, microcontroller, and servo motor.

  • Mechanical Design: Consider the mechanical design of the dustbin lid to ensure smooth and reliable operation of the servo motor.

This project provides a solid foundation for developing more advanced and integrated smart home solutions using the 8051 microcontroller.


Want us to guide you through your project or make the project for you ?






Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 



0 views0 comments

Related Posts

See All

Comments


bottom of page