// LCD
#include<LiquidCrystal_I2C.h>
#include<Wire.h>
// Remote IR
#include <IRremote.h>
// Ultrasonic
#include <Ultrasonic.h>
// Servo
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// int angle = 0; // variable to store the servo position
int buzzerPin = 11;
LiquidCrystal_I2C lcd(0x27,16,2);
String nama = "Buanglah Sampah Pada Tempatnya";
String cur = ""; int start = 0;
bool status = true;
const int RECV_PIN = 2;
const int NUM_OF_BUTS = 21;
long BUTTON_CODES[NUM_OF_BUTS] = {
16729530,
16730040,
16729275,
16728255,
16729020,
16713720,
16717290,
16714230,
16717545,
16718310,
16715250,
16714995,
16718055,
16735905,
16713975,
16719075,
16734885,
16728765,
16732845,
16730805
};
String BUTTON_NAMES[NUM_OF_BUTS] = {
"POWER","MENU","Test","VOL+","BACK",
"PREV/LEFT","PAUSE/MUTE","NEXT/RIGTH",
"0","VOL-","CH","1","2","3","4","5","6","7","8","9"
};
int findButton(long val){
for(int i = 0; i < NUM_OF_BUTS; i++){
if(val == BUTTON_CODES[i]){
return i;
}
}
return val;
}
IRrecv irrecv(RECV_PIN);
decode_results results;
// Ultrasonic
Ultrasonic ultrasonic(6, 7);
int distance;
void setup(){
Serial.begin(9600);
// ir remote
irrecv.enableIRIn(); // Start the receiver
// LCD
lcd.init();
lcd.setCursor(0,0);
pinMode(11, OUTPUT);
myservo.attach(12);
lcd.print("SMART TRASH BIN");
}
String jam ="";
void loop() {
// Remote dan IR untuk control
if (irrecv.decode(&results)) {
//Serial.println(results.value, HEX);
int button_id = findButton(results.value);
// Serial.println(results);
if (button_id <0) {
Serial.println("Unknown button is pressed!");
} else {
Serial.print("Button ");
Serial.print(BUTTON_NAMES[button_id]);
Serial.println(" is pressed!");
if(BUTTON_NAMES[button_id] == "Test"){
lcd.setCursor(0,1);
lcd.print("Silahkan dibuang");
openTrash();
delay(1000);
// jam = "18:00";
}
else if (BUTTON_NAMES[button_id] == "POWER"){
if (status == true){
status = false;
offTrash();
} else {
status = true;
onTrash();
}
}
// action kalo pencet tombol
}
irrecv.resume(); // Receive the next value
}
// Ultrasonic detec jarak
distance = ultrasonic.read(CM);
Serial.print("Distance in CM: ");
Serial.println(distance);
distance = ultrasonic.read(INC);
Serial.print("Distances: ");
Serial.println(distance);
// servo gerak kalo distance sekian
// if(1 == 1){
// }
// LCD
lcd.backlight();
for (int i=start; i<start+16; i++){
cur = cur + nama[i];
}
if (start == 35){ start = -1; }
if (status == true){
lcd.setCursor(0,1);
lcd.print(cur);
}
start++;
cur = "";
// waktu buang sampah
// jam = "17:00";
if (jam == "18:00"){
// lcd.print("Kosongin Saya :(");
tone(11, 200);
delay(500);
noTone(11);
}
delay(500);
}
void openTrash(){
// nyalain buzzer belum bisa
// tone(buzzerPin, 200);
// tone(buzzerPin, 200);
myservo.write(-90);
delay(2000);
myservo.write(90);
irrecv.resume();
}
void offTrash(){
lcd.setCursor(0,0);
lcd.print(" + + ");
lcd.setCursor(0,1);
lcd.print(" O ");
delay(500);
lcd.setCursor(0,0);
lcd.print(" - - ");
lcd.setCursor(0,1);
lcd.print(" ------- ");
delay(500);
lcd.setCursor(0,0);
lcd.print(" + + ");
lcd.setCursor(0,1);
lcd.print(" --- ");
delay(500);
lcd.setCursor(0,0);
lcd.print(" - - ");
lcd.setCursor(0,1);
lcd.print(" - ");
delay(500);
lcd.setCursor(0,0);
lcd.print(" - - ");
lcd.setCursor(0,1);
lcd.print(" ___ ");
delay(1000);
lcd.setCursor(0,0);
lcd.print(" TIME FOR ");
lcd.setCursor(0,1);
lcd.print(" SLEEP ");
delay(2000);
}
void onTrash(){
lcd.setCursor(0,0);
lcd.print("SMART TRASH BIN");
}