#include <HX711_ADC.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
HX711_ADC LoadCell(6, 7); // parameters: dt pin 6, sck pin 7;
LiquidCrystal_I2C lcd(0x27, 16, 2); // 0x27 is the i2c address might be different; you can check with Scanner
#define LOADCELL_DOUT_PIN 2
#define LOADCELL_SCK_PIN 3
#define LED_PIN 13
#define WEIGHT_THRESHOLD 20 // Adjust this threshold value according to your requirements
void setup() {
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells get 2000ms of time to stabilize
LoadCell.setCalFactor(-910.52); // calibration factor for load cell => dependent on your individual setup
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
LoadCell.update(); // retrieves data from the load cell
float weightValue = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to second row
lcd.print(weightValue); // print out the retrieved value to the second row
Serial.print("Weight: ");
Serial.print(weightValue);
Serial.println(" g");
if (weightValue > WEIGHT_THRESHOLD) {
digitalWrite(LED_PIN, HIGH); // Turn on the LED if weight is above the threshold
} else {
digitalWrite(LED_PIN, LOW); // Turn off the LED if weight is below the threshold
}
delay(1000); // Delay for stable readings