Loadcell + HX711 (80Hz mode) and noisy readings to UNO

Hello,

I'm designing - electronic part -for filling machine using UNO + BOSCH loadcell + HX711

Problem is that readings are fluctuating (up/down) while filling so this is affecting accuracy of threshold close gate decision.

I'm using HX711 lib from: GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.
loadcell from: http://uk.bosche.eu/product.php?prodid=599&catid=474

The below code is used for UNO:

#include "HX711.h"
float val = 0;
float wht = 0;

int Wready = 3;
int Wprcnt = 7;
int Wsel   = 9;
int Wsels  = 0;
int RST   = 11;

float prc = 0;

HX711 scale(A1, A2, 32);		  // set gain to 32 so loadcell connected to channel B

void setup() {

  pinMode(Wsel, OUTPUT);
  pinMode(Wready, OUTPUT);
  pinMode(Wprcnt, OUTPUT);
  
  pinMode(A4, INPUT);
  
  Serial.begin(9600);
  Serial.println("Init.");

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());	
  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(4)); 
  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(4));
  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(4), 1);

  scale.set_scale(77);       
  scale.tare();

  Serial.println("After setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());           
  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(4));    
  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(4));		
  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(4), 1);       
  Serial.println("Readings:");

}

void loop() {

  // Check if weighing hopper closed, then reset the loadcell reading
  if(analogRead(A4)>650){
    scale.tare();
  }
  
  
  
  wht = (scale.get_units(2));
  Serial.print("\t");
  Serial.println((wht));

  // Weight selection button
  Wsels = digitalRead(Wsel);

  if(Wsels == HIGH){
    val = 462;
    prc = 0.3;
  }else{
    val = 955; 
    prc = 0.5;
  }

  
  if((wht <= (val)) && (wht > (val*prc))){           // close the feeding hopper gate by 50% when weighing hopper filled with prc% of required weight (to get higher accurate fill)
    digitalWrite(Wready, LOW);
    digitalWrite(Wprcnt, HIGH);
  }else if((wht < (val))){
    digitalWrite(Wready, LOW);
    digitalWrite(Wprcnt, LOW);
  }else{
    digitalWrite(Wready, HIGH);
    digitalWrite(Wprcnt, HIGH);
  }
}

after recording data from loadcell, I got this chart:

I just need to smooth data received from load cell to get more accurate weighing as least error I could get now is +-10grams and this is too much error.

Also after searching, found some techniques like moving-average filters and analog adaptive filters that should help me get more smoothed readings, but I've no idea how to implement any of them.

Please advise.

Regards

Use the scope to monitor the supply voltage. Capacitors will help reducing noise.

Thanks for reply. I'm using http://www.amazon.com/gp/aw/d/B00D7CWSCG for power, so I believe the issue not from PS.

Regards

The sensor should have a cap close to power terminals.

I put HX711 between two parallel steel plates. Sensor cable is sheilded I think.

Regarding your original question (about averaging), you are currently averaging a block of four consecutive values in the get_value and get_units functions. Why not average more values; for example, what happens if you use get_units(128) instead of your get_units(4)....or some other number larger than 4...

Also, presumably you've done this, but googling arduino moving average brings up lots of examples of how smoothing, moving, etc can be implemented, if you want or need to get more complicated than just averaging blocks of consecutive values.

PS: It is interesting that most of the largest "noise" occurs immediately before changes in the slope of the line in your graph. Are you sure that the filling machinery or something else isn't causing some vibrations that the load cell picks up?

Thanks Dave,

For increasing the average number to be more than 4, it will take more time to get the result for every loop - reading - so error will be increased too much, as in filling applications every milliseconds of flow the weight will change, so I need to read the live values as fast as possible.
Also tried to not take average - just get the current reading - the variation got increased in crazy way.

I already searched and found libraries for Arduino averaging but also it will take time to process within every loop which causes error increase so I need it in hardware - I think will be faster than SW [please correct me if wrong].

I'm sure the big issue is mechanical vibrations so already we are using some kind of leather washers trying to eliminate that vibrations effects. For feeding gate opening/closing, I'm using stepper NEMA23 [driver TB6560 V1] with 20cm arm.

..add that 10uF cap (and a small ceramic) - close to the HX711
The stepper makes electrical noise

Smoothing (sumx + reading(1-x)) is too slow? Maybe you need a higher speed ADC. Or, how about a low-pass filter on the load cell output. Better mechanical isolation sounds like the best solution.

Thanks knut and Dave

I'll add these capacitors but please let me know where from HX711 ? power pins ?

Dave, I found some libraries for averaging, so I'll test with this one ( Microsmooth ) then return back to you with results. Also LPF should be with which cutoff frequency ?

Regards

Well, what frequency is most of the so-called "noise" at? Select your LPF cutoff so most of it is attenuated, if that's possible.

..caps at power pins.

After applying moving average on excel data [interval of 2] showing these good results.

Below sample of some row data, please advise which is most accurate interval ?

0.62
1.22
-1.17
1.29
-0.66
-0.38
1.44
-2.18
1.22
-0.58
-3.87
12.42
-19.65
19.97
-15.82
6.78
-2.25
-2.14
5.64
-8.21
11.43
-18.55
25.9
-34.32
39.75
-37.22
27.92
-15.66
2
20.17
-6.09
80.78
30.92
97.4
71
96.73
113
107.57
137.45
127.23
157.74
151.95
168.83
175.95
187.66
186.52
209.45
202.6
229.21
220.81
241.45
247.03
254.03
264.83
270.55
283.21
290.34
296.84
309.01
319.74
325.38
334.96
343.6
352.74
363.23
363.52
387.78
379.66
405.48
397.65
422.22
412.12
438.05
431.65
455.14
445.74
474.58
466.65
489.95
486.79
508.38
499.87
526
517.31
546.01
529.9
568.87
550.3
585.57
558.06
612.7
567.71
634.86
585.42
638.57
599.91

I'll start soon on applying power caps + moving average + LPF practically.

Kind regards

Hi,

Old post, but still current problem.
Did you succeed in averaging the HX711 readings ? What library, etc ... ?

If yes, could you share your results ?

Thanks,

knut_ny:
Use the scope to monitor the supply voltage. Capacitors will help reducing noise.

No, you haven't looked the graph, the signal has oscillations in it (mechanical resonance),
nothing to do with the supply.

tk5ep:
Hi,

Old post, but still current problem.
Did you succeed in averaging the HX711 readings ? What library, etc ... ?

If yes, could you share your results ?

Thanks,

I stopped developing that application for some time. But found - after searching - that only way to apply moving average for HX readings. You can try that arduino lib. GitHub - asheeshr/Microsmooth: A lightweight and fast signal smoothing library for the Arduino platform.

If you got better results, please post here.Regards