#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <HX711.h>
// Constants for pins
const int potentiometerPin = A0;
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
const int buzzerPin = 12;
const int lcdAddress1 = 0x27;
const int lcdAddress2 = 0x26;
LiquidCrystal_I2C lcd1(lcdAddress1, 16, 2);
LiquidCrystal_I2C lcd2(lcdAddress2, 16, 2);
HX711 scale;
// Constants for cylinder sizes
const float cylinderSizes[] = {9.0, 14.0, 19.0, 48.0};
const char* fullnessLabels[] = {"Empty", "Half-filled", "Full"};
// Constants for gas alert threshold
const float gasAlertThreshold = 25.0;
// Variable to represent the current cylinder size
float currentCylinderSize = 0.0; // Initialize to 0.0, you can set it based on your calibration
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
lcd1.init();
lcd1.backlight();
lcd1.clear();
lcd1.setCursor(0, 0);
lcd1.print("Weight:");
lcd2.init();
lcd2.backlight();
lcd2.clear();
lcd2.setCursor(0, 0);
lcd2.print("Fullness:");
scale.begin(2, 3); // Replace with your actual HX711 pin numbers
// Assuming your load cell is already calibrated, you can skip the calibration step.
// Remove this line: scale.set_scale();
scale.tare(); // Reset the scale to zero
// To address the zero factor issue, you can ignore it since the load cell should already be calibrated.
}
void loop() {
// Read load cell data
float loadCellWeight = scale.get_units(10);
// Check if weight is less than zero
if (loadCellWeight < 0) {
loadCellWeight = 0; // Set weight to zero if negative
}
// Determine the fullness status based on the current cylinder size
int fullnessStatus = determineFullness(loadCellWeight, currentCylinderSize);
// Display weight in kilograms on LCD with two decimal places
lcd1.setCursor(0, 1); // Move to the second line of LCD1
lcd1.print("Weight: ");
lcd1.print(loadCellWeight, 2); // Display weight with 2 decimal places
lcd1.print(" kg "); // Add spaces to clear any residual characters
// Display fullness status on LCD2
lcd2.setCursor(9, 0);
lcd2.print(fullnessLabels[fullnessStatus]);
// Activate RGB LED based on fullness status
activateRGBLED(fullnessStatus);
// ... (rest of your loop code)
}
// Function to determine fullness status based on cylinder size
int determineFullness(float weight, float cylinderSize) {
float threshold = cylinderSize * (gasAlertThreshold / 100.0);
if (weight <= (threshold / 2)) {
return 0; // Empty
} else if (weight <= threshold) {
return 1; // Half-filled
} else {
return 2; // Full
}
}
// Function to activate RGB LED based on fullness status
void activateRGBLED(int fullnessStatus) {
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
if (fullnessStatus == 0) {
digitalWrite(redPin, HIGH); // Red for empty
} else if (fullnessStatus == 1) {
digitalWrite(bluePin, HIGH); // Blue for half-filled
} else {
digitalWrite(greenPin, HIGH); // Green for full
}
}