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.

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.

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

