// Libraries
#include <HX711.h> // Load cell library
// Constants
const int LOAD_CELL_DOUT_PIN = 2; // DOUT pin of HX711
const int LOAD_CELL_SCK_PIN = 3; // SCK pin of HX711
const int BUZZER_PIN = 4; // Buzzer pin
const int CALIBRATION_FACTOR = 1024; // Calibration factor for your load cell
const int THRESHOLD = 50000; // Threshold weight in grams (50 kg = 50000 g)
// Variables
HX711 scale;
// Setup
void setup() {
Serial.begin(9600);
scale.begin(LOAD_CELL_DOUT_PIN, LOAD_CELL_SCK_PIN);
scale.set_scale(CALIBRATION_FACTOR);
pinMode(BUZZER_PIN, OUTPUT);
}
// Main loop
void loop() {
float weight = scale.get_units(); // Read weight from the load cell
if (weight > THRESHOLD) {
// Activate the buzzer
digitalWrite(BUZZER_PIN, HIGH);
delay(1000);
digitalWrite(BUZZER_PIN, LOW);
// You can add more actions here, such as sending an alert message.
// Wait for some time to prevent continuous alerts
delay(5000);
}
delay(100);
}