#include <Wire.h>
#include <LiquidCrystal_I2C.h> // Library for I2C LCD
#include <Servo.h> // Library for Servo Motor
#include <HX711.h> // Library for Load Cell
#define PIR_PIN 2 // PIR sensor pin
#define SERVO_PIN 5 // Servo motor pin
#define LOADCELL_DOUT_PIN 3 // Load cell data pin
#define LOADCELL_SCK_PIN 4 // Load cell clock pin
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address for I2C LCD
Servo servo;
HX711 scale;
void setup() {
pinMode(PIR_PIN, INPUT);
servo.attach(SERVO_PIN);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
lcd.init();
lcd.backlight(); // Turn on the backlight of the LCD
servo.write(0); // Initial position for servo
}
void loop() {
int sensorValue = digitalRead(PIR_PIN);
long weight = scale.read(); // Read the weight from the load cell
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Weight: ");
lcd.print(weight);
lcd.print("g");
if (weight < 1500) {
if(sensorValue==HIGH){
servo.write(90); // Turn servo to 90 degrees
}
}
else{
if(sensorValue==HIGH){
servo.write(0);}
}
// Adjust delay as needed
}