Learn

An Arduino kitchen scale with a load cell and an HX711

Intermediate

Or see every lesson.

  • 261parts on the bench
  • 31boards running now
  • 1.00xreal time, on every board
Arduino Uno: kitchen scale on an HX711live0.000 s 0.00x
Click to open it in the editor
The Kitchen scale example on a simulated ATmega328P. Drag the slider to load the cell; grams print in the serial monitor.

A load cell is a metal bar that bends a tiny amount when you put weight on it. Four strain gauges glued to the bar turn that bend into a voltage. The trouble is how small it is: about a thousandth of a volt at full load. No Arduino pin can see that. The HX711 is a small board made to fix it. It amplifies the signal and turns it into a 24-bit number your sketch can read.

The circuit above is an Arduino Uno with a 5 kg bar load cell on an HX711. Drag the slider to put weight on the bar and the serial monitor prints grams. It runs in your browser on the sketch below, so you can see what tare and calibration really do before you build one.

What you need

  • An Arduino Uno
  • A bar load cell (5 kg here) with its four wires
  • An HX711 load cell amplifier board
  • A half-size breadboard and jumper wires
  • Something you know the weight of, for calibration

Wiring

Part and pinGoes toNote
HX711 VCC5 VThe chip runs from 2.6 to 5.5 volts
HX711 GNDGNDShared ground
HX711 DTPin 3Data out; any digital pin works
HX711 SCKPin 2Clock in; any digital pin works
Load cell redHX711 E+Already wired on the part in Mokxi
Load cell blackHX711 E-Already wired
Load cell whiteHX711 A-Already wired
Load cell greenHX711 A+Already wired

Three numbers: raw, tare and scale

The raw reading is not zero with nothing on the cell. No real cell is perfectly balanced. In the circuit above, the sketch prints a raw reading of about 43,000 with nothing on it (42951 when we ran it). That offset is why every scale sketch starts with tare(). It reads the empty cell a few times and calls the average zero.

The scale is how many counts one gram is worth. This cell is 1 mV/V at 5 kg, which works out to 429.5 counts a gram, so the sketch calls set_scale(429.5). After that, get_units(5) takes five readings, subtracts the tare and divides by the scale. Put 500 g on the slider and it prints 500.0 g.

The whole kitchen scale sketch
#include "HX711.h"

const int DT_PIN = 3;
const int SCK_PIN = 2;

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(DT_PIN, SCK_PIN);
  Serial.print("raw with nothing on: ");
  Serial.println(scale.read_average(5));

  scale.set_scale(429.5);
  scale.tare(10);
}

void loop() {
  Serial.print(scale.get_units(5), 1);
  Serial.println(" g");
}

How to find your calibration factor

Your load cell will not be 429.5. Every cell is a little different, so you find your own number once and write it into the sketch. Here is the simple way.

First, print read_average(10) with nothing on the cell. Write it down. Then put on something you know the weight of, like a 200 g can or a bag of sugar, and print read_average(10) again. Subtract the first number from the second. Divide the answer by the weight in grams. That is your calibration factor, and it goes in set_scale().

If your readings come out negative, your number just has the wrong sign. Use the same number with a minus in front, or swap the cell’s white and green wires.

Why the last digit wanders

Watch the readings closely and the last digit moves: 500.0, then 499.9, then 500.0. That is the HX711’s own noise, about twenty counts, which is around a twentieth of a gram here. It is real, and a real board does it too.

Averaging is the fix. get_units(5) averages five readings. Change it to get_units(1) in the editor and watch the tenths jump around more. Change it to get_units(10) and they settle, but each line takes longer. The board reads ten times a second, so ten readings take a full second.

Try it in the editor

Print ounces as well as grams: one ounce is 28.35 grams, so divide by that and print both on one line.

Add a button that calls scale.tare() when you press it, the way a real kitchen scale zeros with a bowl on it.

Click the HX711 and change capacity to 10 in the properties panel. The slider now goes to 10 kg, and the counts per gram change. Work out the new calibration factor with the steps above.

Common mistakes

Forgetting tare(). Without it, the cell’s own offset shows up as weight.

Calibrating backwards. set_scale() takes counts per gram, not grams per count.

Reading drift as a fault. A real load cell creeps a little when a weight sits on it for a while, and it drifts with temperature. Tare again before each use. Mokxi does not model creep or temperature drift, so the circuit above holds steady.

Loose wires between the cell and the board. The signal is tiny, so a bad joint shows up as jumpy readings.

Questions

What is a good calibration factor for an HX711?

There is no standard one. It depends on your load cell’s rating and the gain. Find yours with a known weight: the change in read_average(10) divided by the weight in grams.

Which pins does the HX711 need on an Arduino?

Any two digital pins for DT and SCK, plus 5 V and ground. It is not I2C or SPI; the HX711 has its own simple two-wire signal, and the HX711 library handles it.

Why does my scale show negative weight?

Your calibration factor has the wrong sign for the way the cell is mounted or wired. Flip the sign, or swap the A+ and A- wires.

Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.