Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat tempat sampah pintar buka dan tutup otomatis menggunakan sensor jarak dan Arduino, alat ini sejatinya difungsikan agar orang tidak peerlu repot-repot lagi membuka tempat sampah yang biasanya kotor dan berbau, maka dari itu dibuatlah tempat sampah yang non-kontak agar terjaga kebersihannya terutama bagi manusia dan tangan dari bakteri. tempat sampah ini dilengkapi alarm dan indikator LED hijau dan merah agar kita bisa tahu apakah tempat sampah sudah penuh atau masih kosong. jika sudah penuh maka buzzer akan berbunyi dan LED merah akan menyala, berikut adalah skema dan programnya.
a. Arduino Uno
b. Sensor Jarak HC-SRF04
c. LCD + I2C
d. Motor Servo Mini
e. Led dan Buzzer
f. Program Arduino IDE
#include <Wire.h> // i2C Conection Library
#include <LiquidCrystal_I2C.h> //i2C LCD Library
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#include <Servo.h>
#define trigPin1 7
#define echoPin1 6
#define trigPin2 5
#define echoPin2 4
#define trigPin3 3
#define echoPin3 2
Servo myservo;
int led1 = A0;
int led2 = A1;
int buzzer = A2;
long duration1, distance1;
long duration2, distance2;
long duration3, distance3;
void setup()
{
myservo.attach(9);
lcd.begin();
lcd.noCursor();
lcd.clear();
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,HIGH);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
myservo.write(170);
}
void loop()
{
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;
lcd.setCursor(0,0);
lcd.print(distance1);
lcd.print(" ");
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2/2) / 29.1;
lcd.setCursor(4,0);
lcd.print(distance2);
lcd.print(" ");
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
duration3 = pulseIn(echoPin3, HIGH);
distance3 = (duration3/2) / 29.1;
lcd.setCursor(8,0);
lcd.print(distance3);
lcd.print(" ");
// myservo.write(170);
if(distance3 > 5){
lcd.setCursor(0,1);
lcd.print(" KOSONG ");
digitalWrite(buzzer,HIGH);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
if((distance1 <= 10)&&(distance2 <= 10)){
myservo.write(40);
delay(3000);
myservo.write(170);
}
if((distance1 <= 10)&&(distance2 > 10)){
myservo.write(40);
delay(3000);
myservo.write(170);
}
if((distance1 > 10)&&(distance2 <= 10)){
myservo.write(40);
delay(3000);
myservo.write(170);
}
if((distance1 > 10)&&(distance2 > 10)){
myservo.write(170);
}
}
if(distance3 < 8){
lcd.setCursor(0,1);
lcd.print(" PENUH ");
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(buzzer,LOW);
myservo.write(170);
}
delay(200);
}
#include <LiquidCrystal_I2C.h> //i2C LCD Library
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#include <Servo.h>
#define trigPin1 7
#define echoPin1 6
#define trigPin2 5
#define echoPin2 4
#define trigPin3 3
#define echoPin3 2
Servo myservo;
int led1 = A0;
int led2 = A1;
int buzzer = A2;
long duration1, distance1;
long duration2, distance2;
long duration3, distance3;
void setup()
{
myservo.attach(9);
lcd.begin();
lcd.noCursor();
lcd.clear();
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,HIGH);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
myservo.write(170);
}
void loop()
{
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;
lcd.setCursor(0,0);
lcd.print(distance1);
lcd.print(" ");
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2/2) / 29.1;
lcd.setCursor(4,0);
lcd.print(distance2);
lcd.print(" ");
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
duration3 = pulseIn(echoPin3, HIGH);
distance3 = (duration3/2) / 29.1;
lcd.setCursor(8,0);
lcd.print(distance3);
lcd.print(" ");
// myservo.write(170);
if(distance3 > 5){
lcd.setCursor(0,1);
lcd.print(" KOSONG ");
digitalWrite(buzzer,HIGH);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
if((distance1 <= 10)&&(distance2 <= 10)){
myservo.write(40);
delay(3000);
myservo.write(170);
}
if((distance1 <= 10)&&(distance2 > 10)){
myservo.write(40);
delay(3000);
myservo.write(170);
}
if((distance1 > 10)&&(distance2 <= 10)){
myservo.write(40);
delay(3000);
myservo.write(170);
}
if((distance1 > 10)&&(distance2 > 10)){
myservo.write(170);
}
}
if(distance3 < 8){
lcd.setCursor(0,1);
lcd.print(" PENUH ");
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(buzzer,LOW);
myservo.write(170);
}
delay(200);
}
g. VIDEO HASILNYA