/*PROJECT - automatic trash bin (for 1st round of technoMind)
TEAM - Robo Wizards
AUTHER - H.A.Idusha sachintha (the leader of team Robo Wizards)
CONTACT - whatsapp = 071 5356389 Email = [email protected]
DATE - 24/04/2023
DESCRIPTION,
This is a automatic trash bin.
When a person goes in front of the bin lid will be open.
if the trash bin is full, it will indicate through a Buzzer,LED & LCD display.
used board is ESP32
used laguage for coding is C++
*NOTE
1. Lid open position angle = 180 degrees
2. Lid closed position angle = 20 degrees
3. ultrasonic sensor reading for bin full is distance <= 5cm
*/
#include<ESP32Servo.h> // import servo library for servo
#include <LiquidCrystal_I2C.h> // import the LiquidCrystal_I2C.h library for LCD display
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);//setup the LCD display
Servo servo; //make the servo object
#define PIRPin 4 // define a pin to PIR sensor
#define trig 13//define pins for ultrasonic sensor
#define echo 12
#define buzzerPin 27 //define a pin for buzzer
#define LEDPin 14 //define a pin to LED
void setup() {
// setup PIR sensor pin
pinMode(PIRPin, INPUT);
// setup ultrasonic pins
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
// setup buzzer pin
pinMode(buzzerPin, OUTPUT);
// setup LED pin
pinMode(LEDPin, OUTPUT);
// set a pin to Servo motor
servo.attach(2);
servo.write(0);
//setup the starting text on LCD display
LCD.init();
LCD.backlight();
LCD.setCursor(2, 0);
LCD.println("Robo Wizards");
delay(2000);
LCD.setCursor(0, 0);
LCD.println("Automatic trash");
LCD.setCursor(7, 1);
LCD.println("bin");
delay(2000);
LCD.clear();
LCD.setCursor(2, 0);
LCD.println("turning on...");
delay(2000);
}
void loop() {
lid_open();
trash_full_indicte();
LCD.clear();
}
void lid_open() {
if (digitalRead(PIRPin) == 1) { //read PIR senser & see whether the PIR sensor is on
//open the lid
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("LID OPENING...");
for (int X = 20; X <= 180; X++) {
servo.write(X);
delay(10);
}
//wait 2 seconds
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("PUT YOUR TRASH");
delay(3000);
//close the lid
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("LID closing...");
for (int X = 180; X > 20; X--) {
servo.write(X);
delay(10);
}
}
}
void trash_full_indicte() {
int DISTANCE = 0;
DISTANCE = ultrasonic();
// indicate bin status
if (DISTANCE <= 5) {
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("Trash bin full !");
LCD.setCursor(0, 1);
LCD.println("CLEAN THE BIN");
}
while (DISTANCE <= 5) {
digitalWrite(LEDPin, HIGH);
tone(buzzerPin, 1000);
delay(1000);
digitalWrite(LEDPin, LOW);
tone(buzzerPin, 500);
delay(1000);
DISTANCE = ultrasonic();
}
noTone(buzzerPin);
//if the trash bin is not full turn off the buzzer
}
//Read the ultrasonic sensor & convert the reading to cm
int ultrasonic() {
digitalWrite(trig, LOW);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
int disvalue = pulseIn(echo, HIGH);
int distance = disvalue / 2 / 29;
return distance;
}