#include "HX711.h"
#include <LiquidCrystal.h>
#define DOUT 4
#define CLK 5
#define PUMP_PIN 14
#define THRESHOLD 2000 // Adjust this threshold according to your calibration
HX711 scale;
long simulatedWeight = 0;
bool increasing = true;
// Initialize the LCD with the numbers of the interface pins
LiquidCrystal lcd(12, 13, 14, 27, 26, 25);
void setup() {
Serial.begin(115200);
scale.begin(DOUT, CLK);
pinMode(PUMP_PIN, OUTPUT);
digitalWrite(PUMP_PIN, LOW); // Ensure pump is off initially
// Set up the LCD's number of columns and rows
lcd.begin(16, 2);
lcd.print("Water Level:");
}
void loop() {
// Simulate weight changes
if (increasing) {
simulatedWeight += 50; // Increase weight
if (simulatedWeight >= 2000) {
increasing = false; // Start decreasing after reaching 2000
}
} else {
simulatedWeight -= 0; // Decrease weight
if (simulatedWeight < 0) {
increasing = true; // Start increasing after reaching 0
}
}
Serial.print("Simulated Weight: ");
Serial.println(simulatedWeight);
// Convert weight to height (example: 1000 weight units = 10 cm)
float waterHeight = simulatedWeight / 100.0;
lcd.setCursor(0, 1); // Move to the second line
lcd.print(waterHeight);
lcd.print(" cm");
if (simulatedWeight < THRESHOLD) {
digitalWrite(PUMP_PIN, HIGH); // Turn on pump (LED ON)
Serial.println("Pump ON");
} else {
digitalWrite(PUMP_PIN, LOW); // Turn off pump (LED OFF)
Serial.println("Pump OFF");
}
delay(1000); // Read every second
}