How to Use Load Cell HX711 with Arduino: Simple Guide
To use a load cell with the
HX711 amplifier on Arduino, connect the load cell wires to the HX711, then connect HX711 to Arduino pins. Use the HX711 library to read weight values by initializing the module and calling read() or get_units() functions.Syntax
The basic syntax to use the HX711 with Arduino involves including the HX711.h library, creating an HX711 object with data and clock pins, and then reading values.
HX711 scale;- creates the scale object.scale.begin(dataPin, clockPin);- initializes communication with HX711.scale.read();- reads raw data from the load cell.scale.get_units(n);- reads averaged weight values overnsamples.
arduino
#include "HX711.h" HX711 scale; void setup() { scale.begin(dataPin, clockPin); // Initialize pins } void loop() { long reading = scale.read(); // Raw reading float weight = scale.get_units(10); // Average of 10 readings }
Example
This example shows how to connect the HX711 to Arduino pins 3 (data) and 2 (clock), initialize the scale, and print the weight in grams to the serial monitor.
arduino
#include "HX711.h" #define DOUT 3 #define CLK 2 HX711 scale; void setup() { Serial.begin(9600); scale.begin(DOUT, CLK); scale.set_scale(2280.f); // Adjust this value to calibrate scale.tare(); // Reset the scale to 0 } void loop() { float weight = scale.get_units(10); // Average 10 readings Serial.print("Weight: "); Serial.print(weight); Serial.println(" g"); delay(500); }
Output
Weight: 0.00 g
Weight: 0.00 g
Weight: 5.23 g
Weight: 5.10 g
Weight: 0.00 g
...
Common Pitfalls
- Incorrect wiring: Mixing up data and clock pins or load cell wires causes no or wrong readings.
- Not calibrating: Without
set_scale()andtare(), readings won't match actual weight. - Insufficient power: HX711 and load cell need stable 5V or 3.3V supply.
- Ignoring noise: Use averaging (
get_units(n)) to reduce fluctuations.
arduino
// Wrong wiring example (data and clock swapped): // scale.begin(CLK, DOUT); // Wrong // Correct wiring: scale.begin(DOUT, CLK);
Quick Reference
| Function | Description |
|---|---|
| HX711.begin(dataPin, clockPin) | Initialize HX711 with Arduino pins |
| HX711.read() | Get raw data from load cell |
| HX711.get_units(n) | Get averaged weight over n samples |
| HX711.set_scale(scale) | Set calibration factor for weight conversion |
| HX711.tare() | Reset scale to zero |
Key Takeaways
Connect load cell wires correctly to HX711 and HX711 to Arduino pins.
Use the HX711 library to read and average weight values.
Calibrate your scale with set_scale() and tare() for accurate readings.
Ensure stable power supply and correct wiring to avoid errors.
Use get_units(n) to reduce noise by averaging multiple readings.