How to get more accurate reading out of load cells with HX711

Hello,

I’m currently making an arduino based digital scale with a standard 5kg load cell, a hx711 amp, lcd display, and a few buttons for basic interface now already made that calibration code that stores values in EEPROM but after calibration the weight seems to drift around 1.2Grams over time(for around 2minutes stays there and then fluctuates around 0.03 grams ± how is it possible to fight this?

Thanks for helping here is the code so far:

#include "HX711.h"
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>


#define LCD_ADDRES 0x3F

#define HX711_DT_PIN A1
#define HX711_CLK_PIN A0

LiquidCrystal_PCF8574 lcd(LCD_ADDRES);

// HX711.DOUT  - pin #A1
// HX711.PD_SCK - pin #A0

#define BUTTON0_PIN A2



HX711 scale(HX711_DT_PIN, HX711_CLK_PIN);    // parameter "gain" is ommited; the default value 128 is used by the library


void setup() {

  int error;


  pinMode(BUTTON0_PIN, INPUT_PULLUP);
  
  Serial.begin(115200);
  
  Wire.begin();
  Wire.beginTransmission(0x3F);
  error = Wire.endTransmission();
  Serial.print("Error: ");
  Serial.print(error);

  if (error == 0) {
    Serial.println(": LCD found.");

  } else {
    Serial.println(": LCD not found.");
  } // if

  lcd.begin(16, 2); // initialize the lcd

  lcd.print("Hello LCD");

  scaleCalibrate(100, 25);


  bool Calibrated = EEPROM.read(0);

  if(!Calibrated){
    
    scaleCalibrate(100, 25);

  }

  

  else {

    float CalVal;
    EEPROM.get(1, CalVal);
    scale.set_scale(CalVal);
  }
  
  //scale.set_scale(2280.f);

}

void loop() {
  // put your main code here, to run repeatedly:

  
  lcd.clear();
  
  while(true){
    
    //lcd.setCursor(8,0);

    float Weight = scale.get_units(5);
    long RawVal = scale.read_average(5);
    lcd.clear();
    
    lcd.print("W: ");
    lcd.print(Weight);
    lcd.print(" grams");
    
    lcd.setCursor(0,1);

    lcd.print(RawVal);
    
    scale.power_down();              // put the ADC in sleep mode
    delay(2000);
    scale.power_up();
  }
  
}

long scaleCalibrate(float CalibrationWeight, int AvgTimes){

  float CalVal;
  long CalTareVal;
  long PreCalVal;

  lcd.clear();
  lcd.print("Taring the scale please don't touch it");
  delay(2000);

  scale.tare();
  

  lcd.clear();
  lcd.print("Place the weight");
  lcd.setCursor(0,1);
  lcd.print("and press the button");

  while(digitalRead(BUTTON0_PIN)!= 0);
  
  lcd.clear();
  lcd.print("Starting calibration!");
  
  PreCalVal = scale.get_value(AvgTimes);
  
  Serial.print("PreCalVal: ");
  Serial.println(PreCalVal);

  CalVal = float(PreCalVal) / float(CalibrationWeight);
  
  Serial.print("CalVal: ");
  Serial.println(CalVal);
  
  scale.set_scale(CalVal);

  lcd.clear();
  
  lcd.print("Calibration Done!");

  EEPROM.update(0, 1);
  EEPROM.put(1, CalVal);
  delay(2000);

  
  

}

You didn’t implement the calibration routine as the library author suggested on it’s github page. Why?

Why do you put the HX711 to sleep but not the processor?

Did you read the datasheet? the HX711 needs up to 400ms from reset to stable operation (after wakup a reset is executed) so your sketch never reach a stable state of the HX711.

BTW: +/- 0.03g is extremely accurate.

You could try some of the techniques in this document. If you are really concerned about +/- 0.03 g on a 5 kg scale (or even 1 g), suggest you buy a commercial scale with RS-232 (or other) interface.

A little late to the party here, but load cell components also sometimes take a while to warm up to operation temperature. The two minutes of drift could be how long it takes for the temperature to stabilize.