#include <LiquidCrystal.h> // Include the LCD library
// LCD pins connected to ESP32
const int rs = 22;
const int en = 23;
const int d4 = 19;
const int d5 = 18;
const int d6 = 17;
const int d7 = 16;
// Buzzer and LED pins connected to ESP32
const int buzzerPin = 2;
const int ledPin = 13;
// Initialize the LCD
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 4); // Initialize the LCD with 16 columns and 4 rows
pinMode(buzzerPin, OUTPUT); // Initialize buzzer pin as output
pinMode(ledPin, OUTPUT); // Initialize LED pin as output
lcd.setCursor(0, 0);
lcd.print("PROJECT DONE BY:");
lcd.setCursor(3, 1);
lcd.print("GERALD WATHUTA");
lcd.setCursor(2, 2);
lcd.print("STEPHEN MUTINDA");
delay(10000); // Welcome message delay
}
void loop() {
// Simulated weight values
float weight = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Max weight: 2500g");
lcd.setCursor(0, 1);
lcd.print("Weight: ");
lcd.print(weight, 0); // Print simulated weight in grams with no decimal places
lcd.print("g");
delay(1000); // Delay between updates
// Simulate increasing weight when loaded
for (int i = 0; i <= 2500; i += 100) {
weight = i;
updateDisplay(weight);
if (weight > 2500) {
activateBuzzer();
activateLED();
}
delay(1000); // Delay for demonstration purposes
}
// Simulate decreasing weight when offloaded
for (int i = 2500; i >= 0; i -= 100) {
weight = i;
updateDisplay(weight);
if (weight > 2500) {
activateBuzzer();
activateLED();
}
delay(1000); // Delay for demonstration purposes
}
}
void updateDisplay(float weight) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Max weight: 2500g");
lcd.setCursor(0, 1);
lcd.print("Weight: ");
lcd.print(weight, 0); // Print simulated weight in grams with no decimal places
lcd.print("g");
}
void activateBuzzer() {
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
delay(1000); // Buzz for 1 second
digitalWrite(buzzerPin, LOW); // Turn off buzzer
}
void activateLED() {
digitalWrite(ledPin, HIGH); // Turn on LED
}