#include <HX711.h>
#include <Servo.h>
#include <LiquidCrystal.h>
const int loadCellDTPin = 2; // Pin DOUT load cell
const int loadCellSCKPin = 3; // Pin SCK load cell
const int servoPin = 9; // Pin servo motor
const int rs = 7; // Pin 7 on Arduino to pin 4 (RS) on LCD
const int en = 6; // Pin 6 on Arduino to pin 6 (E) on LCD
const int d4 = 12; // Pin 12 on Arduino to pin 11 (D4) on LCD
const int d5 = 11; // Pin 11 on Arduino to pin 12 (D5) on LCD
const int d6 = 10; // Pin 10 on Arduino to pin 13 (D6) on LCD
const int d7 = 5; // Pin 5 on Arduino to pin 14 (D7) on LCD
HX711 scale;
Servo myServo;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const long threshold = 500.0; // Ambang batas load cell
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
scale.begin(loadCellDTPin, loadCellSCKPin);
myServo.attach(servoPin);
lcd.print("Menyalakan");
delay(2000);
lcd.clear();
}
void loop() {
long weight = scale.read();
lcd.setCursor(0, 0);
lcd.print("Berat:");
lcd.print(weight);
lcd.print(" g ");
lcd.setCursor(0, 1);
if (weight > threshold) {
lcd.print("Lebih dari Batas");
// Jika berat kurang dari batas, set motor servo ke posisi 360 derajat
while (weight > threshold) {
myServo.write(360); // Atur posisi servo ke 0 derajat (atau nilai lainnya sesuai kebutuhan)
delay(50); // Delay yang lebih lama untuk memberikan waktu motor servo berputar
weight = scale.read(); // Baca berat lagi
} }else {
lcd.print("Dalam Batas ");
// Jika berat dalam batas, set motor servo ke posisi 0 derajat (atau posisi lainnya)
myServo.write(0);
}
delay(1000);}