HX711 24-Bit ADC for Scales

The HX711 is a precision 24-bit analog to digital converter (ADC) designed for weigh scales and industrial control applications to interface directly with a bridge sensor.

You can use the HX711 module for it.


You can wire this up as follows:

Device Pin Espruino
DT / DOUT (miso) Any GPIO pin
SCK / PD_SCK (sck) Any GPIO pin
VCC 3.3v (2.7v - 5.5v is acceptable)


All you need to do is set the module up with the following:

var scale = require('HX711').connect({
  sck   : PD_SCK pin
  miso  : DOUT pin
  lsbGrams : 0.00103123388 // (default) - grams per LSB
  // median : 16, // Enable median filter (see below, default = no filter)
  mode  :
    "A128" // Channel A, 128 gain (default)
    //"B32"  Channel B, 32 gain
    //"A64"  Channel A, 64 gain

Then call scale.readGrams() to read the weight.

Usually the scale will need to be tared (have zero set). You can do this by ensuring nothing is on the scale, and running: scale.tare().

It is also very likely that your scales will have a different scale - one kilogram will correspond to a different value from the ADC. To calculate this, after the scale is tared, add a known weight (lets assume 1kg/1000g) and call scale.calculateScale(1000). You can now copy the value of scale.lsbGrams back into your initialisation code.

Median Filtering

If you enable median filtering with median : 16 in the initialisation options, the HX711 module will apply a median filter of that size, and will then average the middle half of all filtered values.

Using a bigger number for the median filter will mean better accuracy, but will then require you to measure that number of samples before the value returned from readRaw/readGrams reflects the actual value from the ADC.

This means that care must be taken with scale.tare() - since you need to have that number of samples in your median filter before using it to get an accurate figure.


If the median filter is enabled, you can use scale.getVariance() to decide if the value in the scales is moving too much for an accurate reading. This can be useful when tareing the scales as you can wait until values have stabilised before setting the zero value.

For instance:

setInterval(function() {
  // Light LED if reading is fluctuating too much
  LED.write(scale.getVariance() > 0.1);

Complete Example

This is an example for displaying weights on a Pixl.js. A0/A1 are used for connecting the HX711 and BTN1 is used to start the tare:

var scale = exports.connect({
  sck   : A1,
  miso  : A0,
  lsbGrams : 0.00103123388, //(default) - grams per LSB
  mode  : "A128",
  median: 16

var weight = scale.readGrams();
var needsTare = true;

setInterval(function() {
  var value = scale.readGrams().toFixed(1);
  var inaccurate = scale.getVariance() > 0.5;
  // tare when we have an accurate reading
  if (needsTare) {
    if (!inaccurate) {
      needsTare = false;
      value = 0;
    } else
      value = "---";
  // display state
  g.drawString(value, g.getWidth()/2, g.getHeight()/2);
  if (inaccurate) {
    g.drawString("NOT ACCURATE", g.getWidth()/2, 0);


setWatch(function() {
  needsTare = true;
}, BTN1, {repeat:true});


HX711.prototype.readRaw = function () { ... }

// Set the current reading to be the zero
HX711.prototype.tare = function () { ... }

// Given a known weight on the scale (after tare) calculate a new 'lsbGrams'
HX711.prototype.calculateScale = function (weightInGrams) { ... }

// Read the ADC and return the result in grams (based on options.lsbGrams)
HX711.prototype.readGrams = function () { ... }

// Is data ready for retrieval?
HX711.prototype.isReady = function () { ... }

// Set whether the ADC is in standby mode or not
HX711.prototype.setStandby = function (isStandby) { ... }

// Work out the amount of grams the values in the median filter vary by
HX711.prototype.getVariance = function () { ... }

exports.connect = function (options) { ... }


(No tutorials are available yet)


This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.