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
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
HC-SR04 Ultrasonic Sensor
- Description: A sensor used to measure distance by using ultrasonic waves.
- Pins: VCC, TRIG, ECHO, GND
IR Sensor
- Description: An infrared sensor used to detect obstacles.
- Pins: out, gnd, vcc
Micro Servo 9G
- Description: A small servo motor used to open and close the dustbin lid.
- Pins: GND, +5V, PWM
USB Power
- Description: A power source providing 5V and GND.
- Pins: +, -
Wiring Details
ESP8266 NodeMCU
- D1: Connected to TRIG pin of the HC-SR04 Ultrasonic Sensor
- D2: Connected to ECHO pin of the HC-SR04 Ultrasonic Sensor
- D3: Connected to out pin of the IR Sensor
- D4: Connected to PWM pin of the Micro Servo 9G
- 3V3: Connected to vcc pin of the IR Sensor
- GND: Connected to - pin of the USB Power, gnd pin of the IR Sensor, GND pin of the Micro Servo 9G, and GND pin of the HC-SR04 Ultrasonic Sensor
- VIN: Connected to + pin of the USB Power
HC-SR04 Ultrasonic Sensor
- TRIG: Connected to D1 pin of the ESP8266 NodeMCU
- ECHO: Connected to D2 pin of the ESP8266 NodeMCU
- VCC: Connected to + pin of the USB Power
- GND: Connected to GND pin of the ESP8266 NodeMCU
IR Sensor
- out: Connected to D3 pin of the ESP8266 NodeMCU
- gnd: Connected to GND pin of the ESP8266 NodeMCU
- vcc: Connected to 3V3 pin of the ESP8266 NodeMCU
Micro Servo 9G
- GND: Connected to GND pin of the ESP8266 NodeMCU
- +5V: Connected to + pin of the USB Power
- PWM: Connected to D4 pin of the ESP8266 NodeMCU
USB Power
- -: Connected to GND pin of the ESP8266 NodeMCU
- +: Connected to VIN pin of the ESP8266 NodeMCU and +5V pin of the Micro Servo 9G
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.
