Hi All
I am programming my Arduino with the following code. The reading of the scale when there is no weight is -404.6kg.
When I add weight, ie 3kg the increase is correct, add another 3kg and the increase is 3kg and so on.
I want to add a line to my code that will add the 404.6 to the weight value from the load cell. How would I do that
#include "HX711.h"
#define LOADCELL_DOUT_PIN 23
#define LOADCELL_SCK_PIN 22
HX711 scale;
float calibration_factor = -20600;
void setup() {
Serial.begin(9600);
// Serial.println("HX711 calibration sketch");
// Serial.println("Remove all weight from scale");
// Serial.println("After readings begin, place known weight on scale");
// Serial.println("Press + or a to increase calibration factor");
// Serial.println("Press - or z to decrease calibration factor");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}
void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1);
Serial.print(" Kgs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
delay(1000);
if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 10;
elseif(temp == '-' || temp == 'z')
calibration_factor -= 10;
}
}
its unclear because it looks like you already did all that coupled with unclear variable names.
you need 2 things normally:
1) the reading when there is no weight on the scale. this looks like line 21 (??) or related to it ??
and
2) the tare value, which is another offset (usually used like if you wanted to weigh grains of sand, you need a bucket to put the sand in, but the bucket's weight isnt important, so tare sets the output to 0.0 when the bucket is on the scale but no sand).
and you seem to have both.
if you already have all the info as I think you do, just adjust it on line 31? Which value is the actual reading/weight?!
otherwise it looks like you are doing the right stuff... take readings for a couple of seconds, get the average reading or even make a 'deadband' for it at 0.0 with nothing on it. Add that to all the output. Handle the tare. Handle the units display. And LOTS of people use non metric values by the way. I use grains a lot: its what all the data is in for reloading. Jewelers use carats. Not everyone is in a lab, and some disciplines are stuck in units from the dark ages.