/*
Tempat Sampah Sensor Versi ke-2!
Maker: Raffa Azka Ghifari (Kelas 8-A)
Collab dengan Ryhanna Afiza Desky (Kelas 8-B)
Peran:
Raffa Azka Ghifari (Programmer, Circuit Designer)
Ryhanna Afiza Desky (Designer, Feature Enhancer)
*/
// Liquid Crystal Library & Pin Arrangement
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Servo Library & Pin Arrangement & Variables
#include <Servo.h>
Servo servo;
int angle =0;
int angleStep =50;
// Ultrasonic Sensor Pin Arrangment & Variables
const int trig = 7;
const int echo = 6;
const int servoPin = 8;
const int dist = 50;
// Used only for distance calculations
float duration_us, distance_cm;
int trashCollected = 0;
// ----------------------------
// The first batch of code that runs on the Arduino:
void setup() {
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
servo.attach(servoPin);
servo.write(0);
lcd.begin(20, 4);
lcd.print("Tempat Sampah Pintar");
}
// The second batch of code that loops infinitely on the Arduino:
void loop() {
lcd.setCursor(0, 1);
lcd.print("Sampah dibuang: ");
lcd.print(trashCollected);
}
// A function callout for measuring the distance between
// the sensor and the object
void measureDistance() {
digitalWrite(trig, LOW);
delayMicroseconds(5);
digitalWrite(trig, HIGH);
delayMicroseconds(15);
digitalWrite(trig, LOW);
duration_us = pulseIn(echo, HIGH);
distance_cm = (duration_us/2) / 29.1;
}