Quick answer: Connect the HX711 module’s DT pin to ESP32 GPIO 13 and SCK to GPIO 12, power it from VIN (5 V), install the HX711 library by Bogdan Necula, then calibrate by placing a known weight and dividing the raw reading by that weight. The result is your scale factor.

This build turns an ESP32 into a working digital scale for under a few dollars in parts. It is a good first sensor project because the wiring is simple but the calibration teaches you something real about how analogue sensors work.

What you need

  • ESP32 development board, any common variant such as the DevKit V1.
  • Load cell, rated for your intended range. 1 kg, 5 kg and 20 kg bar-type cells are the usual hobby options.
  • HX711 amplifier module, the small green breakout board.
  • Jumper wires and, ideally, a soldering iron for the load cell leads.
  • A known weight for calibration. A phone, a bag of sugar, or anything whose mass you already know.
  • A rigid base and platform. This matters more than beginners expect, as explained below.

How load cells and the HX711 work together

A load cell is a metal bar with strain gauges bonded to it. When weight bends the bar very slightly, the gauges stretch or compress and their electrical resistance changes in proportion to the force applied.

The catch is that this change is tiny, producing an output measured in millivolts. An ESP32’s built-in analogue-to-digital converter simply is not sensitive enough to read it reliably.

That is what the HX711 is for. It is a 24-bit ADC designed specifically for load cells. It amplifies the weak signal, digitises it with far greater precision than the ESP32 could manage alone, and sends the result over a simple two-wire interface using a data pin and a clock pin.

Step 1: Install the library

You need the HX711 Arduino library by Bogdan Necula. In the Arduino IDE, open Sketch → Include Library → Manage Libraries, search for HX711, and install it.

Arduino IDE Library Manager showing the HX711 library by Bogdan Necula ready to install

Step 2: Wire it up

The load cell’s four wires connect to the HX711’s E+, E-, A+ and A- terminals. The HX711 then connects to the ESP32 with four wires.

Circuit diagram showing a load cell wired to an HX711 module connected to an ESP32 board

Load cell to HX711

Load cell wire HX711 terminal
Red E+
Black E-
White A-
Green A+

Wire colours vary between manufacturers. If yours differ, check the datasheet rather than guessing, since swapping the signal pair simply inverts your readings.

HX711 to ESP32

HX711 pin ESP32 pin Notes
VCC VIN (5 V) 3.3 V works but 5 V gives more stable readings
GND GND Shared ground is essential
DT (DOUT) GPIO 13 Data line
SCK GPIO 12 Clock line, but see the warning below

A warning about GPIO 12

This trips people up and is rarely mentioned. GPIO 12 is a strapping pin on the ESP32. Its state at power-on tells the chip what flash voltage to use, so if something pulls it high while the board is booting, the ESP32 may fail to start at all.

In practice the HX711 usually leaves it low and everything works. But if your board refuses to boot, or boots only when the HX711 is disconnected, move the clock line to a safer pin such as GPIO 4, 5, 18 or 19 and update the constant in the code to match. Nothing else needs to change.

Assembling the hardware

Mount the load cell so that one end is fixed to a rigid base and the other carries the platform, with a gap that lets the bar flex. If both ends are clamped solid, the bar cannot bend and your readings will be meaningless.

Assembled DIY weight scale with a load cell mounted between a base and platform, wired to an ESP32

You can 3D print a proper enclosure, or salvage the frame from an old kitchen scale, which is often the easiest route.

Step 3: Get a raw reading for calibration

Before the scale can report grams, it needs to learn how many raw ADC counts equal one gram. Upload this sketch first.

#include "HX711.h"

const int LOADCELL_DOUT_PIN = 13;
const int LOADCELL_SCK_PIN  = 12;

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.tare();   // zero the scale with nothing on it
}

void loop() {
  if (scale.is_ready()) {
    Serial.print("HX711 reading: ");
    Serial.println(scale.get_value(5));   // average of 5 readings, tare subtracted
  } else {
    Serial.println("HX711 not found.");
  }
  delay(500);
}

Important: leave the platform empty while the board boots, because scale.tare() runs once in setup and treats whatever is present as zero.

Open the Serial Monitor at 115200 baud. With nothing on the scale you should see readings hovering near zero. Now place your known weight.

A mobile phone of known weight placed on the DIY load cell platform for calibration

Note the raw value the Serial Monitor now reports.

Arduino Serial Monitor displaying raw HX711 readings with a known weight on the load cell

Working out the scale factor

The arithmetic is simple:

scale factor = raw reading / known weight

In this example a phone weighing roughly 220 g produced a raw reading of about 50,600, giving:

50600 / 220 = 230

So the scale factor is 230. Yours will differ depending on your load cell’s rating: a 1 kg cell gives a much larger factor than a 20 kg one, because the same weight bends it further.

Use a weight in the middle of your expected range for the best accuracy, and take a couple of readings to confirm they are consistent before settling on a number.

Step 4: Measure real weights

Now upload the measuring sketch, replacing 230 with your own scale factor.

#include "HX711.h"

const int LOADCELL_DOUT_PIN = 13;
const int LOADCELL_SCK_PIN  = 12;

HX711 scale;

void setup() {
  Serial.begin(115200);
  Serial.println("ESP32 load cell scale starting...");

  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(230);   // <-- your calibration factor here
  scale.tare();           // zero the scale
}

void loop() {
  Serial.print("Weight: ");
  Serial.print(scale.get_units(10), 1);   // average of 10 readings, 1 decimal place
  Serial.println(" g");

  scale.power_down();     // put the HX711 to sleep
  delay(1000);
  scale.power_up();
}

What the code is doing

  • scale.set_scale(230) divides every raw reading by your calibration factor, converting counts into grams.
  • scale.tare() zeroes the reading at startup, so the platform's own weight is ignored.
  • scale.get_units(10) averages ten readings, which smooths out electrical noise considerably. Raise the number for steadier output at the cost of speed.
  • power_down() and power_up() idle the HX711 between readings. This saves power and reduces self-heating drift, which matters for battery projects.
Serial Monitor output showing calibrated weight readings in grams from the ESP32 scale

Troubleshooting

Symptom Likely cause Fix
“HX711 not found” Wiring or power problem Check DT and SCK are not swapped, confirm shared ground, try VIN instead of 3.3 V
ESP32 will not boot GPIO 12 strapping pin held high Move the clock line to GPIO 4, 5, 18 or 19 and update the code
Readings drift constantly Loose mounting or temperature change Secure the load cell firmly, let it warm up for a minute, re-tare
Weight shows as negative Signal wires reversed Swap the white and green load cell wires, or negate the scale factor
Values jump wildly Electrical noise Shorten wires, solder rather than using breadboard jumpers, raise the averaging count
Accurate at one weight, wrong at others Calibrated near the extremes Recalibrate with a weight mid-range, and check the platform is not touching the base
Always reads zero Weight was on the platform at boot Clear the platform and reset, since tare runs at startup

Getting better accuracy

Most disappointing results come from mechanics rather than code:

  • Rigid mounting matters most. Any flex in the base gets measured as weight. Metal or thick plywood beats a thin plastic box.
  • Solder your load cell leads. Breadboard connections on microvolt signals introduce real noise.
  • Keep the cell within its rating. Overloading a 1 kg cell even once can deform it permanently.
  • Let it settle. Load cells drift slightly as they reach thermal equilibrium, so allow a minute before precise measurements.
  • Re-tare regularly if the project runs for hours, since drift accumulates.

Frequently asked questions

Can I use an Arduino Uno instead?
Yes. The library and wiring are the same, though you would use 5 V power and ordinary digital pins. The ESP32's advantage is Wi-Fi, which lets you publish readings to a dashboard or home automation system.

Can I connect two load cells?
The HX711 has two channels, A and B, but channel B has fixed lower gain and is less suited to precision weighing. For multiple cells, use a second HX711 module on different pins.

Why 24-bit if I only need grams?
The extra resolution gives headroom. After amplification and averaging, those spare bits are what let you resolve small changes reliably rather than seeing them lost in noise.

How accurate can this get?
With a well-mounted 5 kg cell, soldered connections and careful calibration, a gram or two is realistic. Kitchen-scale accuracy is achievable; laboratory accuracy is not.

Can it send readings over Wi-Fi?
Yes, and this is where the ESP32 earns its place. Once the scale works over serial, adding an MQTT client or a small web server is a straightforward next step.

Related guides