In this tutorial, it is shown how to utilize an Arduino Uno, a HX711 breakout board, and a load cell in order to measure weight. Moreover, an LCD module of type LCM1602 IIC V1 is used to display the measured weight.
List of materials:
Arduino Uno | |
Jumper wires | |
HX711 Load Cell Amplifier | |
Load Cell | |
LCM1602 IIC V1 (LCD) | |
Small squared timber and screws |
The HX711 is a 24-bit analog-to-digital converter which fits perfectly to weight scale applications. Fortunately, there exist many breakout boards for the HX711. Therefore, it is very easy to use it in combination with a so-called load cell. Load cells are transducers that convert pressure/force into an electrical signal. As the electrical signal has typically only a few millivolts, it has to be amplified. And that’s where the HX711 breakout board comes in: as it amplifies the weak signal to a few volts so that we can read the signal with the help of an Arduino Uno.
Preparations for Wiring:
In order to easily connect the load cell to the pins of the HX711 module, you can add DuPont connectors to the wires. This step is totally optional. You can use whatever you want to connect the wires to module’s pins. If you use DuPont connectors, keep in mind that such load cells often have thin single-strand wires. I used the help of some solder to attach the thin wires more tightly to their connectors.
You will retrieve consistent pressure values from the load cell, if you mount the load cell on something that is solid and heavy. I used a part of an old squared timber for this task:
Wiring:
First, the load cell is connected to the HX711 module. The load cell has four wires, which must be connected to the first four pins of the HX711 module: Red wire to E+, black wire to E-, white wire to A-, and green wire to A+. The remaining pins, B- and B+, can be used if a second load cell has to be connected to the HX711 module.
Next, the HX711 module is connected to the Arduino Uno. The module’s GND pin must be connected to the Arduino’s GND pin. DT and SCK must be connected to digital pins of the Arduino. In this tuorial, DT is connected to digital pin #4 and SCK is connected to digital pin #5. The remaining pin VCC must be connected to the 5V pin of the Arduino. As the LCM1602 module requires also a connection to the 5V pin, a breadboard is used in-between to split the Arduino’s 5V signal.
As a last step, the LCM1602 module’s SDA and SCL pins must be connected to the corresponding SDA and SCL pins of the Arduino Uno. Moreover, the GND pin must be connected to one of the Arduino’s GND pins and the VCC pin has to be connected to the 5V signal of the breadboard.
Example source code:
// (c) Michael Schoeffler 2017, http://www.mschoeffler.de #include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC #include <Wire.h> #include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ) void setup() { LoadCell.begin(); // start connection to HX711 LoadCell.start(2000); // load cells gets 2000ms of time to stabilize LoadCell.setCalFactor(999.0); // calibration factor for load cell => strongly dependent on your individual setup lcd.begin(16, 2); // begins connection to the LCD module lcd.backlight(); // turns on the backlight } void loop() { LoadCell.update(); // retrieves data from the load cell float i = LoadCell.getData(); // get output value lcd.setCursor(0, 0); // set cursor to first row lcd.print("Weight[g]:"); // print out to LCD lcd.setCursor(0, 1); // set cursor to secon row lcd.print(i); // print out the retrieved value to the second row }
Calibration
The last step is to calibrate the weighing scale. This steps becomes very easy if you have some calibration weights. Unfortunately, I do not have such weights. Therefore, I used an alternative approach to calibrate my weighing scale. First, I grabbed another weighing scale and put something on it (dc motor):
Then I put the dc motor on my weighing scale. Next, I adapted the parameter of the setCalFactor method (see setup function) until the correct weight was shown on my weighing scale. Keep in mind, each load cell and setup needs a different calibration factor. Therefore, it makes no sense to tell you mine.
In order to check whether my calibration factor is working, I did the same thing again with something else (screwdriver):
Overall, I’m satisfied with the accuracy:
Video Tutorial:
Can you suggest a tutorial or link to the code in python, such that it may be built using Raspi?
Respected sir,
when I had compiled your code I was getting an error about ” positive ” on 7th line of the code will you please help me with it.
Thank u sir.
saying that ” positive “was not declared .
I have used 16*2 liquidcrystal dispaly..but the weighting value in display does not set to zero after the load is removed..plz help me out by clearing the display for 16*2 lcd diplay
Cannot get code to compile. Get following error message:
Arduino: 1.8.1 (Windows 10), Board: “Arduino/Genuino Uno”
The sketch name had to be modified. Sketch names can only consist
of ASCII characters and numbers (but cannot start with a number).
They should also be less than 64 characters long.
C:\Users\Dell\Documents\Arduino\load_cell_1\load_cell_1.ino:2:61: fatal error: HX711_ADC.h: No such file or directory
#include // https://github.com/olkal/HX711_ADC
^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Can you help me? I’m a beginner.
sir i have arduino uno, hx711, lcd key pad sheild, and i am facing the problam with programing . i need program as a arduino scale load cell hx711 with alrt . also i have realy . so sir please help me. and if you scatch make for me .i will thanking to you.
Hello, i don’t know whats happen with my load cell.
but when i try to read your data (LoadCell.getData()) the number start in zero and increasing by yourself, i don’t have the same reaction like you.
do you know why this happens?
Hello! Good day Sir! I need your help for my school project. I just want to know what is the code if ever the display on the LCD is 1kilogram then it will make the light on. if ever it is half kilo then it will run the motor. I am looking forward for your response Sir. Thank you for sharing your knowledge!
POSITIVE WAS NOT DECLARE IN THIS SCOPE……………..THIS TYPE OF ERROR IS ACCUR….WHAT IS SOLUTION?????????????
U HAVE GOT THE SOLUTION ? PLS. CONFIRM
Got the same error, just replace it with the below line it solved my problem
LiquidCrystal_I2C lcd(0x27,16,2);
Hello, I am thai student. I do my project about weighing scale as yours. I connected everything as you did and wrote the code as yours. But I changed only the calibration factor is 33814. For loadcell, I used 60kgs. But I got a problem when I put the object 5kgs on the loadcell but I got 10 g/kgs (I am not sure about your scale). I thought the weight that show is increase double.
– Thank you for your support –
Thank you very much for the nice video, it was really good.
Thank you for the instructions. I would like to do this with mini Arduino, does the wiring diagram changes?
Also, in addition to LCD display, I would like data to be recorded in SD card? How can I add the SD card recorder?
Finally, how can a tear push bottom can be add to the system?
Sincerely,
Shahin
I dont get your scale Faktor why did you put in 20.000?
an you please explain why you write that 20000 while meassure 54260 g ?
thankyou for the tutorial..but i have a problem …because when i want uploading the programe my lcd was blacklight
hello im trying to recreate your set up but i keep getting an error of – ‘POSITIVE’ was not declared in the scope and im just wondering what LiquidCrystal_I2C library you used
There might be something wrong with the LiquidCrystal_I2C -> look for another variant of the library and/or check whether the library is correctly installed (sorry, I do not have my library in reach right now)
I get a error when I compile.your code.. Can you help
error: ‘POSITIVE’ was not declared in this scope
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
It might have something to do with a wrongly installed LiquidCrystal_I2C library (or the wrong version/variant of LiquidCrystal_I2C was installed)
May i have the code of without LCD screen?
Just remove all the lines that have something to do with LiquidCrystal_I2C.
hello michael, I loved your project and I had an idea but I couldn’t make it work send the weight via modbus rs232 protocol, could you help me, thanks!!!!!!
i’m from Brasil
Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: “Arduino Uno”
sketch_feb17a:7:53: error: ‘POSITIVE’ was not declared in this scope
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
^~~~~~~~
sir while compiling the source code am receiving this message…
‘exit status 1
‘POSITIVE’ was not declared in this scope,
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Michael I really appreciate the simple programming.
I and new to this and had been running around in circles to get this working.
Her Schoffler guten tag.Ich schreibe Ihnen fon Griechenland,und Ihre waage die durch arduino funkzuniert ist sehr indresand.Ich bin imker und mochte eine solche bauen,fur die bienenkaste zu wiegen.Ich wahr in Deutschland vor viele viele jahre,in Baden Wurtemberg,bei firma Bauknecht,eine praktikung gemacht als betriebselektriker.Den haba ich in Thessaloniki die Staatlice Ingenieur Schule als batriebs elektiker gemacht.Ich habe fast die Deutsche sprache vergest,und ist mir leicter sp,rechen.Das wegen ,wenn Ihnen nicht aus macht ,ici habe eine Biete an Sie ,das Ihre telephon numer mich senden,um viel besser kan ich underhalten mit Ihnen .Fur Ihre information ,ich werdr Ihnen bezalen mit honig wen Sie nach Griechenland komen in sommer in Halkidiki.
// Edit: removed telephone number
Hallo Herr Lukmas,… das ehemalige Bauknecht-Gelände ist bei mir um die Ecke (10min mit dem Auto). Auch wenn ich unheimlich gerne ihren Honig mag, muss ich leider zugeben, dass mit die Zeit für eine genaue Hilfestellung zu einer Bienenwaage fehlt :( Trotzdem beste Grüße nach Griechenland!
error: ‘POSITIVE’ was not declared in this scope
There might be a problem with the LiquidCrystal_I2C library. Either it’s the wrong one or the library has not been installed correctly.
Thank you for your favor sir, I am Korean engineering student. This is very big help for me to make a code.
Hello,
I am trying to make the same exact setup as you have here. However, when inputting the code, I receive an error saying “POSITIVE was not declared in this scope”
Do you have any idea where this would stem from
I’ve checked already a lot on the internet
_Max
I can’t solve your issue, however, I might be able to point you into the right direction: I already got some messages/emails describing the same problem. In most cases a wrong LiquidCrystal_I2C library was used or the library was wrongly installed.
Hi,
It will be great if you can put the link of LiquidCrystal_I2C library that you have used.
Hello … Is it possible to apply the same calibration method with 200 kg loadcell with 1 kg sample weight? Your work is excellent. Congratulations.
hello.. is it possible to apply push button to ZERO.. and how to add the code? THANKS..
Hello and thank you for uploading this project. I have tried to recreate this project and whenever I power on the Arduino the number on the LCD is never stabilize and this behavior continues even when adding a load to the load cell. have you experienced a similar issue or know of a way to solve it?
Hallo Michael, vielen Dank für Dein schönes und hilfreiches Tutorial! Hat sofort funktioniert (den LCD-Kram habe ich durch Ausgaben auf die serielle Schnittstelle ersetzt). Der mechanische Aufbau zur Messung wird das eigentliche Problem werden (für mich). Ich möchte einen Behälter wiegen, in welchem sich Filament für den 3D-Druck befindet. Durch die Messung (bzw. Differenzbildung) wird dann klar, wieviel g Filament auf der Rolle verblieben sind.
Ich denke mit ein paar Aluprofilen kann ich einen entsprechenden Rahmen zimmern, bei entsprechendem Gewicht auf der Zelle muss es ja stabil sein und darf nicht kippen (meine Wägezelle funktioniert bis 5kg).
Grüße
Marcus
Hallo Michael,
Ich möchte auch das Waagenprojekt nachbauen. Aber ich habe wie schon mehrere Andere das Problem “error: ‘POSITIVE’ was not declared in this scope”.
Könntest du bitte mal ein Ling senden, wo wir die richtige Library beziehen können.
Mir ist diesen Problem auch schon bei einem anderen Projekt aufgefallen und konnte es nicht lösen.
mit bestem Dank
Andreas Harms
Ich habe das Problem gelöst:
LiquidCrystal_I2C lcd(0x27,20,4);
Damit funktioniert das Programm.
Gruß Andreas
Hallo Michael und die Anderen auf der Seite
Ich möchte gerne noch eine Altanative für die Ansteuerung des Displays zeigen. Ich habe jetzt nicht mehr das Problem mit dem ” POSITIVE “.
Da ich kein Englisch kann, habe ich mir erlaubt auf deutsch zu schreiben.
Gruß Andreas
#include // https://github.com/olkal/HX711_ADC
#include
#include // LiquidCrystal_I2C library
HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin
LiquidCrystal_I2C lcd(0x27,16,2);void setup() {
lcd.init();
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor (1885.0); // calibration factor for load cell => strongly dependent on your individual setup
lcd.begin(16, 2); // begins connection to the LCD module
lcd.backlight(); // turns on the backlight
}
void loop() {
//lcd.backlight(); // turns on the backlight
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print(“Weight[g]:”); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(i); // print out the retrieved value to the second row
}
you are a saviour dude, it worked,can you say what you did?
Please i need your help urgently, how can i interface the loadcell with a GSM module to alert me when the weight reaches a certain level. please kindly help. Thanks in advance
Thank You x100000000000. If it wasn’t for this tutorial I wouldn’t have been able to complete my project. THANK YOU!!!
Hallo,
ich wuerde gerne den Gewichtssensor uber das Arduino MKR WIFI 1010 mit der Arduino Cloud zu verbinden und die ermittelten Daten dort auszugeben.
Ist das moeglich?
VG,
Ludwig
Hello Sir,
I am a student in Kenya and intend to do a project on a weighing system that has an alert buzzer and red led to notify when a load is applied. Could you help me with the code? Thank you.