#include "HX711.h"
// Konfigurasi pin HX711
const int pinDOUT = 2;
const int pinSCK = 4;
// Konfigurasi pin Buzzer
const int buzzerPin = 5;
// Konfigurasi batas berat untuk alarm
const float batas = 36.0;
HX711 scale;
// Konfigurasi LCD
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
scale.begin(pinDOUT, pinSCK);
scale.set_scale(0.42);
scale.tare();
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
lcd.init();
lcd.backlight();
}
void loop() {
if (scale.is_ready()) {
long reading = scale.get_units(3);
float kg = float(reading) / 1000;
Serial.print("Berat: ");
Serial.print(kg, 2);
Serial.println(" kg");
if(kg > batas){
digitalWrite(buzzerPin, HIGH);
delay(5000);
digitalWrite(buzzerPin, LOW);
}
lcd.setCursor(0,0);
lcd.print("Timbangan Digital");
lcd.setCursor(0,1);
lcd.print("Berat: " + String(kg, 2) + "kg");
}
delay(5000);
}