Wednesday, April 15, 2020

Sketch meter hc04

 Sketch meter hc 04 :

#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x3B , 16, 2);  // 0x3B ganti dengan alamat i2C teman"
const int pinEcho = 4; // pin echo pada pin 4
const int pinTrig = 5; // pin triger pada pin 5
int jarak;

void setup() {
 lcd.begin();
 Serial.begin(9600);
pinMode(pinTrig, OUTPUT);
pinMode(pinEcho, INPUT);
  lcd.setCursor(00,00);
  lcd.print(" BELAJAR LISTRIK ");
  lcd.setCursor(00,01);
  lcd.print ("dan ELEKTRONIK");
  delay (1500);
   lcd.clear();
   delay (500);
}
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 > 350) {
  lcd.setCursor(00,00);
  lcd.print(" Project HC-SR04");
  lcd.setCursor(00,01);
  lcd.print ("Jarak :");
  lcd.print (" No range " );
}

else {
lcd.setCursor(00,00);
lcd.print(" Project HC-SR04");
lcd.setCursor(00,01);
lcd.print ("Jarak : ");
lcd.print ( jarak ) ;
lcd.print (" cm");

}
delay (500);
lcd.clear();
}

No comments:

Post a Comment