#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <HX711.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // Alamat I2C dan ukuran LCD
HX711 scale;
const int triggerPin = 12;// kaki triger ultrasound jarak hc-sr04
const int echoPin = 11;//kaki echo ultrasound jarak
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(2,0); //COLOM KE2 BARIS 1
lcd.print("PROJECT INDIVIDU");
lcd.setCursor(1,1); //COLOM KE1 BARIS 2
lcd.print("TIMBANGAN & TINGGI");
lcd.setCursor(4,2); //COLOM KE4 BARIS 3
lcd.print("ABDUL SUKUR");
lcd.setCursor(2,3); //COLOM KE2 BARIS 4
lcd.print("NIM: 02202205001");
delay(5000); // delay 5 detik
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
scale.begin(2, 3); // pin DOUT di 2 dan SCK di 3
scale.set_scale(0.42);
scale.tare();
}
void loop() {
long duration, distance;
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1; // Menghitung jarak dalam cm
if (scale.is_ready()){
long reading = scale.get_units(3);
float kg = float(reading) / 1000;
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Berat: " + String(kg, 2) + " kg");
lcd.setCursor(3, 2);
lcd.print("Tinggi: " + String(distance) + " cm");
delay(1000);
}
}