#include <HX711.h>
#include <Servo.h>
#define calibration_factor 7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define LOADCELL_DOUT_PIN 3
#define LOADCELL_SCK_PIN 2
Servo s1;
float val = 0 ;
HX711 scale;
void setup() {
Serial.begin(9600);
Serial.println("HX711 scale demo");
s1.attach(9);
s1.write(90);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
Serial.println("Readings:");
}
void loop() {
Serial.print("Reading: ");
//Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
val=scale.get_units();
Serial.print(val);
Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
if (val > 0.1)
{
s1.write(90);
delay(2000);
}
else
{
s1.write(0);
}
}