#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
String word1;
String word2;
bool splash;
int total_kendaraan_masuk;
int total_kendaraan_keluar;
const float GAMMA = 0.7;
const float RL10 = 50;
#define ECHO_PIN_MASUK 3
#define TRIG_PIN_MASUK 4
#define ECHO_PIN_KELUAR 11
#define TRIG_PIN_KELUAR 12
float readDistanceCM(int TRIG_PIN, int ECHO_PIN) {
pinMode(TRIG_PIN, OUTPUT); // Clear the trigger
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
pinMode(ECHO_PIN, INPUT);
return pulseIn(ECHO_PIN, HIGH);
}
void setup() {
lcd.init();
lcd.backlight();
lcd.clear();
word1 = "Selamat datang";
word2 = " di ITTS ";
splash=true;
}
void loop() {
if (splash){
lcd.clear();
lcd.setCursor(3, 1);
lcd.print(word1);
lcd.setCursor(3, 2);
lcd.print(word2);
delay(1500);
lcd.clear();
splash=false;
} else{
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage /5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1/GAMMA));
if (lux > 100){
// Siang
lcd.setCursor(0, 0);
lcd.print("Saat ini Siang hari");
float jarak_masuk = readDistanceCM(TRIG_PIN_MASUK, ECHO_PIN_MASUK);
if (jarak_masuk/58 < 100.0){
total_kendaraan_masuk++;
delay(250);
lcd.setCursor(0, 2);
lcd.print("Kendaraan Masuk: ");
lcd.print(total_kendaraan_masuk);
}
}
else{
// Malam
lcd.setCursor(0, 0);
lcd.print("Saat ini Malam hari");
}
float jarak_keluar = readDistanceCM(TRIG_PIN_KELUAR, ECHO_PIN_KELUAR);
if (jarak_keluar/58 < 100.0){
total_kendaraan_keluar++;
delay(250);
lcd.setCursor(0, 3);
lcd.print("Kendaraan Keluar: ");
lcd.print(total_kendaraan_keluar);
}
}
}