Source: https://mokxi.com/libraries/hx711
Updated: 2026-11-02

Libraries / Sensors
Arduino library · Sensors

# HX711: read a load cell and turn it into grams

A load cell is a strain gauge bridge whose output changes by a few millivolts across its whole range, far too little for analogRead(). The HX711 is a 24-bit converter with a built-in amplifier made for exactly this, and the HX711 Arduino Library (by Bogdan Necula, often called bogde’s library) reads it over two pins: DOUT for data and SCK for the clock.

Open the example in the editor See the calls

Built in on Mokxi: #include <HX711.h> and it builds, with nothing to install. Free, and no account needed.

## What HX711 Arduino Library does

The library hands you raw counts. Turning counts into grams is two steps: tare() records what the empty scale reads, and set_scale() takes a calibration factor, the number of counts per gram (or per pound), which you find once with a known weight. After that, get_units() returns weight in your unit.

The chip converts 10 times a second by default, so averaging several readings costs time: get_units(10) takes about a second. The gain is 128 on channel A unless you set it, which suits most load cells.

Library Manager name | HX711 Arduino Library

Author | Bogdan Necula

Include | #include <HX711.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Load cell with HX711

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <HX711.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "HX711 Arduino Library" by Bogdan Necula from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add HX711 Arduino Library to lib_deps in PlatformIO. Mokxi follows the calls of release 0.7.5, so a sketch written here builds there too.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### HX711 scale

Creates the amplifier object. Pins are given in begin().

### scale.begin(DOUT_PIN, SCK_PIN)

Sets the data and clock pins, and the gain (128 by default).

### scale.is_ready()

True when a new conversion is waiting. Reads block until one is, so test this when the loop must not stall.

### scale.tare()

Reads the empty scale and stores it as the zero. Call it with nothing on the platform.

### scale.set_scale(2280.f)

Sets the counts per unit. Find the number by putting a known weight on and dividing the reading by that weight.

### scale.get_units(10)

The average of 10 readings, with the tare taken off and divided by the scale factor.

### scale.read_average(20)

The raw average of 20 conversions, with no tare or scale applied, useful while calibrating.

### scale.power_down()

Puts the HX711 to sleep to save power and stop self-heating. power_up() wakes it.

## Example: Calibrate a scale with a known weight (Rob Tillaart’s HX711)

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 3 to Load cell with HX711 DT
- Arduino Uno R3 2 to Load cell with HX711 SCK
- Arduino Uno R3 5V to Load cell with HX711 VCC
- Arduino Uno R3 GND to Load cell with HX711 GND

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### The weight is negative when you press on the scale

The load cell is mounted upside down, or its signal wires are swapped. Either turn the cell over, swap A+ and A-, or use a negative calibration factor in set_scale().

### Readings drift or jump by hundreds of counts

Load cells need a stiff mount and short, twisted wires. Tare after the scale has been on for a minute, average more readings with get_units(20), and keep the cell out of drafts and direct sun.

### The sketch hangs at the first read

A read waits for DOUT to go low, which never happens if DOUT and SCK are swapped or the module has no power. Check the pins in begin() match the wires, and test is_ready() in setup() to print a message.

## Projects that use HX711 Arduino Library

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Kitchen scale A bar load cell on an HX711, read with the HX711 library: tare, a scale in counts per gram, and grams on the serial monitor. Load cell pedals on a Pro Micro A load cell brake on an HX711 that responds to force, a hall sensor throttle and a pot clutch, each calibrated and sent as one Joystick.h report.

## Keep going

### Learn

- Arduino HX711 Load Cell: Calibration and Code
- DIY Load Cell Pedals and Flight Stick on a Pro Micro

### Parts

- Load cell with HX711

### More sensors libraries

- DHT sensor library
- DHT20
- VL53L0X
- Adafruit_VL53L0X
- MPU6050
- Adafruit MPU6050
- BME280
- Adafruit BMP280 Library

Every built-in library · Open the editor

## Try HX711 Arduino Library without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
