#include "HX711.h"
// Load Cell Pins
#define LOADCELL_DOUT_PIN 32 // GPIO pin connected to HX711 DT
#define LOADCELL_SCK_PIN 33 // GPIO pin connected to HX711 SCK
// LED Pins
#define RED_LED_PIN 23 // GPIO pin connected to Red LED
#define GREEN_LED_PIN 22 // GPIO pin connected to Green LED
// Load Cell Threshold
#define WEIGHT_THRESHOLD 25.0 // 25 kg
// Blinking parameters
#define BLINK_DELAY 500 // Delay for blinking (in milliseconds)
HX711 scale;
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Initialize Load Cell
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(4452); // Set the correct calibration factor for your load cell
// Set up LED Pins
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
// Turn off both LEDs initially
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW);
}
void loop() {
// Measure weight using the load cell
float weight = scale.get_units(10); // Get the average of 10 readings
// Control LEDs based on weight
if (weight > WEIGHT_THRESHOLD) {
// Weight above threshold: Blink Red LED
blinkLED(RED_LED_PIN);
Serial.println("Weight above threshold, Red LED blinking");
} else {
// Weight below threshold: Blink Green LED
blinkLED(GREEN_LED_PIN);
Serial.println("Weight below threshold, Green LED blinking");
}
// Print weight to Serial Monitor
Serial.print("Weight: ");
Serial.print(weight);
Serial.println(" kg");
delay(1000); // Delay for stability
}
void blinkLED(int ledPin) {
digitalWrite(ledPin, HIGH); // Turn on LED
delay(BLINK_DELAY); // Wait for a while
digitalWrite(ledPin, LOW); // Turn off LED
delay(BLINK_DELAY); // Wait for a while
}