#include <HX711.h>
#include <ESP32Servo.h>
#define calibration_factor 3196.6 //Calibrated for kg
// Define the GPIO pins for ESP32
#define LOADCELL_DOUT_PIN 6
#define LOADCELL_SCK_PIN 7
Servo s1; // Servo object
float val = 0;
HX711 scale;
void setup() {
Serial.begin(9600);
Serial.println("HX711 scale demo");
s1.attach(18);
s1.write(90); // Move the servo to the initial position
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(calibration_factor); // Set the calibration factor for kilograms
scale.tare(); // Reset the scale to 0, assuming no weight on it
Serial.println("Readings:");
}
void loop() {
Serial.print("Reading: ");
val = scale.get_units(); // Get the weight in kilograms
Serial.print(val);
Serial.print(" kg");
Serial.println();
if (val < 0.2) //Turns motor if bowl is nearly empty
{
s1.write(90); // Move servo to 90 degrees if weight is low
delay(2000);
}
else
{
s1.write(0); // Move servo back to 0 degrees to prevent over filling
}
}
Loading
esp32-c6-devkitc-1
esp32-c6-devkitc-1