HX711 loadcell crashing as soon as weight is placed on it

Pulling my hair out on this. I am trying to build a digital weight scale with an arduino, loadcell and HX711 module.

I am following this tutorial: How STRAIN GAUGE Works | Precision SCALE With Arduino - YouTube
I am using this HX711 library: GitHub - olkal/HX711_ADC: Arduino library for the HX711 24-bit ADC for weight scales

When trying to measure weight, the program crashes after a few seconds, sometimes in less than a second.

The issue I am having is during the calibration the script just resets after a few reads. If I do not place anything on the scale during calibration, and just put in a low amount, then the program runs fine, but then crashes as soon as anything is placed on the scale.

Here is what the output is for the calibration example sketch:

Starting...
Startup is complete
***
Start calibration:
Place the load cell an a level stable surface.
Remove any load applied to the load cell.
Send 't' from serial monitor to set the tare offset.
Tare complete
Now, place your known mass on the loadcell.
Then send the weight of this mass (i.e. 100.0) from serial monitor.
Known mass is: 213.00
New calibration value has been set to: 432.60, use this as calibration value (calFactor) in your project sketch.
Save this value to EEPROM adress 0? y/n
Value 432.60 saved to EEPROM address: 0
End calibration
***
To re-calibrate, send 'r' from serial monitor.
For manual edit of the calibration value, send 'c' from serial monitor.
***
Load_cell output val: 213.00
Load_cell output val: 213.01
Load_cell output val: 213.02
Load_cell output val: 213.02
Load_cell output val: 213.03
Load_cell output val: 213.03
Load_cell output val: 213.05

Starting...
Startup is complete
***
Start calibration:
Place the load cell an a level stable surface.
Remove any load applied to the load cell.
Send 't' from serial monitor to set the tare offset.

It reads a few times and then resets.

Here is output for the "Testing" example sketch:

I pushed down on the scale and shortly after it crashes

Starting...
Startup is complete
Calibration value: 696.00
HX711 measured sampling rate HZ: 11.23
HX711 measured settlingtime ms: 1426
Note that the settling time may increase significantly if you use delay() in your sketch!
Load_cell output val: 0.01
Load_cell output val: -0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: -0.02
Load_cell output val: 17.04
Load_cell output val: 145.96
Load_cell output val: 285.60
Load_cell output val: 423.75
Load_cell output val: 444.50
Load_cell output val: 428.34
Load_cell output val: 377.06
Load_cell output val: 343.03
Load_cell output val: 322.22
Load_cell output val: 334.14
Load_cell output val: 360.46
Load_cell output val: 410.86
Load_cell output val: 461.09
Load_cell output val: 512.24
Load_cell output val: 519.79
Load_cell output val: 377.77
Load_cell output val: 172.20
Load_cell output val: 7.33
Load_cell output val: 0.02
Load_cell output val: 0.04
Load_cell output val: 0.04
Load_cell output val: 0.04
Lo

Does anyone know what could be causing this?

Thanks in advance!

I think it's line 15001 and line 47985 of your code. If you fix those lines then everything should work fine.

Now how did I know line 15001 and line 47985 of your code is the issue? I don't.

Help us help you.

Hi, thanks for the reply, here's some additional info:

Microcontroller: Arduino Uno

Schematic:

Testing code:

/*
   -------------------------------------------------------------------------------------
   HX711_ADC
   Arduino library for HX711 24-Bit Analog-to-Digital Converter for Weight Scales
   Olav Kallhovd sept2017
   -------------------------------------------------------------------------------------
*/

/*
   Settling time (number of samples) and data filtering can be adjusted in the config.h file
   For calibration and storing the calibration value in eeprom, see example file "Calibration.ino"

   The update() function checks for new data and starts the next conversion. In order to acheive maximum effective
   sample rate, update() should be called at least as often as the HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS.
   If you have other time consuming code running (i.e. a graphical LCD), consider calling update() from an interrupt routine,
   see example file "Read_1x_load_cell_interrupt_driven.ino".

   This is an example sketch on how to use this library
*/

#include <HX711_ADC.h>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif

//pins:
const int HX711_dout = 4; //mcu > HX711 dout pin
const int HX711_sck = 5; //mcu > HX711 sck pin

//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);

const int calVal_calVal_eepromAdress = 0;
unsigned long t = 0;

void setup() {
  Serial.begin(57600); delay(10);
  Serial.println();
  Serial.println("Starting...");

  float calibrationValue; // calibration value
  calibrationValue = 696.0; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266) || defined(ESP32)
  //EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch this value from eeprom
#endif
  //EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch this value from eeprom

  LoadCell.begin();
  //LoadCell.setReverseOutput();
  unsigned long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time
  boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
  LoadCell.start(stabilizingtime, _tare);
  if (LoadCell.getTareTimeoutFlag()) {
    Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
  }
  else {
    LoadCell.setCalFactor(calibrationValue); // set calibration factor (float)
    Serial.println("Startup is complete");
  }
  while (!LoadCell.update());
  Serial.print("Calibration value: ");
  Serial.println(LoadCell.getCalFactor());
  Serial.print("HX711 measured conversion time ms: ");
  Serial.println(LoadCell.getConversionTime());
  Serial.print("HX711 measured sampling rate HZ: ");
  Serial.println(LoadCell.getSPS());
  Serial.print("HX711 measured settlingtime ms: ");
  Serial.println(LoadCell.getSettlingTime());
  Serial.println("Note that the settling time may increase significantly if you use delay() in your sketch!");
  if (LoadCell.getSPS() < 7) {
    Serial.println("!!Sampling rate is lower than specification, check MCU>HX711 wiring and pin designations");
  }
  else if (LoadCell.getSPS() > 100) {
    Serial.println("!!Sampling rate is higher than specification, check MCU>HX711 wiring and pin designations");
  }
}

void loop() {
  static boolean newDataReady = 0;
  const int serialPrintInterval = 500; //increase value to slow down serial print activity

  // check for new data/start next conversion:
  if (LoadCell.update()) newDataReady = true;

  // get smoothed value from the dataset:
  if (newDataReady) {
    if (millis() > t + serialPrintInterval) {
      float i = LoadCell.getData();
      Serial.print("Load_cell output val: ");
      Serial.println(i);
      newDataReady = 0;
      t = millis();
    }
  }

  // receive command from serial terminal, send 't' to initiate tare operation:
  if (Serial.available() > 0) {
    char inByte = Serial.read();
    if (inByte == 't') LoadCell.tareNoDelay();
  }

  // check if last tare operation is complete:
  if (LoadCell.getTareStatus() == true) {
    Serial.println("Tare complete");
  }

}

Note: there are no error messages in the console, the program loop just suddenly stops

Sometimes, when trying to upload the sketch, I get this error:

avrdude: stk500_paged_load(): (a) protocol error, expect=0x10, resp=0xe6
avrdude: stk500_cmd(): programmer is out of sync
avr_read(): error reading address 0x0000
    read operation not supported for memory "flash"
avrdude: failed to read all of flash memory, rc=-2
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x98
Failed uploading: uploading error: exit status 1

But usually if I reset the arduino then the sketch uploads fine

1 Like

It won't let me post multiple images in a single post. Here's an image of what the actual project looks like:

1 Like

Reads like the Uno has a hardware issue. Does the issue happen when you use your spare Uno or a different MCU?

Unfortunately I only own 1 arduino currently. I cleared the EEPROM and the error seems to have gone. Other sketches are also working fine.

The issue with the scale crashing still remains though :frowning:

Here's another sketch from a different library I tried:
(GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.)

#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;

HX711 scale;

void setup() {
  Serial.begin(57600);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  Serial.println("Start reading scale");
}

void loop() {

  if (scale.is_ready()) {
    long reading = scale.read();
    Serial.print("HX711 reading: ");
    Serial.println(reading);
  } else {
    Serial.println("HX711 not found.");
  }

  delay(1000);
  
}

And the output:
Program doesn't crash this time, since there's an is_ready() check before reading.

Start reading scale
HX711 not found.
HX711 reading: 451846
HX711 reading: 451820
HX711 reading: 451875
HX711 reading: 451858
HX711 reading: 451872
HX711 reading: 451855
Start reading scale
HX711 not found.
HX711 not found.
HX711 not found.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.