HX711 Load Cell (Weight Sensor)

How to measure weight with the HX711 load cell amplifier and ESP32

The HX711 is a precision 24-bit analog-to-digital converter (ADC) designed specifically for weigh scales. Paired with a load cell, it turns your ESP32 into a digital scale capable of measuring weight with impressive precision -- kitchen scales, postal scales, bee hive monitors, and industrial weighing systems all use this same chip.

A load cell is a metal bar with strain gauges bonded to it. When weight is applied, the bar flexes slightly, changing the resistance of the strain gauges by a tiny amount. The HX711 amplifies this minuscule signal (on the order of millivolts) and converts it to a digital value your ESP32 can read.

🔗Key Specs

ParameterValue
ADC resolution24-bit
Sample rate10 SPS or 80 SPS (selectable)
Operating voltage2.6V -- 5.5V
Input channels2 (Channel A: gain 64/128, Channel B: gain 32)
InterfaceCustom serial (2 wires: DT, SCK)
Reference voltageInternal, from supply

Note: The HX711 does not use I2C or SPI. It has its own simple serial protocol using two pins (DT for data and SCK for clock). The library handles all the communication details.

🔗What You'll Need

ComponentQtyNotesBuy
ESP32 dev board1AliExpress | Amazon.de .co.uk .com
HX711 load cell amplifier module1AliExpress | Amazon.de .co.uk .com
Load cell1AliExpress | Amazon.de .co.uk .com
Breadboard1AliExpress | Amazon.de .co.uk .com
Jumper wires4AliExpress | Amazon.de .co.uk .com

Links marked Amazon/AliExpress are affiliate links. We may earn a small commission at no extra cost to you.

🔗Wiring

🔗HX711 to ESP32

HX711 PinESP32 Pin
VCC3.3V
GNDGND
DT (DOUT)GPIO 4
SCK (PD_SCK)GPIO 5

Board variation note: Pin labels and GPIO numbers vary between ESP32 boards. Always check your specific board's pinout diagram. The recommended starter board is the ESP32-WROOM-32 DevKit. Any digital GPIO will work for DT and SCK -- just avoid GPIOs 34--39 (input-only) for the SCK pin, since it needs to be an output.

🔗Load Cell to HX711

The load cell has four wires that connect to the HX711 module:

Load Cell WireHX711 TerminalFunction
RedE+Excitation positive
BlackE-Excitation negative
WhiteA-Signal negative
GreenA+Signal positive

Wire colors can vary between manufacturers. The most common convention is listed above, but always check the documentation that came with your specific load cell. If your readings are negative, swap A+ and A-.

Common load cell capacities for hobby projects: 1 kg (kitchen scale), 5 kg (general purpose), 10 kg, 20 kg, and 50 kg.

🔗Required Libraries

Install through the Arduino IDE Library Manager:

  • HX711 by Bogdan Necula -- simple, well-maintained library for reading the HX711.

Search for "HX711" in the Library Manager and install the one by Bogdan Necula (also listed as "HX711 Arduino Library").

🔗Code Example

This sketch includes a full calibration procedure. Run it once to find your calibration factor, then use that factor in your final project.

#include <HX711.h>

#define DT_PIN  4
#define SCK_PIN 5

HX711 scale;

// Set this to your calibration factor (see calibration steps below)
float calibrationFactor = -7050.0;  // Example value -- yours WILL be different

void setup() {
    Serial.begin(115200);
    Serial.println("HX711 Scale");

    scale.begin(DT_PIN, SCK_PIN);

    Serial.println("Remove all weight from the scale...");
    delay(3000);

    scale.set_scale();       // Reset to default scale
    scale.tare();            // Zero the scale (set current reading as zero)
    Serial.println("Scale tared (zeroed).");

    scale.set_scale(calibrationFactor);
    Serial.println("Place known weight on the scale to verify calibration.");
    Serial.println("(If uncalibrated, follow the calibration steps in the guide.)");
}

void loop() {
    if (scale.is_ready()) {
        float weight = scale.get_units(10);  // Average of 10 readings
        Serial.print("Weight: ");
        Serial.print(weight, 1);
        Serial.println(" g");
    } else {
        Serial.println("HX711 not ready.");
    }

    delay(500);
}

🔗How It Works

  1. Strain gauges and Wheatstone bridge -- A load cell contains four strain gauges arranged in a Wheatstone bridge configuration. When no load is applied, the bridge is balanced and the output voltage is near zero. When weight deforms the load cell, the resistance of the strain gauges changes slightly, unbalancing the bridge and producing a small differential voltage. This voltage is typically in the range of a few millivolts full-scale.

  2. Amplification and ADC -- The HX711 amplifies this tiny signal by a gain of 128 (Channel A default) and converts it to a 24-bit digital value. With 24 bits, the ADC can resolve over 16 million discrete levels, which is why these scales can be so precise.

  3. Tare (zeroing) -- The tare() function reads the current value and stores it as the zero point. Any subsequent readings are relative to this baseline. This lets you place a container on the scale, tare it, and then measure only the contents.

  4. Calibration factor -- The raw ADC value is an arbitrary number. The calibration factor converts this raw number into meaningful weight units (grams, kilograms, ounces). You determine this factor by placing a known weight on the scale.

🔗Step-by-Step Calibration

Follow this procedure to find your sensor's calibration factor:

Step 1: Upload this calibration sketch:

#include <HX711.h>

#define DT_PIN  4
#define SCK_PIN 5

HX711 scale;

float calibrationFactor = -7050.0;  // Starting guess

void setup() {
    Serial.begin(115200);
    scale.begin(DT_PIN, SCK_PIN);

    scale.set_scale();
    scale.tare();
    Serial.println("Tared. Place a known weight on the scale.");
    Serial.println("Send '+' or '-' via Serial to adjust calibration factor.");
    Serial.println("Send 't' to re-tare.");
}

void loop() {
    scale.set_scale(calibrationFactor);
    Serial.print("Weight: ");
    Serial.print(scale.get_units(5), 1);
    Serial.print(" g  |  Factor: ");
    Serial.println(calibrationFactor);

    if (Serial.available()) {
        char c = Serial.read();
        if (c == '+') calibrationFactor += 10;
        if (c == '-') calibrationFactor -= 10;
        if (c == 't') scale.tare();
    }

    delay(200);
}

Step 2: Open the Serial Monitor at 115200 baud.

Step 3: With nothing on the scale, send t to tare.

Step 4: Place a known weight (e.g., a 100 g calibration weight, or a sealed 500 ml water bottle which weighs approximately 500 g).

Step 5: Send + or - to adjust the calibration factor until the displayed weight matches the known weight. Coarse adjustments first, then fine-tune.

Step 6: Note the final calibrationFactor value and use it in your project code.

Tip: The calibration factor depends on your specific load cell, its capacity, and your wiring. It can be positive or negative. If your readings are inverted (show negative when weight is applied), flip the sign of the calibration factor.

🔗Troubleshooting

ProblemPossible CauseSolution
Readings drift slowlyTemperature changes affecting strain gaugesLet the scale reach thermal equilibrium; recalibrate in the operating environment
Readings are very noisyUnstable surface, vibrations, or loose wiresPlace on a solid, level surface; secure all connections
Always reads 0Load cell wires not connected or swappedCheck E+, E-, A+, A- connections; verify wire colors match your load cell
Negative weight readingsA+ and A- swapped, or calibration factor sign is wrongSwap A+ and A- wires, or negate the calibration factor
"HX711 not ready"Wiring issue on DT or SCK pinsVerify DT and SCK connections; try different GPIO pins
Readings change when touchedStatic electricity or grounding issueAdd a ground wire; avoid touching the load cell during measurements
Scale does not return to zeroLoad cell permanently deformed (exceeded max capacity)Replace the load cell; never exceed its rated capacity
Readings are inconsistentNot averaging enough samplesIncrease the number of readings in get_units() (e.g., 20 instead of 10)

🔗Next Steps

  • Build a kitchen scale with an OLED display and a tare button.
  • Create a bee hive monitor that tracks hive weight over time to estimate honey production.
  • Build a parts counter that calculates the number of items based on total weight and known piece weight.
  • Log weight data over WiFi for tracking trends (e.g., plant growth by pot weight over weeks).
  • Add a second load cell on Channel B for dual-scale measurements.