Clean City
Hello, I'm new at Instructables. I would like to show one of my DIY project. We are going to build a bin that performs multiple functions. It opens when there are people near it and it closes after 7 seconds. It continues being closed when there don't pass people. If the bin is full, it won't open. Using Clean City, we check the level of garbage inside the bin to an app. I used Blynk in designing an environment for the app. In application:
When red is on there is a lot of garbage and it needs to be emptied.
When orange on it means that the quantity of waste inside bin is average and it may soon need to unload.
When blue is on, there is few garbage.
Gathering Materials
Components used in this project are:
· NodeMCU ESP8266 Microcontroller
· 2 ultrasonic sensors
· 1 breadboard
· 1 PC
· A lot of jumper wires
· 1 Servo Motor
· 1 Power Bank
· A bin
· A USB Cable
· A phone
Code
#include <Blynk.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
Servo servo1;
const int trig = 4;
const int echo = 5;
const int trig1 = 0;
const int echo1 = 2;
int distance;
long duration;
int distance1;
long duration1;
char auth[] = ""; //Enter the auth token given by Blynk to your email adress
char ssid[] = ""; //Enter your ssid
char pass[] = ""; //Enter the password of your ssid
WidgetLED blue (V0);
WidgetLED orange (V1);
WidgetLED red(V2);
WidgetLCD lcd(V3);
WidgetLCD lcd1(V4);
void setup() {
Serial.begin(9600);
Serial1.begin(115200);
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
pinMode(trig1,OUTPUT);
pinMode(echo1,INPUT);
Blynk.begin(auth,ssid,pass);
servo1.attach(16);
servo1.write(0);
}
void loop() {
lcd.clear();
lcd.print(0,0,"Smart bin 1");
lcd1.clear();
lcd1.print(0,0,"Distance in cm");
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
duration = pulseIn(echo,HIGH);
distance = duration * 0.0343/2;
lcd.print(7,1,distance);
digitalWrite(trig1,LOW);
delayMicroseconds(2);
digitalWrite(trig1,HIGH);
delayMicroseconds(10);
digitalWrite(trig1,LOW);
duration1 = pulseIn(echo1,HIGH);
distance1 = duration1* 0.0343/2;
Serial.println(distance1);
if(distance >= 22){
blue.on();
orange.off();
red.off();
}
if(distance < 22 && distance >= 10){
blue.off();
orange.on();
red.off();
}
if(distance < 10){
blue.off();
orange.off();
red.on();
}
if(distance > 10 && distance1 <= 10){
servo1.write(150);
delay(7000);
servo1.write(0);
}
if(distance <=10 && distance1 > 10){
servo1.write(0);
}
Blynk.run();
delay(100);
}
Downloads
Schematic
Servo red wire is connected to 5V. I have connected it to 3V supply of NodeMCU ESP8266. Servo brown wire is connected to GND and servo yellow pin is connected to D0.
The first ultrasonic sensor (the one inside the bin) GND pin is connected to GND; VCC pin is connected to VIN; echo pin is connected to D1; trig pin is connected to D2. The second ultrasonic sensor GND pin is connected to GND; VCC pin is connected to VIN; trig pin is connected to D3; echo pin is connected to D4.
My App
Feel free to experiment in Blynk to create your own app environment.
Video
https://youtu.be/jmlyqFKLBQo