#include <HX711.h>
// Define the pins for the HX711 module
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
HX711 scale;
void setup() {
Serial.begin(9600);
// Initialize the scale
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// Set the scale gain
// This is set according to your load cell's specifications
// The default value is 128. You can try different values
// to improve the measurement accuracy.
scale.set_scale(128);
// Tare the scale to remove any initial load
scale.tare();
}
void loop() {
// Read the raw value from the load cell
long rawValue = scale.read();
// Get the weight in grams
float grams = scale.get_units();
// Print the raw value and weight
Serial.print("Raw Value: ");
Serial.print(rawValue);
Serial.print(", Weight: ");
Serial.print(grams);
Serial.println(" g");
delay(1000); // Wait for one second before taking the next measurement
}