#include <Servo.h>
#include <LiquidCrystal_I2C.h>
const int t1 = 3;
const int e1 = 2;
const int t2 = 11;
const int e2 = 10;
const int b = 12;
int jsampah;
int tangan;
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo s;
void setup() {
pinMode(t1, OUTPUT);
pinMode(t2, OUTPUT);
pinMode(e1, INPUT);
pinMode(e2, INPUT);
pinMode(b, OUTPUT);
Serial.begin(9600);
s.attach(13);
lcd.init();
lcd.backlight();
lcd.print("XIA OFFICIAL");
}
void loop() {
digitalWrite(t1, LOW);
delayMicroseconds(2);
digitalWrite(t1, HIGH);
delayMicroseconds(10);
digitalWrite(t1, LOW);
long duration1 = pulseIn(e1, HIGH);
int Jrk1 = duration1 / 58;
digitalWrite(t2, LOW);
delayMicroseconds(2);
digitalWrite(t2, HIGH);
delayMicroseconds(10);
digitalWrite(t2, LOW);
long duration2 = pulseIn(e2, HIGH);
int tangan = duration2 / 58;
Serial.println(Jrk1);
Serial.println(tangan);
int i;
if (Jrk1<100) {
Serial. println("sampah full");
tone(b, 100);
s.write(90);
lcd. setCursor(0,1);
lcd. print("sampah penuh");
delay(100);
}
else {
if (Jrk1>100){
noTone(b);
if (tangan<100) {
Serial.println("ada tangan");
s.write(0);
lcd.setCursor(0, 1);
lcd.print("silakan nyampah");
delay(100);
}
else {
if (tangan>100) {
Serial.println("sleep");
s.write(90);
lcd.setCursor(0, 1);
lcd.print("trash colector");
delay(100);
}
}
}
}
}