#include <HX711_ADC.h>
#define DOUT 3 // HX711 DOUT pin
#define CLK 2 // HX711 SCK pin
HX711_ADC scale(DOUT, CLK); // Create instance of HX711_ADC
float calibrationFactor = 7050.0; // Initial calibration factor (can be adjusted manually)
float weight;
void setup() {
Serial.begin(9600);
Serial.println("Calibration Process for HX711 Load Cell");
// Initialize the HX711 scale
scale.begin();
scale.start(2000); // Stabilize readings over 2 seconds
scale.setCalFactor(calibrationFactor); // Set the initial calibration factor
// Tare the scale (zero it out)
// scale.tare();
Serial.println("Scale tared. Place a known weight on the scale and adjust the calibration factor.");
}
void loop() {
// Update scale readings
scale.update();
// Get the weight value in kilograms
weight = scale.getData();
// Print the current weight and calibration factor
Serial.print("Weight: ");
Serial.print(weight, 2); // Print the weight with 2 decimal places
Serial.print(" kg, Calibration Factor: ");
Serial.println(calibrationFactor);
// Allow manual adjustment of calibration factor using Serial Monitor
if (Serial.available() > 0) {
char input = Serial.read();
if (input == '+') {
calibrationFactor += 10000; // Increase calibration factor
} else if (input == '-') {
calibrationFactor -= 10000; // Decrease calibration factor
}
scale.setCalFactor(calibrationFactor); // Update the calibration factor
}
delay(500); // Delay for readability
}