#include <HX711.h>
#include <LiquidCrystal_I2C.h>
const int ld_cell = 2;
const int ld_sck = 4;
const int RED = 13; // Assuming you have an LED connected to pin 13.
HX711 scale;
LiquidCrystal_I2C lcd(0x27, 16, 2);
float Weight = 0.0; // Use float for weight measurement
float Tank_weight = 6.2;
void setup() {
Serial.begin(115200);
scale.begin(ld_cell, ld_sck);
lcd.init();
lcd.backlight();
pinMode(RED, OUTPUT); // Set the red LED pin as an output
}
void loop() {
float Wei = 0.0; // Initialize Wei as a float
for (int x = 0; x < 100; x++) {
Wei += scale.read(); // Use scale.read() to read from the HX711
//delay(10); // Delay between readings
}
Wei = (Wei-Tank_weight) * 100.0;
//Wei = (Wei / 100.0 - Tank_weight) * 100.0; // Calculate the average and convert to percentage
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Gas Level");
lcd.setCursor(0,1);
lcd.print(Wei);
if (Wei < 10.0) {
Serial.println("Gas Level Low");
digitalWrite(RED, HIGH);
lcd.setCursor(0, 2); // Set cursor position for the second line
lcd.print("Gas Level is Low");
} else {
digitalWrite(RED, LOW);
lcd.setCursor(0, 2); // Set cursor position for the second line
lcd.print("Gas Level is Normal");
}
Serial.print("Gas Level: ");
Serial.println(Wei);
//delay(1000); // Delay for 1 second before the next reading
}