#include <HX711.h>
// Define the pins for Channel A
const int LOADCELL_DOUT_PINA = 15;
const int LOADCELL_SCK_PINA = 14;
// Define the pins for Channel B
const int LOADCELL_DOUT_PINB = 17;
const int LOADCELL_SCK_PINB = 16;
// Initialize the HX711 library for Scale A
HX711 scaleA;
// Initialize the HX711 library for Scale B
HX711 scaleB;
// Define the calibration factor for Scale A (replace with your own calibration factor)
float calibrationFactorA = -459.542; // replace this value
// Define the calibration factor for Scale B (replace with your own calibration factor)
float calibrationFactorB = -459.542; // replace this value
void setup() {
Serial.begin(57600);
Serial.println("Initializing Scale A");
scaleA.begin(LOADCELL_DOUT_PINA, LOADCELL_SCK_PINA);
Serial.println("Initializing Scale B");
scaleB.begin(LOADCELL_DOUT_PINB, LOADCELL_SCK_PINB);
}
void loop() {
Serial.println(scaleA.get_units(), 1);
Serial.println(scaleB.get_units(), 1);
delay(1000);
// Calibrate Scale A
Serial.println("Calibrating Scale A...");
long readingA = 0;
for (int i = 0; i < 10; i++) {
readingA += scaleA.read();
delay(50);
readingA /= 10;
scaleA.set_scale(calibrationFactorA); // replace with your own calibration factor
scaleA.tare();
Serial.println("Calibration Scale B - complete.");
// Calibrate Scale B
Serial.println("Calibrating Scale B...");
long readingB = 0;
for (int i = 0; i < 10; i++) {
readingB += scaleB.read();
delay(50);
readingB /= 10;
scaleB.set_scale(calibrationFactorB); // replace with your own calibration factor
scaleB.tare();
Serial.println("Calibration Scale A - complete.");
// Read and display the weight for Scale A
Serial.print("Weight on Scale A: ");
Serial.print(scaleA.get_units(), 2);
Serial.print(" kg");
// Read and display the weight for Scale B
Serial.print("Weight on Scale B: ");
Serial.print(scaleB.get_units(), 2);
Serial.println(" kg");
delay(1000);
}
}
}