#include <Arduino.h>
#include "soc/rtc.h"
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 2;
HX711 scale;
void setup() {
Serial.begin(115200); // Initialize Serial communication
while (!Serial); // Wait for the Serial connection to establish (if required)
delay(2000); // Allow Serial Monitor to initialize
rtc_cpu_freq_config_t config;
rtc_clk_cpu_freq_get_config(&config);
rtc_clk_cpu_freq_set_config_fast(&config); // Retain clock frequency
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); // Initialize HX711
// Set the scale factor here (calculated during calibration)
scale.set_scale(419);
scale.tare(); // Zero the scale to remove any offset
Serial.println("Scale initialized. You can now measure weight.");
}
void loop() {
if (scale.is_ready()) { // Ensure HX711 is ready
float weight = scale.get_units(10); // Average of 10 readings for stability
Serial.print("Measured Weight: ");
Serial.print(weight);
Serial.println(" grams");
} else {
Serial.println("HX711 not found. Please check connections.");
}
delay(1000); // Wait 1 second before taking another reading
}