When you need to measure weight, force, or tension in a microcontroller project, the HX711 paired with a resistive strain gauge is the undisputed workhorse. Unlike simple analog sensors, this electronic sensor setup requires a dedicated amplifier and an understanding of digital serial protocols to extract usable data. This guide provides the exact wiring, raw-to-unit math, and ESP32-specific noise mitigation required to get lab-grade accuracy from a $5 hardware stack.

Sensing Principle and Output Signal Definition

A load cell utilizes a Wheatstone bridge circuit composed of four resistive strain gauges bonded to a deformable metal element (usually aluminum or steel). When mechanical force is applied, the metal bends, causing the physical dimensions of the strain gauges to change. This deformation alters their electrical resistance by a microscopic amount, unbalancing the bridge and producing a differential voltage output in the microvolt (µV) range. Because a 3.3V ESP32 GPIO pin cannot resolve microvolt shifts, an instrumentation amplifier is mandatory.

The HX711 chip acts as this amplifier and analog-to-digital converter (ADC). It features a Programmable Gain Amplifier (PGA) that boosts the microvolt signal and a 24-bit sigma-delta ADC that digitizes it. The output is not an analog voltage, nor is it standard I2C or SPI. It is a proprietary two-wire serial digital stream (Data and Clock) that outputs a 24-bit signed integer in two's complement format. You must bit-bang the clock line to shift the data out, which is why dedicated libraries are required to interface with it.

Wiring Pinout and Electrical Specifications

The HX711 breakout board acts as the bridge between the high-impedance analog load cell and the digital microcontroller. Below is the complete electrical specification and pin mapping for a standard ESP32 DevKit V1 integration.

Table 1: HX711 Electronic Sensor Pinout and Electrical Specs
Pin / Parameter Function / Value ESP32 Connection Notes & Constraints
VCC Power Supply (2.6V to 5.5V) 3V3 or 5V Pin Must be clean; LDO recommended over raw USB 5V.
GND Analog & Digital Ground GND Pin Star-ground to ESP32 GND to prevent ground loops.
DT (DOUT) Serial Data Output GPIO 4 Digital push-pull output. 3.3V logic safe.
SCK (PD_SCK) Serial Clock Input GPIO 5 Digital input. Keep high for >60µs to power down.
E+ / E- Excitation Voltage to Load Cell N/A (Sensor Side) Provides reference voltage to the Wheatstone bridge.
A+ / A- Analog Signal from Load Cell N/A (Sensor Side) Channel A input. Gain selectable via clock pulses.
Channel A Gain 128x (Default) or 64x Set via Software 128x for standard load cells; 64x for higher voltage signals.
Channel B Gain 32x (Fixed) Set via Software Used for secondary sensors (e.g., thermistors).
Output Rate 10 Hz or 80 Hz Hardware Pin (RATE) Tie RATE pin to VCC for 80 SPS, GND for 10 SPS.
⚠️ ESP32 Logic Level Callout: While the HX711 can be powered by 5V, its digital output (DT) will swing to its VCC voltage. If you power the HX711 with 5V, the DT pin will output 5V logic, which will damage the 3.3V-tolerant GPIO pins on an ESP32. Always power the HX711 from the ESP32's 3V3 pin, or use a logic level shifter on the DT line if 5V excitation is strictly required for your specific load cell.

Raw-to-Unit Math and Calibration Procedure

The HX711 does not output grams or pounds; it outputs a raw 24-bit signed integer. In two's complement format, this yields a theoretical range from -8,388,608 to +8,388,607. To convert this raw ADC reading into a physical unit (like grams), you must apply a linear transformation based on a known tare offset and a calibration factor.

The mathematical relationship is strictly linear:

Physical_Weight = (Raw_ADC_Reading - Tare_Offset) / Calibration_Factor

The Tare_Offset is the raw ADC value when zero load is applied. The Calibration_Factor represents the number of ADC ticks per unit of weight. Because manufacturing tolerances in strain gauges vary wildly, you cannot use a datasheet value for the calibration factor; you must derive it empirically.

Step-by-Step Calibration Sequence

  1. Upload uncalibrated code: Set the calibration factor to a dummy value (e.g., 1.0) and initialize the tare function.
  2. Apply a known mass: Place a precisely known weight on the load cell (e.g., a 1000g calibration weight or a verified 500g bag of sugar).
  3. Read the raw output: Note the raw integer value printed to the serial monitor. Assume the raw reading is 21,850,000 for a 1000g weight.
  4. Calculate the factor: Divide the raw reading by the known weight. 21,850,000 / 1000 = 21850. Your calibration factor is 21850.0.
  5. Hardcode the factor: Update your firmware with this derived constant.

Complete ESP32 Arduino Firmware

This code utilizes the standard HX711 library by Bogdan Neculai (available via the Arduino Library Manager). It includes a readiness check to prevent the ESP32 from hanging if the sensor is disconnected.

#include 'HX711.h'

// ESP32 Pin Definitions
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;

HX711 scale;

// Derived via known-weight calibration procedure
float calibration_factor = 21850.0; 

void setup() {
  Serial.begin(115200);
  Serial.println('Initializing HX711 Electronic Sensor...');

  // Initialize the scale with designated GPIO pins
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  
  // Set gain to 128 (Channel A default)
  scale.set_gain(128);
  
  // Apply the empirically derived calibration factor
  scale.set_scale(calibration_factor);
  
  // Zero the scale (captures current raw value as Tare_Offset)
  scale.tare(); 
  Serial.println('Tare complete. Ready to measure.');
}

void loop() {
  // Check if the HX711 has finished a conversion cycle
  if (scale.is_ready()) {
    // Average 10 readings to smooth out high-frequency noise
    float weight_grams = scale.get_units(10); 
    
    Serial.print('Weight: ');
    Serial.print(weight_grams, 1);
    Serial.println(' g');
  } else {
    Serial.println('HX711 not found or not ready. Check wiring.');
  }
  
  // Delay must be >100ms for 10Hz sample rate, >12.5ms for 80Hz
  delay(200);
}

Common Interference Sources and Hardware Fixes

Strain gauge electronic sensors are notoriously susceptible to environmental and electrical noise. If your serial monitor shows weight values jumping by hundreds of grams while the load cell is sitting empty, you are experiencing one of the following interference modes.

  • ESP32 WiFi Ground Bounce: When the ESP32 transmits a WiFi packet, it draws current spikes up to 500mA. On a shared breadboard ground rail, this creates a voltage spike (ground bounce) of 50mV to 100mV. Because the HX711 is measuring microvolt shifts, this ground bounce is interpreted as massive weight changes. Fix: Use a 'star ground' topology where the HX711 GND and Load Cell GND meet at a single physical point, separate from the ESP32's digital return path.
  • Thermal Drift: Strain gauges are temperature-sensitive. If your load cell is near a heat source (like a voltage regulator or direct sunlight), the metal element expands, altering the bridge resistance. Fix: Allow the system to thermally stabilize for 15 minutes after power-on before executing the tare() function.
  • Mechanical Creep and Binding: If the load cell is mounted with screws that are over-torqued, or if the mounting surface is not perfectly rigid, the metal will 'creep' over time, causing the zero-point to drift continuously. Fix: Mount the load cell using the specified torque values (usually 2-4 Nm for 50kg cells) and ensure the mounting bracket is machined flat.
  • EMI from Unshielded Cables: The analog wires (A+, A-, E+, E-) carry microvolt signals. If these wires run parallel to AC mains cables or stepper motor leads, they will act as antennas. Fix: Use twisted-pair shielded cable for the load cell connection, and connect the shield to GND at the HX711 end only to prevent ground loops.

For deeper theoretical background on how the underlying Wheatstone bridge balances these microvolt signals, refer to the bridge circuit analysis on All About Circuits. For hardware-specific assembly and breakout board schematics, the SparkFun HX711 Hookup Guide remains the definitive visual reference.

By respecting the strict digital protocol of the HX711, executing a proper empirical calibration, and isolating your analog ground from digital switching noise, you can reliably achieve sub-gram resolution on a standard 50kg aluminum electronic sensor.