#include <HX711.h>
#include <LiquidCrystal.h>
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 3;
const int LOADCELL_SCK_PIN = 2;
// Parameters for calibration
const long LOADCELL_OFFSET = 0;
const float LOADCELL_DIVIDER = 428.0; // Adjust this divider to calibrate the scale
// Alarm settings
const int BUZZER_PIN = 4;
const int ALARM_WEIGHT_THRESHOLD = 8; // Weight threshold for the alarm in grams
// LCD settings
const int LCD_RS = 5;
const int LCD_EN = 6;
const int LCD_D4 = 7;
const int LCD_D5 = 8;
const int LCD_D6 = 9;
const int LCD_D7 = 10;
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
HX711 scale;
void setup() {
Serial.begin(9600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(LOADCELL_DIVIDER);
scale.tare(); // Reset the scale to zero
pinMode(BUZZER_PIN, OUTPUT); // Set up the buzzer pin as an output
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
}
void loop() {
float weight = scale.get_units(10); // Average 10 readings for stability
if (weight > ALARM_WEIGHT_THRESHOLD) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Overload!");
digitalWrite(BUZZER_PIN, HIGH); // Trigger the buzzer alarm
} else {
Serial.print("Weight: ");
Serial.print(weight);
Serial.println(" g");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Weight:");
lcd.setCursor(0, 1);
lcd.print(weight);
lcd.print(" g");
digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer
}
delay(500); // Wait for a bit before reading again
}