#include <HX711.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// HX711 pins
HX711 scale;
const int DOUT = A1; // Data out
const int CLK = A0; // Clock
// LCD Display
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address of the LCD
int buzzerPin = 7; // Buzzer pin
int buttonPin = 8; // Button to simulate sack removal
// Inventory variables
int stockCount = 10; // Initial stock of cement sacks
const int safetyStock = 10; // Minimum allowed stock before alert
void setup() {
lcd.begin(16, 2);
lcd.backlight();
// Initialize the HX711
scale.begin(DOUT, CLK);
// Initialize pins
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Simulate sack removal with a button
// Display initial stock
lcd.setCursor(0, 0);
lcd.print("Cement Sacks:");
lcd.setCursor(0, 1);
lcd.print(stockCount);
}
void loop() {
// Simulate sack removal when button is pressed
if (digitalRead(buttonPin) == LOW) {
delay(300); // debounce delay
stockCount--; // Decrease stock count
lcd.setCursor(0, 1);
lcd.print(stockCount); // Update stock count on LCD
// Check if stock count is below safety level
if (stockCount <= safetyStock) {
digitalWrite(buzzerPin, HIGH); // Activate buzzer
lcd.setCursor(0, 0);
lcd.print("Alert: Low Stock");
} else {
digitalWrite(buzzerPin, LOW); // Deactivate buzzer
lcd.setCursor(0, 0);
lcd.print("Cement Sacks: ");
}
}
delay(500); // Delay for readability
}