0
\$\begingroup\$

I am trying to calibrate four 50kg Weight Sensors with Arduino's HX711 Amplifier AD Module. I am getting a variable range of errors. I am using this video as a reference link below. It shows me use a formula such as

Current Value= 0.8* Current value + 0.2* Sensor reading // which is taking an average of the senor

final value = ((Current Value-Actual Sensor Value) divided by reading of known weight multiplied by the known weight value

such as below,

known weight=100g

reading of known weight=2155

val = 0.8 * val + 0.2 *scale.read();

val_g=((val-159958)/2155.f*100);

The problem I am having is if I put the weight of 100 to the test the value, it keeps on changing up and down of the actual weight such as 103...101....100...102..100...97...99...103...102

I did try many attempts of calibrating but it always has that fluctuation in weight

My code:

//Oled Display
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "HX711.h"
#define WIRE Wire
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);

//Weight
const int LOADCELL_DOUT_PIN = 3;
const int LOADCELL_SCK_PIN = 2;
const int Button_PIN = 5;

unsigned long timer ;


HX711 scale;

void setup() {
  //Weight
  Serial.begin(9600);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  //For Display
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
  display.setTextSize(1.5);
  display.setTextColor(SSD1306_WHITE);

  while(1){
  display1();
  loop();
}
}
//Weight
long val=0;
float reads=0;
float val_g=0;
float val_gm=0;
float val_lb=0;
float zero;

void loop() {
  //val=scale.read();
  val = 0.8 * val + 0.2 *scale.read() ; //averaging
  val_g=((val-159958)/2155.f*100);
  //val_g=((val-166351)/2116.f*100);

 
pinMode(Button_PIN, INPUT_PULLUP);
   byte buttonState = digitalRead(Button_PIN);
  if (buttonState  == 0 && val_g>0|| val_g<0){
    zero=val_g;}
  
  
  val_gm=val_g - zero;
  val_lb= ((val_gm)*0.0022);
  
  Serial.print("Weight in G=");
  Serial.println(val_gm);
  
  Serial.println(val);

  
  Serial.print("Weight in Lb=");
  Serial.println(val_lb);
  }

void display1(){
  val_g;
  display.setCursor(10,0);
  display.print("Gram:");
  display.print(val_gm);
  display.setCursor(10,10);
  display.print("Pound:");
  display.print(val_lb);
  display.setCursor(6,6);
  display.display();
  display.clearDisplay();  
  }

Load Cell calibration for reference

\$\endgroup\$
2
  • \$\begingroup\$ Do you see the same fluctuations if you do just "scale.read()"? Is your "averaging" routine throwing you off? \$\endgroup\$ Commented Jul 11, 2023 at 20:19
  • \$\begingroup\$ yes I see the same fluctuations with scale.read(). I don't get any constant reading,and I thought that's the reason we are doing the averaging. \$\endgroup\$ Commented Jul 11, 2023 at 20:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.