ESP8266 NodeMCU with Load Cell and HX711 Amplifier (Digital Scale)

In this tutorial, you’ll learn how to create a scale with the ESP8266 NodeMCU using a load cell and the HX711 amplifier. First, you’ll learn how to wire the load cell and the HX711 amplifier to the ESP8266 to build a scale. Then, we’ll show you how to calibrate the scale, and a simple example to get the weight of objects. Later, we’ll also add a display to show the measurements and a button to tare the scale.

ESP8266 NodeMCU with Load Cell and HX711 Amplifier Digital Scale Arduino IDE

Table of Contents

In this tutorial, we’ll cover the following topics:

Introducing Load Cells

A load cell converts a force into an electrical signal that can be measured. The electrical signal changes proportionally to the force applied. There are different types of load cells: strain gauges, pneumatic, and hydraulic. In this tutorial, we’ll cover strain gauge load cells.

load cell wheatstone bridge

Strain gauge load cells are composed of a metal bar with attached strain gauges (under the white glue in the picture above). A strain gauge is an electrical sensor that measures force or strain on an object. The resistance of the strain gauges varies when an external force is applied to an object, which results in a deformation of the object’s shape (in this case, the metal bar). The change of the resistance is proportional to the load applied, which allows us to calculate the weight of objects.

Usually, load cells have four strain gauges hooked up in a Wheatstone bridge (as shown below) that allow us to get accurate resistance measurements. For a more detailed explanation of how strain gauges work, read this article.

load cell wheatstone bridge

The wires coming from the load cell usually have the following colors:

  • Red: VCC (E+)
  • Black: GND (E-)
  • White: Output – (A-)
  • Green: Output + (A+)

Applications

Strain gauge load cells can be used in a wide variety of applications. For example:

  • check if an object’s weight changes over time;
  • measure the weight of an object;
  • detect the presence of an object;
  • estimate a container’s liquid level;
  • etc.

Because the changes in strain when weighting objects are so small, we need an amplifier. The load cell we’re using is usually sold together with an HX711 amplifier. So, that’s the amplifier we’ll use.

HX711 Amplifier

The HX711 amplifier is a breakout board that allows you to easily read load cells to measure weight. You wire the load cell wires on one side, and the microcontroller on the other side. The HX711 communicates with the microcontroller using two-wire interface (Clock and Data).

HX711 amplifier

You need to solder header pins on the GND, DT, SCK, and VCC pins to connect to the ESP8266. I soldered the load cell wires directly to the E+, E-, A-, and A+ pins. The load cell wires were very thin and fragile, be careful when soldering to not damage the wires.

HX711 Amplifier Soldered

For more information about the HX711 amplifier, you can consult the HX711 datasheet.

Setting Up the Load Cell

Our load cell kit came with two acrylic plates and some screws to set up the load cell as a scale. You can use wood plates or 3D-print your own plates.

load cell hx711amplifier package

You should attach the plates to the load cell in a way that creates a strain between the opposite ends of the metal bar. The bottom plate holds the load cell, and the upper plate is where you place the objects.

load cell setup scale

The following figure shows what my load cell with the acrylic plates looks like.

load cell scale

Where to Buy Load Cell with HX711?

You can check the load cell with the HX711 on Maker Advisor to find the best price (with or without acrylic plates included). There are load cells with different measurement ranges. The most common maximum weights are 1kg, 5kg, 10kg, and 20kg.

Load Cell HX711 Amplifier

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Wiring Load Cell and HX711 Amplifier to the ESP8266

The HX711 amplifier communicates via two-wire interface. You can connect it to any GPIOs of your chosen microcontroller. We’re connecting the data pin (DT) to GPIO 12 (D6) and the clock pin (CLK) to GPIO 13 (D7). You can use any other suitable pins (check the ESP8266 pinout guide).

Follow the next table or schematic diagram to wire the load cell to the ESP8266 board.

Load CellHX711HX711ESP8266
Red (E+)E+GNDGND
Black (E-)E-DTGPIO 12 (D6)
White (A-)A-SCKGPIO 13 (D7)
Green (A+)A+VCC3.3V
ESP8266 with Load Cell HX711 Wiring Schematic Diagram

Installing the HX711 Library

There are several different libraries to get measurements from a load cell using the HX711 amplifier. We’ll use the HX711 library by bodge. It is compatible with the ESP32, ESP8266, and Arduino.

Arduino IDE

Follow the next instructions to install the library if you’re using Arduino IDE.

  1. Open Arduino IDE and go to Sketch > Include Library > Manage Libraries.
  2. Search for “HX711 Arduino Library” and install the library by Bogdan Necula.
Install HX711 Bogdan Library Arduino IDE

VS Code with PlatformIO

If you’re using VS Code with the PlatformIO extension to program your boards, follow the next instructions.

  1. After creating a new project on PlatformIO for your board, go to the PIO Home (click on the house icon on the bottom bar). Then, click on Libraries. Search for HX711 and select the Library by bodge.
  2. Then, click on Add to Project and select the project you’re working on.
Install HX711 load cell library VS Code

Now, if you go to your project folder and open the platformio.ini file, there should be a line to include the library as follows:

lib_deps = bogde/HX711@^0.7.5

Also, add the following line to change the Serial Monitor speed to 115200:

monitor_speed = 115200

Calibrating the Scale (ESP8266 with Load Cell)

At this time, we assume you have wired the load cell to the HX711 amplifier and the amplifier to the ESP8266. You should also have your scale set up (two plates wired on opposite ends on the load cell), and have installed the HX711 library.

Before getting the weight of objects, you need to calibrate your load cell first by getting the calibration factor. Your calibration factor will be different than mine, so you shouldn’t skip this section.

1) Prepare an object with a known weight. I used my kitchen scale and weighed a glass with water (300g).

2) Upload the following code to your ESP8266. We wrote the following code taking into account the instructions to calibrate the load cell provided by the library documentation.

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp8266-load-cell-hx711/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

// Calibrating the load cell
#include <Arduino.h>
#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 12;
const int LOADCELL_SCK_PIN = 13;

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}

void loop() {

  if (scale.is_ready()) {
    scale.set_scale();    
    Serial.println("Tare... remove any weights from the scale.");
    delay(5000);
    scale.tare();
    Serial.println("Tare done...");
    Serial.print("Place a known weight on the scale...");
    delay(5000);
    long reading = scale.get_units(10);
    Serial.print("Result: ");
    Serial.println(reading);
  } 
  else {
    Serial.println("HX711 not found.");
  }
  delay(1000);
}

//calibration factor will be the (reading)/(known weight)

View raw code

3) After uploading, open the Serial Monitor at a baud rate of 115200 and reset the ESP8266 board.

4) Follow the instructions on the Serial Monitor: remove any weights from the scale (it will tare automatically). Then, place an object with a known weight on the scale and wait until you get a value.

5) Calculate your calibration factor using the formula:

calibration factor = (reading)/(known weight)
Calibrate load cell Arduino IDE Serial Monitor

In our case, the reading is -141449. The known weight is 300g, so our calibration factor will be: -141449/300 = -471.497.

calibration factor = -141449/300 = -471.497

Save your calibration factor because you’ll need it later. Yours will be different than ours.

Because the output of the sensor is proportional to the force applied to the load cell, you can calibrate your scale using whatever unit makes sense for you. I used grams, but you can use pounds, kilograms, or even pieces of cat food (as in this Andreas Spiess video).


Weighting Objects (ESP8266 with Load Cell)

Now that you know your calibration factor, you can use your load cell to weight objects. Start by weighing objects with a known weight and repeat the calibration process if the values are not accurate.

Copy the following code to your Arduino IDE. Before uploading it to your board, don’t forget to insert your calibration factor in line 43/44 of the code. The following code is the example provided by the library that demonstrates the use of most of its functions.

/**
 * Complete project details at https://RandomNerdTutorials.com/esp8266-load-cell-hx711/
 * 
 * HX711 library for Arduino - example file
 * https://github.com/bogde/HX711
 *
 * MIT License
 * (c) 2018 Bogdan Necula
 *
**/

#include <Arduino.h>
#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 12;
const int LOADCELL_SCK_PIN = 13;

HX711 scale;

void setup() {
  Serial.begin(115200);
  Serial.println("HX711 Demo");
  Serial.println("Initializing the scale");

  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());      // print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));   // print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));   // print the average of 5 readings from the ADC minus the tare weight (not set yet)

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);  // print the average of 5 readings from the ADC minus tare weight (not set) divided
            // by the SCALE parameter (not set yet)
            
  scale.set_scale(-478.507);
  //scale.set_scale(-471.497);                      // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();               // reset the scale to 0

  Serial.println("After setting up the scale:");

  Serial.print("read: \t\t");
  Serial.println(scale.read());                 // print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));       // print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));   // print the average of 5 readings from the ADC minus the tare weight, set with tare()

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);        // print the average of 5 readings from the ADC minus tare weight, divided
            // by the SCALE parameter set with set_scale

  Serial.println("Readings:");
}

void loop() {
  Serial.print("one reading:\t");
  Serial.print(scale.get_units(), 1);
  Serial.print("\t| average:\t");
  Serial.println(scale.get_units(10), 5);

  scale.power_down();             // put the ADC in sleep mode
  delay(5000);
  scale.power_up();
}

View raw code

How the Code Works

Start by including the required libraries. We’ve included Arduino.h in case you’re using PlatformIO instead of Arduino IDE.

#include <Arduino.h>
#include "HX711.h"

The following lines define the GPIOs you’ll use to connect to the HX711 amplifier. We chose GPIOs 12 and 13. You can use any other suitable GPIOs.

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

Then, create an instance of the HX711 library called scale that you’ll use later on to get the measurements.

HX711 scale;

setup()

In the setup(), initialize the Serial monitor.

Serial.begin(115200);

Initialize the load cell by calling the begin() method on the scale object and passing the GPIOs as arguments.

scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

Then, it calls several methods that you can use to get readings using the library.

  • read(): gets a raw reading from the sensor
  • read_average(number of readings): gets the average of the latest defined number of readings
  • get_value(number of readings): gets the average of the last defined number of readings minus the tare weight;
  • get_units(number of readings): gets the average of the last defined number of readings minus the tare weight divided by the calibration factor — this will output a reading in your desired units.
Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read());      // print a raw reading from the ADC

Serial.print("read average: \t\t");
Serial.println(scale.read_average(20));   // print the average of 20 readings from the ADC

Serial.print("get value: \t\t");
Serial.println(scale.get_value(5));   // print the average of 5 readings from the ADC minus the tare weight (not set yet)

Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1);  // print the average of 5 readings from the ADC minus tare weight (not set) divided
// by the SCALE parameter (not set yet)

In the following line, don’t forget to insert your calibration factor. It uses the set_scale() method.

scale.set_scale(INSERT YOUR CALIBRATION FACTOR)

Then, call the tare() method to tare the scale.

scale.tare();               // reset the scale to 0

After this setup, the scale should be ready to get accurate readings in your desired unit. The example calls the same previous methods so that you can see the difference before and after setting up the scale.

Serial.print("read: \t\t");
Serial.println(scale.read());                 // print a raw reading from the ADC

Serial.print("read average: \t\t");
Serial.println(scale.read_average(20));       // print the average of 20 readings from the ADC

Serial.print("get value: \t\t");
Serial.println(scale.get_value(5));   // print the average of 5 readings from the ADC minus the tare weight, set with tare()

Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1);        // print the average of 5 readings from the ADC minus tare weight, divided
// by the SCALE parameter set with set_scale

loop()

In the loop(), the example calls the get_units() method in two different ways: to get one single reading (without any parameters) and to get the average of the last 10 readings.

Serial.print("one reading:\t");
Serial.print(scale.get_units(), 1);
Serial.print("\t| average:\t");
Serial.println(scale.get_units(10), 5);

It shuts down the ADC that reads the sensor by using the power_down() method. Then, it waits for 5 seconds, powers up the ADC (power_up()), and the loop() repeats. So, you’ll get new readings on the Serial Monitor every 5 seconds.

scale.power_down();             // put the ADC in sleep mode
delay(5000);
scale.power_up();

Demonstration

Upload the code to your ESP8266 board. After uploading, open the Serial Monitor at a baud rate of 115200.

Let the code run a few seconds so that it has time to set up the scale (you’ll see the message on the Serial Monitor). Then, place any object on the scale to measure it and you’ll get the results on the Serial Monitor.

Load cell demonstration Arduino IDE Serial Monitor

I experimented with several objects and compared them against the value on my kitchen scale, and the results were the same. So, I can say that my ESP8266 scale is at least as accurate as my kitchen scale.


Digital Scale with ESP8266

In this section, we’ll create a simple digital scale with the ESP8266. We’ll add an OLED display to show the results and a pushbutton to tare the scale.

ESP8266 Digital Scale

Parts Required

Here’s a list of the parts required for this project:

Schematic Diagram

Add an OLED display and a pushbutton to your previous circuit on the following pins:

OLED DisplayESP8266
VCC3.3V or 5V*
GNDGND
SDAGPIO 4 (D2)
SCLGPIO 5 (D1)

*connect to 3.3V or 5V depending on the model.

Not familiar with the OLED display? Read: ESP8266 OLED Display with Arduino IDE.

Wire the pushbutton via a 10kOhm pull-down resistor to GPIO 14 (D5). The other lead of the pushbutton should be connected to 3.3V. You can use any other suitable GPIO (check the ESP8266 pinout guide).

You can follow the next schematic diagram to wire your parts.

ESP8266 Digital Scale Schematic Diagram

ESP8266 Digital Scale – Code

For simplicity, we’ll handle the pushbutton using a simple library that detects button presses with debouncing (so we don’t need to worry about that in our code). To write to the OLED display, we’ll use the Adafruit SSD1306 and Adafruit GFX libraries.

Pushbutton Library

There are many libraries with many functionalities to handle pushbuttons. We’ll use the pushbutton library by polulu. It is a simple library but comes with everything we need for this project. In your Arduino IDE, go to Sketch > Include Library > Manage Libraries and search for “pushbutton“. Install the pushbutton library by polulu.

Pushbutton Library Arduino IDE Polulu

Alternatively, if you don’t want to use the library you can add the debounce code yourself (which is not difficult). For a debounce code example, in the Arduino IDE, you can go to File > Examples > Digital > Debounce.

OLED Libraries

We’ll use the following libraries to control the OLED display. Make sure you have these libraries installed:

You can install the libraries using the Arduino Library Manager. Go to Sketch Include Library > Manage Libraries and search for the library name.

Installing Libraries – PlatformIO

If you’re using VS Code with the PlatformIO extension, follow the next steps to install the library:

  1. After creating a new project on PlatformIO for your board, go to the PIO Home (click on the house icon on the bottom bar). Then, click on Libraries. Search for pushbutton and select the Pushbutton library by Polulu.
  2. Then, click on Add to Project and select the project you’re working on.
  3. Repeat the process for the Adafruit SSD1306 and Adafruit GFX libraries. Also, don’t forget to add the HX711 library too.

In your platformio.ini file, you should have the following lines that include all the required libraries (also change the Serial Monitor speed to 115200).

monitor_speed = 115200
lib_deps = 
	bogde/HX711@^0.7.5
	pololu/Pushbutton@^2.0.0
        adafruit/Adafruit SSD1306@^2.4.6
	adafruit/Adafruit GFX Library@^1.10.10

Code

Copy the following code to your Arduino IDE. Before uploading it to the ESP8266, you need to insert your calibration factor (obtained previously).

// Complete project details at https://RandomNerdTutorials.com/esp8266-load-cell-hx711/
// Library HX711 by Bogdan Necula: https://github.com/bogde/HX711
// Library: pushbutton by polulu: https://github.com/pololu/pushbutton-arduino

#include <Arduino.h>
#include "HX711.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Pushbutton.h>

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 12;
const int LOADCELL_SCK_PIN = 13;

HX711 scale;
int reading;
int lastReading;
//REPLACE WITH YOUR CALIBRATION FACTOR
#define CALIBRATION_FACTOR -478.507

//OLED Display
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

//Button
#define BUTTON_PIN 14
Pushbutton button(BUTTON_PIN);

void displayWeight(int weight){
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 10);
  // Display static text
  display.println("Weight:");
  display.display();
  display.setCursor(0, 30);
  display.setTextSize(2);
  display.print(weight);
  display.print(" ");
  display.print("g");
  display.display();  
}

void setup() {
  Serial.begin(115200);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000);
  display.clearDisplay();
  display.setTextColor(WHITE);
  
  Serial.println("Initializing the scale");
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  scale.set_scale(CALIBRATION_FACTOR);   // this value is obtained by calibrating the scale with known weights
  scale.tare();               // reset the scale to 0
}

void loop() {
  
  if (button.getSingleDebouncedPress()){
    Serial.print("tare...");
    scale.tare();
  }
  
  if (scale.wait_ready_timeout(200)) {
    reading = round(scale.get_units());
    Serial.print("Weight: ");
    Serial.println(reading);
    if (reading != lastReading){
      displayWeight(reading); 
    }
    lastReading = reading;
  }
  else {
    Serial.println("HX711 not found.");
  }
}

View raw code

How the Code Works

Start by including the required libraries:

#include <Arduino.h>
#include "HX711.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Pushbutton.h>

Define the pins for the HX711 (load cell)—we’re using the same as previous examples:

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 12;
const int LOADCELL_SCK_PIN = 13;

Create an HX711 instance called scale.

HX711 scale;

The following variables will hold the current weight reading and the last weight reading. We only want to update the OLED display in case there’s a new reading, so that’s why we need these two variables. Additionally, we don’t want to measure decimals of grams which will make the scale too sensitive for our application—that’s why these variables are integers. If you need decimals in your measurements, you can define float variables instead.

int reading;
int lastReading;

Don’t forget to replace the next value with your calibration factor. In my case, that line of code looks as follows (my value is negative):

#define CALIBRATION_FACTOR -471.497

Next, we need to define the OLED width and height:

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

And create an instance of the Adafruit_SSD1306 library called display.

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

Define the GPIO you’ll use to read the button and create a Pushbutton object called button on that pin.

#define BUTTON_PIN 14
Pushbutton button(BUTTON_PIN);

displayWeight() function

We created a function called displayWeight() that accepts as arguments the weight you want to display on the OLED.

void displayWeight(int weight){
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 10);
  // Display static text
  display.println("Weight:");
  display.display();
  display.setCursor(0, 30);
  display.setTextSize(2);
  display.print(weight);
  display.print(" ");
  display.print("g");
  display.display();  
}

Not familiar with the OLED display? Read: ESP8266 OLED Display with Arduino IDE.

setup()

In the setup(), initialize the Serial Monitor.

Serial.begin(115200);

Initialize the OLED display:

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 
  Serial.println(F("SSD1306 allocation failed"));
  for(;;);
}
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);

And finally, initialize the load cell:

Serial.println("Initializing the scale");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

scale.set_scale(CALIBRATION_FACTOR);   // this value is obtained by calibrating the scale with known weights
scale.tare();               // reset the scale to 0

loop()

The pushbutton library allows us to wait for an event in case of a pushbutton press or pushbutton release. In this case, we check whether the pushbutton was pushed using the getSingleDebouncePress() method and call the tare() function if the button was pressed.

if (button.getSingleDebouncedPress()){
  Serial.print("tare...");
  scale.tare();
}

The HX711 provides a non-blocking method to get readings. It defines a maximum timeout to wait for the hardware to be initialized and doesn’t block your code in case the scale gets disconnected or in case of hardware failures.

if (scale.wait_ready_timeout(200)) {
  reading = round(scale.get_units());
  Serial.print("Weight: ");
  Serial.println(reading);

In the loop(), we are constantly getting new readings and checking them against the latest reading. If we got a new measurement, we call the displayWeight() function to update the OLED display.

if (reading != lastReading){
  displayWeight(reading); 
}

Demonstration

After uploading the code to your board, you can start weighing objects with your load cell. The readings will show up on the OLED display. You can tare the scale by pressing the pushbutton.

ESP8266 digital scale demonstration OLED

Once again, the readings on my ESP8266 digital scale correspond to the readings on my kitchen scale.

ESP8266 digital scale testing

Wrapping Up

In this tutorial, you learned how to interface a strain gauge load cell with the ESP8266 using the HX711 amplifier. The output of the load cell is proportional to the force applied. So, you can calibrate it to be used in g, kg, ib, or any other unit that makes sense for your project.

In summary, you learned how to calibrate the scale and how to get the weight of objects. You also learned how to create a simple digital scale with the ESP8266 using an OLED display to show the measurements and a pushbutton to tare the scale.

We hope you found this tutorial useful to get you started with a load cell. Besides being useful to measure the weight of objects, it can also be useful in many applications like detecting the presence of an object, estimating the level of liquid in a tank, calculating water’s evaporation rate, checking if there’s food on your pet’s bowl, etc.

Because of the wi-fi capabilities of the ESP8266, you can build an IoT scale using a web server to display the results on your browser’s smartphone, or save the readings on the Firebase database and access them from anywhere, send a notification when the weight is below a certain value (via email, or Telegram, for example), etc. What IoT tutorials would you like to see using the load cell? Let us know in the comments below.

We have tutorials for other popular sensors that you might find useful:

Learn more about the ESP8266 with our resources:



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

15 thoughts on “ESP8266 NodeMCU with Load Cell and HX711 Amplifier (Digital Scale)”

  1. Hi,
    As usual you guys have done a fantastic job of outlining the steps and explaining each so very clearly. I have used this to configure a load cell that monitors my dog’s water bottle weight and it works perfectly, almost. The only issue I have (and everyone will have this issue) is that if the power is interrupted then you have to go through the whole tare process by removing the item being monitored then set tare then put the weight back on.

    Is there a way to have the current weight stored in EEPROM periodically then restored again on startup? As we know, power can be a problem with ESP devices and this would allow continuous monitoring rather than just taking the weight of something.

    Thanks!

    Reply
    • Hi.
      Yes, you can save the latest reading on the flash memory. When the ESP8266 restarts, it can read the value from the flash memory and compensate with that value on the readings later on.
      There are different ways to save data on the flash memory. For example, you can create a file and write/read to the file using LittleFS. Or use EEPROM, for example.
      Unfortunately, at the moment, we don’t have any tutorials about those subjects with the ESP8266.
      Regards,
      Sara

      Reply
      • Ok. Thanks. I was hoping you might have a solution as I tried storing the value in EEPROM and then restoring it on boot but I could never get it to work. Maybe something you guys can try sometime? Thanks.

        Reply
  2. Just a tip. In Europe -and no doubt in many other countries- supermarkets often have a recycle bin for electronics. Kitchen scales are an item that for some reason is often thrown away. These have the load cells and also that little amplifier board (or at least one that looks like it).

    Pulled out several of those already for various projects

    Reply
  3. Hey,
    I am trying to send the weight measured to my thingspeak. I use the following code to send the data to my cloud
    (…)

    I code has no errors, but when I upload it, I get just dots in the serial monitor. Can you help me find what is wrong in the code? Thanks in advance!

    Reply
    • Hi.
      When you get a lot of dots on the Serial Monitor in a code like yours, it probably means that the ESP is not able to connect to your local network.
      Please check the network credentials and that the ESP8266 is relatively close to your router to catch the Wi-Fi signal.
      Regards,
      Sara

      Reply
  4. I want to make 4 scales
    Is it possible to connect more than 1 load cell, with its HX711, to a single Node MCU, or would I need four Node MCUs?
    Many thanks
    Chris

    Reply
  5. Hi,
    I am trying to connect load cell on bottle with esp8266 and that data in want to send it to nodemcu and then it will print the value of load cell and also predict that when it will going to empty. There will be continuous monitoring of data. Problem we re facing is that we don’t have idea about hoe to do calibrate loadcell data into Nodemcu, also calculation prlm in loadcell,

    Reply
  6. I am a keen follower of your blog, you are doing a fantastic job. I followed the instructions and i was getting this error in my arduino sketch
    (Arduino: 1.8.19 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”

    prototyping:20:7: error: no matching function for call to ‘HX711::HX711()’

    20 | HX711 scale;

    | ^~~~~

    In file included from C:\Users\USER\Documents\Arduino\prototyping\prototyping.ino:14:

    C:\Users\USER\Documents\Arduino\libraries\HX711/HX711.h:23:3: note: candidate: ‘HX711::HX711(byte, byte, byte)’

    23 | HX711(byte dout, byte pd_sck, byte gain = 128);

    | ^~~~~

    C:\Users\USER\Documents\Arduino\libraries\HX711/HX711.h:23:3: note: candidate expects 3 arguments, 0 provided

    C:\Users\USER\Documents\Arduino\libraries\HX711/HX711.h:10:7: note: candidate: ‘constexpr HX711::HX711(const HX711&)’

    10 | class HX711

    | ^~~~~

    C:\Users\USER\Documents\Arduino\libraries\HX711/HX711.h:10:7: note: candidate expects 1 argument, 0 provided

    C:\Users\USER\Documents\Arduino\prototyping\prototyping.ino: In function ‘void setup()’:

    prototyping:24:9: error: ‘class HX711’ has no member named ‘begin’

    24 | scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

    | ^~~~~

    Multiple libraries were found for “HX711.h”

    Used: C:\Users\USER\Documents\Arduino\libraries\HX711

    Not used: C:\Users\USER\Documents\Arduino\libraries\HX711-master

    Not used: C:\Users\USER\Documents\Arduino\libraries\HX711_Arduino_Library

    exit status 1

    no matching function for call to ‘HX711::HX711()’

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.
    )

    Reply
  7. Dear Rui and Sara, I would like to thank you and congratulate for the outstanding job!
    I have been following you for many years now, and thanks to you I developed a fairly good understanding of the Arduino environment. I was looking for a retirement hobby and your books – I bought almost all of them, including the latest on LVGL – helped me immensely!
    Nowhere else I could find such good material, guiding step by step in every detail.
    Your books and tutorials are the very best!

    Reply
    • That’s great.
      I’m glad you like our tutorials and thank you so much for supporting our work.

      Regards,
      Sara

      Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.