#include <HX711.h>
// Define HX711 pins
const int HX711_DOUT = 4; // Data Out pin
const int HX711_SCK = 5; // Clock pin
// Initialize HX711
HX711 scale;
// Calibration factor: Adjust this based on your calibration results.
float calibration_factor = 420.0; // Example factor
void setup() {
Serial.begin(115200); // Start serial communication
scale.begin(HX711_DOUT, HX711_SCK); // Initialize the scale
scale.set_scale(calibration_factor); // Set the calibration factor
scale.tare(); // Tare the scale (reset to zero)
Serial.println("Scale is ready");
}
void loop() {
long T1=millis();
// Read raw weight
long raw_value = scale.read();
// Read weight in kg
float weight = scale.get_units();
// Output raw and calibrated weights to serial monitor
Serial.print("Raw value: ");
Serial.print(raw_value);
Serial.print(" | Weight: ");
Serial.print(weight);
Serial.println(" kg");
long T1_exe=millis()-T1;
Serial.print("T1exe = ");
Serial.println(T1_exe);
delay(500); // Small delay between readings
}