#include <ESP32Servo.h>
#include "HX711.h"
const int servoPin1 = 21;
const int servoPin2 = 19;
const int servoPin3 = 18;
const int servoPin4 = 5;
// Define the pins connected to the HX711
const int LoadCellDoutPin = 23;
const int LoadCellSckPin = 22;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
HX711 scale;
void setup() {
Serial.begin(9600);
scale.begin(LoadCellDoutPin, LoadCellSckPin);
servo1.attach(servoPin1, 500, 2400);
servo2.attach(servoPin2, 500, 2400);
servo3.attach(servoPin3, 500, 2400);
servo4.attach(servoPin4, 500, 2400);
}
void loop() {
// Move each servo to the desired position
servo1.write(45);
servo2.write(90);
servo3.write(135);
servo4.write(180);
// Delay to keep the servos in position
delay(3000);
// Return each servo to its initial position (0 degrees)
servo1.write(0);
servo2.write(0);
servo3.write(0);
servo4.write(0);
// Delay to keep the servos in position
delay(1000);
if (scale.is_ready()) {
long weight = scale.get_units(); // Get weight in grams
Serial.print("Weight: ");
Serial.print(weight*100/42);
Serial.println(" grams");
} else {
Serial.println("Error: Unable to detect HX711. Please check your connections.");
}
delay(1000); // Delay for one second (adjust as needed)
}