#include <HX711.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = A1; // Data pin
const int LOADCELL_SCK_PIN = A2; // Clock pin
HX711 scale;
// Initialize the LCD with its I2C address (0x27 or 0x3F are common)
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// Calibrate the scale with a known weight. Replace "YOUR_CALIBRATION_FACTOR" with your factor.
scale.set_scale(420.0); // Replace with your calibration factor
scale.tare(); // Reset the scale to 0
// Initialize the LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Weight: ");
}
void loop() {
float weight = scale.get_units(10); // Average 10 readings for accuracy
// Display the weight on the LCD
lcd.setCursor(0, 1);
lcd.print(" "); // Clear the second line
lcd.setCursor(0, 1);
lcd.print(weight, 2); // Display weight with 2 decimal places
lcd.print(" kg");
delay(500); // Update every half second
}