Arduino Kran Otomatis
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F , 16, 2);
const int pinTrig = 8;
const int pinEcho = 9;
const int kran = 13;
int jarak;
void setup() {
lcd.begin();
Serial.begin(9600);
pinMode(pinTrig, OUTPUT);
pinMode(pinEcho, INPUT);
pinMode(kran,OUTPUT);
digitalWrite(kran,LOW);
lcd.setCursor(00,00);
lcd.print(" BELAJAR LISTRIK ");
lcd.setCursor(00,01);
lcd.print ("dan ELEKTRONIK");
delay (1500);
lcd.clear();
}
void loop() {
digitalWrite(pinTrig, HIGH);
delayMicroseconds(10);
digitalWrite(pinTrig, LOW);
float durasi = pulseIn(pinEcho, HIGH);
jarak =(durasi *0.034)/2;
Serial.println (jarak );
if (jarak < 40) {
digitalWrite(kran,HIGH);
lcd.setCursor(00,00);
lcd.print(" TERUS JAGA ");
lcd.setCursor(00,01);
lcd.print (" KEBERSIHAN " );
}
else {
digitalWrite(kran,LOW);
lcd.setCursor(00,00);
lcd.print("READY , DEKATKAN ");
lcd.setCursor(00,01);
lcd.print (" TANGAN ANDA ");
}
}
Komentar
Posting Komentar