#include "HX711.h"
// Pin setup for HX711 amplifier
#define DOUT A1
#define CLK A0
// Threshold in kg
float thresholdWeight = 2;
HX711 scale;
int ledPin = 13;
void setup() {
Serial.begin(9600);
// Initialize HX711
scale.begin(DOUT, CLK);
// Calibrate the scale (this value may vary, you can calibrate it manually)
scale.set_scale(415.f); // Adjust to match your load cell calibration factor
scale.tare(); // Reset scale to 0
// Setup LED pin
pinMode(ledPin, OUTPUT);
}
void loop() {
// Get weight in kg
float weight = scale.get_units(10); // Average of 10 readings
// Display weight on serial monitor
Serial.print("Weight: ");
Serial.print(weight);
Serial.println(" kg");
// Check if the weight exceeds threshold
if (weight >= thresholdWeight) {
// Blink LED if the weight exceeds 5kg
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
} else {
// Keep LED off if below threshold
digitalWrite(ledPin, LOW);
}
delay(1000); // Delay for 1 second before next reading
}