Connecting load cell with HX711 for weight measurement

Hello i am new in Arduino and Recently i bought one load sensor of 10 kg and HX711 for simple weight measurement of objects. I searched in internet for the connectivity of HX711 with load cell and tried to measure the weight but i am not getting the measures in kgs. Anyone here who can help me with this problem?

I have this code and it doesn't works for me. It is giving measurement in some different unit. I want it in kg.

#include "HX711.h"

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

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

void setup() {
  Serial.begin(38400);
  Serial.println("HX711 Demo");

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());			// print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));  	// print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight (not set yet)

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);	// print the average of 5 readings from the ADC minus tare weight (not set) divided 
						// by the SCALE parameter (not set yet)  

  scale.set_scale(2280.f);                      // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();				        // reset the scale to 0

  Serial.println("After setting up the scale:");

  Serial.print("read: \t\t");
  Serial.println(scale.read());                 // print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));       // print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight, set with tare()

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);        // print the average of 5 readings from the ADC minus tare weight, divided 
						// by the SCALE parameter set with set_scale

  Serial.println("Readings:");
}

void loop() {
  Serial.print("one reading:\t");
  Serial.print(scale.get_units() * 29, 1);
  Serial.print("\t| average:\t");
  Serial.println(scale.get_units(10), 1);

  scale.power_down();			        // put the ADC in sleep mode
  delay(500);
  scale.power_up();
}

From Google HX711 Arduino this came up:How to get kilogram from hx711? and the proper calibration. · Issue #70 · bogde/HX711 · GitHub

You have to calibrate it with known Weights and scale it yourself.
With the Library for the HX711 , there are examples which show you how to scale it , zero it and so on.

I am not getting how to calibrate using the above code. What are the factors that will help me to calibrate? I

In the examples there is a calibration routine where you calculate a scale factor.
You then put that factor in your program

Run the examples !!

Not able to do. Totally confused. Someone explain me from the beginning.

Have you looked at and run the examples provided with the library ?? Is there a specific problem there ??
File/examples ...

One explains how to get a scale factor by calibrating the scale With weights. Another then tells you where to put this scale factor into an example sketch ( scale.set_scale()) so that it reads in kg or whatever you want and is accurate .

That is from the beginning . If you are very new to Arduino , I would suggest playing with the provided examples for analog/digital and so on , to get up to speed on coding, before playing with this .

There are also some good examples Mr Google provides too , such as : Load Cell Amplifier HX711 Breakout Hookup Guide - SparkFun Learn

ashishpandey:
I am not getting how to calibrate using the above code. What are the factors that will help me to calibrate?

A: Calibration Procedures of Load Cell
1. If your load cell is looked like the following, then connect it with the HX711 Module as per Figure of Step-2.
loadCell.png
Figure-1: Pictorial view of Load Cell

2. Look at the datasheet of you Load Cell or on the label on the load cell and identify the excitation wires (IN: E+, E1) and the signal Wires (OUT: OUT+, OUT-1/S+, S-). Connect these 4 wires with HX711 Module as per following diagram of Fig-2. Connect the shield wire (if any) of the load cell with GND-pin of Arduino UNO. Also connect 5V and GND of UNO with HX711 Module.
loadcellCalib.png
Figure-2: Connection diagram among UNO, Load Cell, and HX711

3. Mount your load cell on a firm Bench/Table using screws and holes of the load cell near the cable side (Fig-1).

4. Place 500 gm weight at the cantilever end (side) of the load cell.

5. Upload the program in the UNO and record the value (the counts in hex that are coming from HX711 Module and is proportional to weight) as C1 from the Serial Monitor.

unsigned long x = 0x12345600, y, sum;
unsigned long dataArray[10];
int j = 0;
void setup()
{
  Serial.begin(9600);

  pinMode(A0, OUTPUT);  //SCK line
  pinMode(A1, INPUT); //data line
}

void loop()
{

  for (int j = 0; j < 10; j++)
  {
    digitalWrite(A0, LOW);//SCK is made LL
    while (digitalRead(A1) != LOW)
      ;//if (digitalRead(A1) == LOW) //conversion done
    {
      for (int i = 0; i < 24; i++)  //read 24-bit data from HX711
      {
        clk();      //generate CLK pulse to get MSB-it at A1-pin
        bitWrite(x, 0, digitalRead(A1));
        x = x << 1;
      }
      clk();
      Serial.println(x, HEX);
      y = x;
      x = 0x12345600;    //12345678 is the debug value
      delay(200);
    }
    dataArray[j] = y;
  }

  Serial.println("===averaging process=========");
  for (j = 0; j < 10; j++)
  {
    Serial.println(dataArray[j], HEX);
  }

  sum = 0;

  for (j = 0; j < 10; j++)
  {
    sum += dataArray[j];
  }
  Serial.print("Average Count = ");
  sum = sum / 10;
  Serial.println(sum, HEX);
  // while (1);
//  showWeight();
  delay(2000);
}

void clk()
{
  digitalWrite(A0, HIGH);
  digitalWrite(A0, LOW);
}

6. Place 1500 gm weight at the cantilever side of the load cell. Record the counts as C2.

7. Based on these two known point responses: A(500 gm, C1) and B(1500 gm, C2), we can find the equation for the unknown point C(W, C); where, C is the unknown counts for the unknown load W as:

(W-1500)/(C-C2)=(1500-500)/(C2 - C1)

 W= m*C- k  //m and k are known points called gain and offset of the system; finding these two values is known as [b]Calibration[/b]
 float W=(float)m*C- k;  //W is in gm
 W=(float)W/1000.00;    //W is in kg
 Serial.println(W, 3);       //weight will be shown as xx.xxx kg

B: Known/Unknown weight acquisition and display
Now, place upload the following sketch. Place 500 gm, 1000 gm, 1500 gm, and unknown_weight on the load cell and check that the Serial Monitor shows correct weight with error of +/- 2 gm (or check for the error tolerance/accuracy of your load cell).

unsigned long x = 0x12345600, y, sum;
unsigned long dataArray[10];
int j = 0;
void setup()
{
  Serial.begin(9600);

  pinMode(A0, OUTPUT);  //SCK line
  pinMode(A1, INPUT); //data line
}

void loop()
{

  for (int j = 0; j < 10; j++)
  {
    digitalWrite(A0, LOW);//SCK is made LL
    while (digitalRead(A1) != LOW)
      ;//if (digitalRead(A1) == LOW) //conversion done
    {
      for (int i = 0; i < 24; i++)  //read 24-bit data from HX711
      {
        clk();      //generate CLK pulse to get MSB-it at A1-pin
        bitWrite(x, 0, digitalRead(A1));
        x = x << 1;
      }
      clk();
      Serial.println(x, HEX);
      y = x;
      x = 0x12345600;    //12345678 is the debug value
      delay(200);
    }
    dataArray[j] = y;
  }

  Serial.println("===averaging process=========");
  for (j = 0; j < 10; j++)
  {
    Serial.println(dataArray[j], HEX);
  }

  sum = 0;

  for (j = 0; j < 10; j++)
  {
    sum += dataArray[j];
  }
  Serial.print("Average Count = ");
  sum = sum / 10;
  Serial.println(sum, HEX);
  // while (1);
 showWeight();
  delay(2000);
}

void showWeight()
{
  //eneter weight calculating equation here from Step-7
}
void clk()
{
  digitalWrite(A0, HIGH);
  digitalWrite(A0, LOW);
}

BTW: HX711.h Library will offer you a different way of calibrating the sensor/input-device. You are also urged to practice the examples of the HX711.h Library

loadcellHx711.png

loadCell.png

Hi,
Can you post a picture of your project so we can see your component layout and how you have your loadcell mounted.

Thanks.. Tom... :slight_smile: