#define BLYNK_TEMPLATE_ID "TMPL3R2c0wG3m"
#define BLYNK_TEMPLATE_NAME "Smart Load Monitor"
#define BLYNK_AUTH_TOKEN "bbp0r33vgSdrYYaF77R9y79WauHLEdo1"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h> // Blynk library for ESP32
#include <HX711.h> // HX711 load cell library
const char* ssid = "Wokwi-GUEST"; // Wi-Fi SSID
const char* password = ""; // Wi-Fi password
char auth[] = "bbp0r33vgSdrYYaF77R9y79WauHLEdo1"; // Blynk Auth Token
String Message ="HI kavi: Overload Alert";
String Message1 ="HI kavi: Material Deplition Alert";
const int LED_PIN = 15; // LED pin
const int BUZZER_PIN = 2; // Buzzer pin
// Load Cell HX711 setup
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;
HX711 scale;
// Initialize LCD I2C with address 0x27 and size 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
pinMode(BUZZER_PIN, OUTPUT); // Set Buzzer pin as output
// Initialize LCD
Wire.begin(21, 22);
lcd.begin(16, 2);
lcd.backlight();
lcd.print("LCD OK!");
delay(1000);
// Setup Load Cell HX711
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(0.42);
scale.tare(); // Set initial weight to 0
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Connect to Blynk
Blynk.begin(auth, ssid, password);
}
void blinkLEDAndBuzzer() {
for (int i = 0; i < 3; i++) {
digitalWrite(LED_PIN, HIGH);
tone(BUZZER_PIN, 800);
delay(300);
digitalWrite(LED_PIN, LOW);
noTone(BUZZER_PIN);
delay(300);
}
}
void loop() {
Blynk.run(); // Keep Blynk connection alive
long reading = scale.get_units(3);
float kg = float(reading) / 1000;
Serial.print("WEIGHT: ");
Serial.print(kg, 2);
Serial.println(" kg");
lcd.setCursor(0,0);
lcd.print("Smart load monitor");
lcd.setCursor(0,1);
lcd.print("WEIGHT: " + String(kg, 2) + "kg");
// Send weight data to Blynk
Blynk.virtualWrite(V1,kg); // v1 for Load Cell weight
// If weight exceeds 45kg
if (kg >= 45.0) {
lcd.setCursor(0, 1);
lcd.print("overload");
Serial.println("Overload");
Blynk.logEvent("overload", Message);
blinkLEDAndBuzzer();
}
// if weight below 5 kg
else if (kg <= 5.0) {
lcd.setCursor(0, 1);
lcd.print("Material Deplition");
Serial.println("Material Deplition");
Blynk.logEvent("deplition", Message1);
blinkLEDAndBuzzer();
}
else {
// Turn off LED and Buzzer if no action
digitalWrite(LED_PIN, LOW);
noTone(BUZZER_PIN);
}
delay(200); // Wait before reading again
}
BEFORE STOPPING THE SIMULATION REMOVE ALL THE WEIGHT(PRESSURE=0) TO
GET CORRECT READINGS ON NEXT STIMULATION
KAVINATH.K
22BEC0692