Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #define BLYNK_PRINT Serial
- #include <Servo.h>
- #include <Ultrasonic.h>
- #define trigPin 12
- #define echoPin 13
- Ultrasonic ultrasonic (12,13);
- Ultrasonic ultrasonic2(05, 04);
- Servo servo;
- int sound = 250;
- //blynk
- char auth [] = "DQE0nrb27s3yAJm9CO_kYDl99yh_H7_H";
- char ssid [] = "Kris";
- char pass [] = "0987654321";
- WidgetLCD lcd(V5);
- void setup() {
- Blynk.begin(auth, ssid, pass);
- Serial.begin (9600);
- pinMode(12, OUTPUT);
- pinMode(13, INPUT);
- servo.attach(16);
- }
- void loop() {
- Blynk.run();
- long duration, distance, example;
- distance = ultrasonic.read();
- example = ultrasonic2.read();
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = duration/ 200;
- if (distance < 5) {
- Serial.println("the distance is less than 5");
- servo.write(90);
- delay (2000);
- }
- else {
- servo.write(0);
- }
- if (distance > 60 || distance <= 0){
- Serial.println("The distance is more than 60");
- }
- else {
- Serial.print(distance);
- Serial.println(" cm");
- }
- delay(0);
- if (example<=3){
- Serial.print("Example in CM: ");
- Serial.println(example);
- lcd.print(0,0,"Tempat Sampah Penuh!!");
- Blynk.notify("Penuh!!");
- } else {
- lcd.print(0,1,"Tempat Sampah Belum Penuh!!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement