Build a digital Raspberry Pi Scale (with Weight Sensor HX711)

As hardly any scales work analogously, it is of course also possible to measure weights with a digital Raspberry Pi scale. This can be used in various applications as the weight value ranges which can be measured are also almost unlimited. Only a sensor and a load cell are required, which are available for different weight ranges.

In this tutorial we are building a simple Raspberry Pi kitchen scale, whose precision is amazingly accurate. Of course, it is also possible to unscrew an existing (person) scale and read it out using a Raspberry Pi.

 

Accessories for the Raspberry Pi Scale

Raspberry Pi Scale - Load Cell HX711

The most important thing to build your own scale is a “load cell”, which is a metal bar with a hole in the center (see picture on the right). This is available for different weight classes (up to 1kg, up to 5kg, up to 50kg, etc.). Even though some have a different form, all are provided with four cables. To read out the values, the HX711 weight sensor is also required. This sensor is available in two versions: red and green. The pressure sensors probably have small differences, but are – theoretically – both compatible. I have used the green HX711. Fixing material is also required.

In summary, the required components are:

  • Load Cell (US / UK)
  • Green HX711 (US / UK)
  • Breadboard
  • Jumper wire
  • Two boards (the boards should not bend easily, therefore the best is not too thin plywood)
  • Longer bolts + matching nuts

Alternatively, you can also take an existing person or kitchen scale and unscrew it. In any cases, a load cell is available and sometimes also a HX711 weighting sensor. With this you could start directly. Since complete scales cost only slightly more than the load cells, this is definitely worth considering.
If someone has screwed his scale and both are present, I would be pleased about a comment with name / manufacturer of the balance.

 

Raspberry Pi Scale – Assembling

Before the load cell is connected to the HX711 weight sensor, it should be mounted on the two plates. For this I made markings with a ballpoint pen on the wooden boards, where the screws come in. With a drill I drilled the holes and inserted the screws. Between the screw and the load cell, there should be a nut, which serves as a protection to the board (see pictures).

Raspberry Pi Waage Wägezelle

Attach the underside of the balance first.

The nuts should be well tightened so that the screws do not slip off the board.

Raspberry Pi Waage Wägezelle seitlich

Side view of the scale after both boards are mounted.

If the construction is complete, we can go to the HX711. The four cables of the Load Cell must be connected to the weight sensor. The green HX711, however, has six connections, of which we only need four for the cables. The connection is as follows:

  • Red: E+
  • Black: E-
  • Green: A-
  • White: A+

The pins labeled B+/B- remain empty. Apparently there are versions of the sensor. Where the pins are labeled S+/S- instead of A+/A-.

Now you just have to connect the sensor to the Raspberry Pi. Since this also has only four connections, the wiring is quite simple:

  • VCC to Raspberry Pi Pin 2 (5V)
  • GND to Raspberry Pi Pin 6 (GND)
  • DT to Raspberry Pi Pin 29 (GPIO 5)
  • SCK to Raspberry Pi Pin 31 (GPIO 6)

Schematically, the connection to a Raspberry Pi 3 then looks as follows:

Raspberry Pi HX711 Steckplatine

Of course, you can also change the pin assignments of DT and SCK, e.g. If you have an older model. However, you have to adjust the corresponding pins then synonymous in the code.

 

 

Raspberry Pi Weight Sensor Software

To measure the weight and to read out the value we use a Python library. Although there are corresponding C ++ libraries, however, I have no good experience with that. First, we will clone the project:

git clone https://github.com/tatobari/hx711py

It contains an example.py file which shows the function of the library and can also be used. Before that, however, a few adjustments are necessary.

First we will edit this file:

cd hx711py
sudo nano example.py

We are looking for the line in which the reference unit is set and comment it out with a hashtag sign, so that the line looks as follows:

Save it with CTRL+O and exit with CTRL+X. This reference unit is the divisor, but we must first find it out in the next step. Meanwhile you can run the example (abort with CTRL+C). The values should appear in the range 0 to 200, but this is not important at this point.

sudo python example.py

 

First Test of our Raspberry Pi Scale

The correct calibration of the weight sensor and the Raspberry Pi balance is crucial. For this we need a comparison object whose weight we know. For example, I have taken two packs of rice (1kg each), since it is recommended to choose an average value of the maximum (my load cell could be used up to 5 kilograms). Place it on the scale and run it again with sudo python example.py. The displayed values can be positive as well as negative. In my case were displayed at 2kg (= 2000 gramm) values around -882000. My reference value is thus -882000 ÷ 2000 = -441.

We then edit the sample file in the same way as above descirbed, remove the comment hashtag and enter this value accordingly. My line now looks as follows:

After saving and starting the file, the weights should now be displayed as shown in the following video. Since I had the problem that sometimes values below 0 slipped and this should not be possible, I have extended the line, in which the value is read out. This displays no longer negative weights.

 

In my tests I took a load cell with up to 5kg and calibrated with 2kg. As seen in the video, the measurement is astonishingly accurate. It is important, however, to ensure that the mounted plate does not bend too much (especially the floor plate must be fixed). However, you should be aware that the values outside the range (e.g. above 5kg) will no longer be accurate – a different load cell with its own calibration is required.

How to show text on a LCD display, I have described in this tutorial and in the video also used.

43 Responses

  1. Very nice tutorial, i would like to know if it can measure a weight of 60 grams thank you

    Reply
  2. Using a 0-50kg load cell that looks just like yours with same wire colors. About 1 in 5 values is very high or just random. I followed instructions in the code to show the bit/byte info but I do not know what to do with the info that is displayed. Can you advise?

    Reply
  3. Hey nice tutorial, thanks!
    I have 2 questions about this:

    1. Does the weight of the plate that is fixed to the top of the load cell factor in to the maximum weight? So if your plate weighs 500g will the maximum amount of weight you should put on it be 4.5kg? Or is it purely relative?

    2. Does accuracy of the load cell degrade with increasing maximum load? So will a load cell with a max. weight of 50kg sense a weight difference of 50g as accurately as a load cell with a max. weight of 5kg would?

    Reply
    • Hi Daniel,
      i haven’t tested both scenarios, so these are just my guesses:
      1. Should be absolute (500g plate will decrease the maximum amount)
      2. Yes, the nearer you weight is to the boundaries, the less accurate it is. But load cells with higher maximum weights are not as accurate in small regions (bigger “weight steps”).

      Reply
  4. first thank you for this nice tutorial.
    I try monitoring beehives (8) . Every day I receive the internal T° and an external. Now I’d like to have te weight.
    Can I connect several load cell (8) to my raspberry?

    Reply
    • I’m Looking at Doing Similar. Weight of my behive and other sensors I’ve been looking @ using hivetool.org as the base …

      Reply
    • Hi Billynux,
      I too am a bee keeper and would like to monitor the internal temp, humidity and weight of my colonies. Do you have a material list you could post or email me at service@heatwavellc.com
      Thanks
      Phil

      Reply
  5. I have cloned the file and it seems to have done so but now i can’t open it. It says -bash: cd: hx711: No such file or directory.

    what to do?

    Reply
  6. Is there anyway to get the value from the scale recorded into an array in python , as I am hoping to use something like this to make a very simple fruit sorting machine.

    Reply
  7. Hi,
    You have powered the HX711 module from 5V, and you are giving it’s Data-Out line directly to the Pi’s GPIO, won’t the 5V level damage the pi ?

    Reply
  8. Hi, this is a great article, thank you. I’ve two questions, I’d like to use this with the small E shaped load sensors found in kitchen and ‘human’ or bathroom scales. 4 of them are often used to make a total of 200kgs. Am not sure if I should provide a link to where they’re sold or not, so thought best not. They each have 3 wires, red, black, and white. Should these also be wired through an HX 711? and how? And also, is it possible for the Pi to have 4, or even 8, different load cell inputs and hence readings? If so, what would the connections be? I’m afraid I’ve very little experience in this.

    Reply
    • I haven’t seen load cells with only 3 wires, but you should be able to use several HX711 (when having enough GPIOs).

      Reply
  9. When I execute the python 2.7 code, it errors out after pressing enter for the input. Any ideas to resolve it?

    Reply
  10. in example.py
    input(‘Put known weight on the scale and then press Enter’)
    after pressing enter it throws out error File….at line 1
    I am not able to execute the example.py
    Pls. help

    Reply
  11. Just wanted to know how you got the RX711 amplifier part for FRITZING. I’d greatly appreciate it!!

    Reply
  12. Nice tutorial! Although the directory name is actually “hx711py” not “hx711” so to edit the file you need:
    cd hx711py
    sudo nano example.py

    Reply
  13. I cant calibrate it as the weight value doesn’t change when I add a weight to the load cell. It just comes up with random values. what do?

    Reply
  14. Excellent tutorial. I have everything connected and working, using a reference unit of 8200 for a 5 gram weight. When I place the weight on the scale I get an accurate reading of 5 grams. However I’d like to get a reading to the nearest two decimal places – 4.995, for example. My Python skills are a bit rusty, does anyone know how I might accomplish this?

    Reply
  15. I also have this issue please help

    I am at the calibration stage and have tried 2 different hx711 boards so i know they are not faulty?

    when i run example.py:

    python ./example.py

    I get random numbers that range from -90000 to (+)20000

    knowing this isnt right I worked out an average using your calculations which came to 53.3

    now when i run it i still get random numbers only smaller random numbers?!:

    Monitor:~/fuel/hx711py $ sudo python example.py
    195
    99
    28
    765
    36
    0
    77
    38
    88
    208
    81
    96
    91
    861
    37
    100
    99
    6974
    44
    1511
    0
    45
    153
    316
    0
    281
    285
    0
    592
    0
    430
    0
    138
    439
    51
    0
    468
    0
    233
    1669
    238
    0
    0
    0
    5709
    1555
    847
    1081
    0
    0
    0
    0
    0
    0
    0
    0
    0
    ^CCleaning…
    Bye!

    Please Help

    Reply
  16. Getting a lot of random values when i run the code. the values do no change even if load is applied to the load cell. please do reply.

    Reply
    • I had the same problem. Turns out it was a broken load cell- remove it from the plates and you’ll probably see broken wires running between the white bits of the bar. All you can really do is buy a new load cell

      Reply
  17. Hello
    When I run the code, I get completely random values, even when nothing is on the board.
    The boards I placed on the load cell are not very stable, could it be the reason?
    Also, I am using a 50kg load cell.

    Please reply.

    Reply
  18. Hi there,

    Just a quick note. I think the wiring schematic provided *might* be incorrect. As an example, I wired up the hx711 as per your instruction, and ran the example script to ensure that I had everything correct and the load cell worked as expected. When run, the output yielded:

    “`
    ~/hx711py $ python example.py
    0
    18236
    18236
    18236
    18236
    18236
    18236
    18236
    18236
    “`

    No matter what I did, the load cell (I’m using the TAS606, which has a nearly identical wiring scheme from what I can tell) gave the results listed above. After doing a bit of digging and swapping out the wires on the Raspi’s #29 & #31 pins, I received the following:

    “`
    ~/hx711py $ python example.py
    -6
    -18029
    18230
    -18171
    -15963
    -18207
    -18029
    -18207
    “`

    Which seemed to indicate a working load cell. Is it possible that the wiring scheme in your tutorial has the pins swapped? I currently have DAT going to #31 and CLK going to #29.

    Reply
    • You are correct there is a typo on the wiring schematic. The green wire should be labeled A+ not A-. White is A-.

      Reply
  19. Great article, but I have a question when you state ” since it is recommended to choose an average value of the maximum (my load cell could be used up to 5 kilograms). ” I don’t understand what that means. The average value of the maximum of what? Are you saying the average value of the heaviest item you intend to weigh? Everything work great even small increments like 10g, 20g. Only issue is when I try to weight 4k to 5k items. (I have a 5K load cell btw) that when he accuracy is off. So my question is do I use something close to 5k when I’m getting the reference value? and why did you use 2k for your 5K load cell? Thanks for your time.

    Reply

Leave a Comment

Your email address will not be published.

Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!