#include <HX711.h>
#include <Servo.h>
//#define calibration_factor 7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define calibration_factor 420
#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 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 value: ");
//Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
val = scale.get_units();
Serial.print(val);
Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
// Control servo
if (val > 0.1)
{
s1.write(90);
delay(2000);
}
else
{
s1.write(0);
}
}
/*
// Calibrition code
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 3;
const int LOADCELL_SCK_PIN = 2;
HX711 scale;
void setup() {
Serial.begin(57600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}
void loop() {
if (scale.is_ready()) {
scale.set_scale();
Serial.println("Tare... remove any weights from the scale.");
delay(5000);
scale.tare();
Serial.println("Tare done...");
Serial.print("Place a known weight on the scale...");
delay(5000);
long reading = scale.get_units(10);
Serial.print("Result: ");
Serial.println(reading);
}
else {
Serial.println("HX711 not found.");
}
delay(1000);
} */