Today, we will be measuring weight by connecting a Load Cell and HX711 Weight Sensor with Arduino. Weight machines can be found in various stores, and they show the weight when an item is placed on the weighing platform. Thus, we are constructing a weighing device with Arduino and load cells capable of measuring up to 40kg. The Load cell of higher capacity can increase the limit even more.
Required Components:
- Arduino Uno assemblage
- Load sensor (40kg)
- HX711 Load Cell Amplification Module
- LCD with a size of 16 by 2.
- Linking cables
- Cable for connecting via USB
- Prototyping platform for electronic circuits.
- Nuts, screws, structure, and foundation
Load Cell and HX711 Weight Sensor Module:
A load cell is a sensor that converts force or pressure into an electrical signal. The size of the electrical output is directly related to the amount of force applied. Load cells contain strain gauges that bend when pressure is exerted on them. The strain gauge produces an electrical signal when deformed due to a change in its resistance. Typically, a load cell is made up of four strain gauges arranged in a Wheatstone bridge setup. Load cells are available in different capacities such as 5kg, 10kg, 100kg, and others; in this case, we are using a load cell that can measure up to 40kg.
Now the electrical signals generated by Load cell is in few millivolts, so they need to be further amplify by some amplifier and hence HX711 Weighing Sensor comes into picture. HX711 Weighing Sensor Module has HX711 chip, which is a 24 high precision A/D converter (Analog to digital converter). HX711 has two analog input channels and we can get gain up to128 by programming these channels. So HX711 module amplifies the low electric output of Load cells and then this amplified & digitally converted signal is fed into the Arduino to derive the weight.
The load cell is linked to the HX711 Load Cell Amplifier using four wires. The Red, Black, White, and Green/Blue wires are these four wires. Colors of wires may differ slightly between modules. Underneath are the specifics of the connection and a visual representation.
- The E+ terminal is where the RED Wire is attached.
- The E- terminal is where the BLACK Wire is connected.
- The wire that is white is connected to A-.
- The A+ terminal is connected to the GREEN Wire.
Fixing Load Cell with Platform and Base:
You may choose to skip this step by placing the weights directly on the Load cell without a Platform and simply clamping it without securing it to a base. However, it is recommended to use a platform for placing larger items and securing it on a base to ensure stability. Therefore, we must construct a frame or platform for placing objects in order to measure their weight. A foundation is necessary to attach the load cell on top of it using nuts and bolts. In this case, we utilized a sturdy cardboard for the frame to support items and a wooden board as the bottom surface. Once you connect the components according to the circuit diagram, you are all set to proceed.
Circuit Explanation:
Connections for this project are easy and the schematic is given below. 16×2 LCD pins RS, EN, d4, d5, d6, and d7 are connected with pin numbers 8, 9, 10, 11, 12, and 13 of Arduino respectively. HX711 Module’s DT and SCK pins are directly connected with Arduino’s pins A0 and A1. Load cell connections with the HX711 module are already explained earlier and also shown in the below circuit diagram.
Working Explanation:
The operation method of this Arduino Weight Measurement project is simple. Before we delve into specifics, we need to adjust this system to ensure accurate weight measurement. Upon powering on, the system will initiate automatic calibration. To manually calibrate the device, the user can press the push button. We have developed a function named calibrate() with void return type for calibration purposes, please see the code provided below.
To calibrate, look for the LCD display to show when placing a 100 gram weight on the load cell, as illustrated in the picture below. Once the LCD displays “put 100g,” place the 100g weight on the load cell and wait. The calibration process will be complete in a few moments. Following calibration, the user can place any weight up to 40kg on the load cell and view the corresponding value in grams on the LCD screen.
Arduino was employed to regulate the entire process in this project. The load cell detects the mass and provides a voltage signal to the HX711 Load Amplifier Module. HX711 is a 24-bit analog-to-digital converter that boosts and converts the output from the Load cell digitally. Next, the Arduino receives this increased value. Arduino now processes the HX711 output, converting it into weight in grams and displaying it on an LCD screen. A push-button is employed to calibrate the system. We’ve created an Arduino program for the entire process, make sure to review the Code and demo Video located at the conclusion of this tutorial.
Arduino Weighing Scale Code:
The programming aspect of this project may be challenging for those new to coding. For this project, we opted not to utilize any libraries when connecting the HX711 load sensor to Arduino. We have recently adhered to the specifications of HX711 and accompanying documentation. Despite the existence of libraries for this task, you can simply include the library and obtain the weight in just one line of code.
Initially, we incorporated a LCD header file and designated the pins for the LCD. Also, for push-button. Next, some variables were initialized for the purpose of calculation.
#include <LiquidCrystal.h> LiquidCrystal lcd(8, 9, 10, 11, 12, 13); #define DT A0 #define SCK A1 #define sw 2 long sample=0; float val=0; long count=0;
After it, we have created the below function for reading data from the HX711 module and return its output.
unsigned long readCount(void) { unsigned long Count; unsigned char i; pinMode(DT, OUTPUT); digitalWrite(DT,HIGH); digitalWrite(SCK,LOW); Count=0; pinMode(DT, INPUT); while(digitalRead(DT)); for (i=0;i<24;i++) { digitalWrite(SCK,HIGH); Count=Count<<1; digitalWrite(SCK,LOW); if(digitalRead(DT)) Count++; } digitalWrite(SCK,HIGH); Count=Count^0x800000; digitalWrite(SCK,LOW); return(Count); }
After it, we have initialized LCD and give directions to input and output pins in void setup().
void setup() { Serial.begin(9600); pinMode(SCK, OUTPUT); pinMode(sw, INPUT_PULLUP); lcd.begin(16, 2); lcd.print(" Weight "); lcd.setCursor(0,1); lcd.print(" Measurement "); delay(1000); lcd.clear(); calibrate(); }
Next in void loop() function, we have read data from HX711 module and converted this data into weight (grams) and sent it to the LCD.
void loop() { count= readCount(); int w=(((count-sample)/val)-2*((count-sample)/val)); Serial.print("weight:"); Serial.print((int)w); Serial.println("g"); lcd.setCursor(0,0); lcd.print("Weight "); lcd.setCursor(0,1); lcd.print(w); lcd.print("g "); if(digitalRead(sw)==0) { val=0; sample=0; w=0; count=0; calibrate(); } }
Before this, we have created a calibration function in which we have calibrated the system by placing the 100gm weight over the Load cell.
void calibrate() { lcd.clear(); lcd.print(“Calibrating…”); lcd.setCursor(0,1); lcd.print(“Please Wait…”); for(int i=0;i<100;i++) { count=readCount(); sample+=count; Serial.println(count); } ….. …. ….. …..
So here we have learned the basic Interfacing of Load cell and HX11 Weight Sensor with Arduino to measure the weights. In our text tutorials, we will create some applications based on weight measurement like Smart container, Automatic gate etc.
Code
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
#define DT A0
#define SCK A1
#define sw 2
long sample=0;
float val=0;
long count=0;
unsigned long readCount(void)
{
unsigned long Count;
unsigned char i;
pinMode(DT, OUTPUT);
digitalWrite(DT,HIGH);
digitalWrite(SCK,LOW);
Count=0;
pinMode(DT, INPUT);
while(digitalRead(DT));
for (i=0;i<24;i++)
{
digitalWrite(SCK,HIGH);
Count=Count<<1;
digitalWrite(SCK,LOW);
if(digitalRead(DT))
Count++;
}
digitalWrite(SCK,HIGH);
Count=Count^0x800000;
digitalWrite(SCK,LOW);
return(Count);
}
void setup()
{
Serial.begin(9600);
pinMode(SCK, OUTPUT);
pinMode(sw, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.print(” Weight “);
lcd.setCursor(0,1);
lcd.print(” Measurement “);
delay(1000);
lcd.clear();
calibrate();
}
void loop()
{
count= readCount();
int w=(((count-sample)/val)-2*((count-sample)/val));
Serial.print(“weight:”);
Serial.print((int)w);
Serial.println(“g”);
lcd.setCursor(0,0);
lcd.print(“Weight “);
lcd.setCursor(0,1);
lcd.print(w);
lcd.print(“g “);
if(digitalRead(sw)==0)
{
val=0;
sample=0;
w=0;
count=0;
calibrate();
}
}
void calibrate()
{
lcd.clear();
lcd.print(“Calibrating…”);
lcd.setCursor(0,1);
lcd.print(“Please Wait…”);
for(int i=0;i<100;i++)
{
count=readCount();
sample+=count;
Serial.println(count);
}
sample/=100;
Serial.print(“Avg:”);
Serial.println(sample);
lcd.clear();
lcd.print(“Put 100g & wait”);
count=0;
while(count<1000)
{
count=readCount();
count=sample-count;
Serial.println(count);
}
lcd.clear();
lcd.print(“Please Wait….”);
delay(2000);
for(int i=0;i<100;i++)
{
count=readCount();
val+=sample-count;
Serial.println(sample-count);
}
val=val/100.0;
val=val/100.0; // put here your calibrating weight
lcd.clear();
}
Video
Read More: Arduino Weight Measurement using Load Cell and HX711 Module