DIY Digital Scale: ESP8266 NodeMCU & Load Cell + HX711 Amplifier Setup

by AKP in Circuits > Arduino

967 Views, 3 Favorites, 0 Comments

DIY Digital Scale: ESP8266 NodeMCU & Load Cell + HX711 Amplifier Setup

esp8266-load-cell-hx711.jpg

In this guide, you’ll be taken step by step through the process of creating a scale using the ESP8266 NodeMCU along with a load cell and the arduino HX711 amplifier. Initially, you’ll become familiar with the necessary wiring connections needed to link the load cell arduino and HX711 amplifier to the ESP8266 for constructing the scale. After that, we’ll detail the calibration process for the scale and present a simple example for determining the weight of objects. Furthermore, we’ll enhance the tutorial by integrating a display to present measurements and adding a button to perform taring on the scale.

Introducing Load Cells

load-cell.jpg
load-cell-setup-scale-wheatstone-brifge-01.jpg

Load cells have a primary function of converting force into a measurable electrical signal. This signal’s magnitude changes proportionally with the applied force. There are several types of load cells available, including strain gauges, pneumatic, and hydraulic variants. In this guide, our focus will be on strain gauge load cells.

Strain gauge load cell arduino are constructed with a metal bar equipped with attached strain gauges (located beneath the white adhesive in the above image). Strain gauges, acting as electrical sensors, gauge the force or strain experienced by an object. When an external force impacts an object, like the metal bar in this instance, the resistance of the strain gauges shifts due to the object’s deformation. This change in resistance corresponds directly to the applied load, enabling us to compute the weight of the object.

Commonly, load cells integrate four strain gauges interconnected within a Wheatstone bridge configuration (depicted below). This arrangement facilitates accurate resistance measurements. For a more comprehensive understanding of how strain gauges function, please refer to this article.

The wires extending from the load cell are typically color-coded as follows:

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

Applications

Strain gauge load cells find diverse applications, including:

  • Monitoring changes in an object’s weight over time
  • Measuring the weight of objects
  • Detecting the presence of objects
  • Estimating liquid levels within containers
  • And more

Due to the subtle nature of strain changes during weight measurement, an amplifier becomes indispensable. The load cell arduino we are utilizing is often sold together with an arduino HX711 amplifier. Hence, we will utilize the HX711 amplifier to enhance and amplify the measurements.

HX711 Amplifier

hx711-amplifier.jpg
hx711-amplifier-soldered.jpg

The HX711 amplifier is a breakout board designed to simplify the process of reading load cells for weight measurement. One side of the board is dedicated to connecting the load cell wires, while the other side connects to the microcontroller. Communication between the HX711 and the microcontroller is established through a two-wire interface involving Clock and Data signals.

To establish a connection with the ESP8266, it’s necessary to solder header pins onto the GND, DT, SCK, and VCC pins. As for the hx711 load cell wires, I directly soldered them onto the E+, E-, A-, and A+ pins. It’s crucial to exercise caution during soldering to avoid damaging the delicate and thin load cell wires.

For more comprehensive details about the HX711 amplifier, you can refer to the HX711 datasheet.

Load Cell Setup

Load-cell-hx711-amplifier-package.jpg
load-cell-setup-scale.jpg
load-cell-scale-arduino.jpg

In our load cell kit, we received two acrylic plates along with screws to assemble the load cell into a functional scale. Alternatively, you can opt for wooden plates or create your own plates using 3D printing.

The essential objective is to affix the plates to the load cell in a manner that induces strain across the metal bar’s opposing ends. The lower plate serves as the foundation for the load cell arduino, while the upper plate functions as the platform for placing objects.

The illustration below provides a visual representation of how my hx711 load cell appears with the acrylic plates attached.

Code

ESP8266-digital-scale (1).jpg
digital-scale-kitchen.jpg
ESP8266-digital-scale-demonstration.jpg

Copy the provided code to your Arduino IDE. Before uploading it to the ESP8266, make sure you insert your calibration factor that you 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.");
}
}


See Full Article Here