Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP8266 Smart Dustbin with Ultrasonic and IR Sensors

View and Edit Project In Cirkit DesignerImage of ESP8266 Smart Dustbin with Ultrasonic and IR Sensors

Smart Dustbin Project Documentation

Summary

This project involves a smart dustbin that uses an ultrasonic sensor to measure the level of waste, an IR sensor to detect obstacles, and a servo motor to open the dustbin lid. The system is controlled by an ESP8266 NodeMCU microcontroller, and it is powered via a USB power source.

Component List

  1. ESP8266 NodeMCU

    • Description: A low-cost Wi-Fi microcontroller with multiple GPIO pins.
    • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
  2. HC-SR04 Ultrasonic Sensor

    • Description: A sensor used to measure distance by using ultrasonic waves.
    • Pins: VCC, TRIG, ECHO, GND
  3. IR Sensor

    • Description: An infrared sensor used to detect obstacles.
    • Pins: out, gnd, vcc
  4. Micro Servo 9G

    • Description: A small servo motor used to open and close the dustbin lid.
    • Pins: GND, +5V, PWM
  5. USB Power

    • Description: A power source providing 5V and GND.
    • Pins: +, -

Wiring Details

ESP8266 NodeMCU

HC-SR04 Ultrasonic Sensor

IR Sensor

Micro Servo 9G

USB Power

Code Documentation

ESP8266 NodeMCU Code

/*
 * Smart Dustbin Project
 * This code uses an ultrasonic sensor to measure the dustbin level, an IR sensor
 * to detect obstacles, and a servo motor to open the dustbin lid.
 */

#include <Servo.h>

// Pin definitions
const int trigPin = D1;
const int echoPin = D2;
const int irPin = D3;
const int servoPin = D4;

Servo dustbinServo;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(irPin, INPUT);
  dustbinServo.attach(servoPin);

  // Set initial servo position
  dustbinServo.write(0); // Close the lid
}

void loop() {
  // Measure distance using ultrasonic sensor
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;

  // Print distance to serial monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Check for obstacle using IR sensor
  int irValue = digitalRead(irPin);
  if (irValue == LOW) { // Obstacle detected
    dustbinServo.write(90); // Open the lid
    delay(5000); // Keep the lid open for 5 seconds
    dustbinServo.write(0); // Close the lid
  }

  delay(1000); // Wait for 1 second before next measurement
}

HC-SR04 Ultrasonic Sensor Code

// No code required for this component

IR Sensor Code

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

Micro Servo 9G Code

// No code required for this component

This documentation provides a comprehensive overview of the smart dustbin project, including the components used, their wiring details, and the code running on the ESP8266 NodeMCU microcontroller.