ballas43jhosuacayani
Published © GPL3+

EasyTrash 1.0

You don't open it, it opens itself. You don't check it, it checks itself

IntermediateShowcase (no instructions)1,584
EasyTrash 1.0

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Male/Male Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
We used HY-SRF05 which is similar to the SR04 but the input and output pin for the ultrasonic detection is separated to 2 pins
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Resistor 2.2k ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Generic trash can
×1
Power Bank
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk
Fritzing

Story

Read more

Schematics

Schematic

This is the schematic of the project

Code

Code

C/C++
This is the code for the project
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600

#include <Servo.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>

char auth[] = "<Your Blink API Code>";
char ssid[] = "<Your WI-FI SSID>";
char pass[] = "<Your WI-FI Password>";

const unsigned int TRIG_PIN=11;
const unsigned int ECHO_PIN=10;
const unsigned int PIR_PIN=7;
const unsigned int SERVO1_PIN=12;


Servo trashservo;

SoftwareSerial EspSerial(2, 3);
ESP8266 wifi(&EspSerial);

int opened, level, pir_value;

unsigned long previousMillis = 0; 
const long interval = 5000;

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(PIR_PIN, INPUT);
  Serial.begin(9600);

  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  closeTrash();
}

void servoDetail(){
  Blynk.virtualWrite(V2, trashservo.read());
}

void openDetail(){
  Blynk.virtualWrite(V3, opened);
}

void openTrash(){
  trashservo.attach(SERVO1_PIN);
  trashservo.write(25);
  
  servoDetail();
  delay(1);
  trashservo.detach();
  
  opened = 1;
  delay(1000);
}

void closeTrash(){
  trashservo.attach(SERVO1_PIN);
  trashservo.write(120);
  
  servoDetail();
  delay(1);
  trashservo.detach();
  
  opened = 0;
  delay(1000);
}

void pirSensor(){
  pir_value = digitalRead(PIR_PIN);
  Blynk.virtualWrite(V0, pir_value);
  if(pir_value == HIGH && opened == 0){
    openTrash();
  }else if(pir_value == HIGH && opened == 1){
    closeTrash();
  }
}

void checkLevel(){
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  

 const unsigned long duration= pulseIn(ECHO_PIN, HIGH);
 int distance= duration/29/2;
 level = distance;
 Blynk.virtualWrite(V1, level);

 if(level < 10){
  Blynk.notify("Trash Full!!");
 }
 delay(100);
}

void loop() {
  unsigned long currentMillis = millis();
  
  Blynk.run();
  openDetail();
  pirSensor();
  
  if (currentMillis - previousMillis >= interval && opened!=1) {
    previousMillis = currentMillis;
    checkLevel();
  }
}

Credits

ballas43

ballas43

0 projects • 0 followers
jhosuacayani

jhosuacayani

0 projects • 0 followers

Comments

Add projectSign up / Login