Help with module HX711 scale

Hi!

I purchased a scale with HX711 module with 4 load cells:

The circuit is very simple to connect. I'm using ESP32, clock and data pins are on pins 18 and 5 and power is on GND and VIN. But I'm only using 1 of the load cells because it came closest to the values ​​while I was testing.

Searching the internet I saw that it is necessary to calibrate the scale, so I used this code to calibrate:

#include <HX711.h> //adiciona a biblioteca ao codigo

//configuracao dos pinos para o modulo HX711
const int PINO_DT = 5;
const int PINO_SCK = 18;

const int TEMPO_ESPERA = 1000; //declaracao da variavel de espera

HX711 escala; //declaracao do objeto escala na classe HX711 da biblioteca

float fator_calibracao = -2890; //pre-definicao da variavel de calibracao

char comando; //declaracao da variavel que ira receber os comandos para alterar o fator de calibracao

void setup ()
{

  //mensagens do monitor serial
  Serial.begin(9600);
  Serial.println("Celula de carga - Calibracao de Peso");
  Serial.println("Posicione um peso conhecido sobre a celula ao comecar as leituras");

  escala.begin (PINO_DT, PINO_SCK); //inicializacao e definicao dos pinos DT e SCK dentro do objeto ESCALA

  //realiza uma media entre leituras com a celula sem carga 
  float media_leitura = escala.read_average(); 
  Serial.print("Media de leituras com Celula sem carga: ");
  Serial.print(media_leitura);
  Serial.println();

  escala.tare(); //zera a escala
}

void loop ()
{
  escala.set_scale(fator_calibracao); //ajusta a escala para o fator de calibracao

  //verifica se o modulo esta pronto para realizar leituras
  if (escala.is_ready())
  {
    //mensagens de leitura no monitor serial
    Serial.print("Leitura: ");
    Serial.print(escala.get_units(), 1); //retorna a leitura da variavel escala com a unidade quilogramas
    Serial.print(" kg");
    Serial.print(" \t Fator de Calibracao = ");
    Serial.print(fator_calibracao);
    Serial.println();

  //alteracao do fator de calibracao
    if(Serial.available())
      {
        comando = Serial.read();
        switch (comando)
        {
          case 'x':
          fator_calibracao = fator_calibracao - 100;
          break;
          case 'c':
          fator_calibracao = fator_calibracao + 100;
          break;
          case 'v':
          fator_calibracao = fator_calibracao - 10;
          break;
          case 'b':
          fator_calibracao = fator_calibracao + 10;
          break;
          case 'n':
          fator_calibracao = fator_calibracao - 1;
          break;
          case 'm':
          fator_calibracao = fator_calibracao + 1;
          break;
        }
      }
    }
    else
    {
      Serial.print("HX-711 ocupado");
    }
  delay(TEMPO_ESPERA);
}

In this code above I use it to find the scale value. Then I put a weight of 1kg and I increase or decrease the value to find the value. Testing gave the value -1990.

Then I loaded this code with the value obtained:

//adiciona as bibliotecas ao codigo
#include <HX711.h> 


//configuracao dos pinos para o modulo HX711
const int PINO_DT = 5;
const int PINO_SCK = 18;

//declaracao do intervalo de espera
const int TEMPO_ESPERA = 500;

HX711 escala; //declaracao do objeto ESCALA na classe HX711 da biblioteca

const int FATOR_CALIBRACAO = -1990; //esse valor deve ser alterado para o valor de calibracao obtido com o outro codigo

void setup ()
{

  Serial.begin(9600);
  Serial.println("Iniciando...");

  escala.begin (PINO_DT, PINO_SCK); //inicializacao e definicao dos pinos DT e SCK dentro do objeto ESCALA
  
  escala.tare(); //zera a escala

  escala.set_scale(FATOR_CALIBRACAO); //ajusta a escala para o fator de calibracao
  
}

void loop ()
{
  //verifica se o modulo esta pronto para realizar leituras
  if (escala.is_ready())
  {
  //mensagens de leitura no monitor serial
    Serial.print(" Peso: ");
    Serial.print(escala.get_units(), 1); //retorna a leitura da variavel escala com a unidade quilogramas
    Serial.println(" kg");
  
  }
  else
  {
    Serial.print(" Aguarde  . . . ");
  }
  delay(TEMPO_ESPERA); //intervalo de espera para leitura
}

and it already starts with the value of 1kg, when I put the weight nothing increases and when I take it off it decreases a little but then it stagnates at 1kg.

I don't know what I could be doing wrong. The library examples don't help me much because it doesn't have calibration examples and then it returns unrealistic values.

Does anyone have experience with this module and scale? Could you give me some better guidance to configure the use of the scale?

Thank you very much.

You should look for info on how your kit works. On these 3 wire load cells it´s necessary to use them in pairs. Check if your kit can operate with only one and how to do it.

1 Like

Turns out connecting the 4 load cells doesn't work. It generates the maximum value of type long and the average of the get_units() function returns "NaN".

So I left it with just 1 cell. According to the manufacturer, it's okay to use just one of the load cells. With only one cell, return me better values, including using get_units().

To calibrate I'm using this code to find out the calibration factor, using a 1kg weight:

#include <HX711.h> //adiciona a biblioteca ao codigo

//configuracao dos pinos para o modulo HX711
const int PINO_DT = 5;
const int PINO_SCK = 18;

const int TEMPO_ESPERA = 1000; //declaracao da variavel de espera

HX711 escala; //declaracao do objeto escala na classe HX711 da biblioteca

float fator_calibracao = -45000; //pre-definicao da variavel de calibracao

char comando; //declaracao da variavel que ira receber os comandos para alterar o fator de calibracao

void setup ()
{

  //mensagens do monitor serial
  Serial.begin(250000);
  Serial.println("Celula de carga - Calibracao de Peso");
  Serial.println("Posicione um peso conhecido sobre a celula ao comecar as leituras");

  escala.begin (PINO_DT, PINO_SCK); //inicializacao e definicao dos pinos DT e SCK dentro do objeto ESCALA


  //realiza uma media entre leituras com a celula sem carga 
  float media_leitura = escala.read_average(); 
  Serial.print("Media de leituras com Celula sem carga: ");
  Serial.print(media_leitura);
  Serial.println();

  escala.tare(); //zera a escala
}

void loop ()
{
  escala.set_scale(fator_calibracao); //ajusta a escala para o fator de calibracao

  //verifica se o modulo esta pronto para realizar leituras
  if (escala.is_ready())
  {
    //mensagens de leitura no monitor serial
    Serial.print("Leitura: ");
    Serial.print(escala.get_units(), 1); //retorna a leitura da variavel escala com a unidade quilogramas
    Serial.print(" kg");
    Serial.print(" \t Fator de Calibracao = ");
    Serial.print(fator_calibracao);
    Serial.println();

  //alteracao do fator de calibracao
    if(Serial.available())
      {
        comando = Serial.read();
        switch (comando)
        {
                    case 'i':
          fator_calibracao = fator_calibracao - 10000;
          break;
          case 'k':
          fator_calibracao = fator_calibracao + 10000;
          break;
          case 'f':
          fator_calibracao = fator_calibracao - 1000;
          break;
          case 'u':
          fator_calibracao = fator_calibracao + 1000;
          break;
          case 'x':
          fator_calibracao = fator_calibracao - 100;
          break;
          case 'c':
          fator_calibracao = fator_calibracao + 100;
          break;
          case 'v':
          fator_calibracao = fator_calibracao - 10;
          break;
          case 'b':
          fator_calibracao = fator_calibracao + 10;
          break;
          case 'n':
          fator_calibracao = fator_calibracao - 1;
          break;
          case 'm':
          fator_calibracao = fator_calibracao + 1;
          break;
        }
      }
    }
    else
    {
      Serial.print("HX-711 ocupado");
    }
  delay(TEMPO_ESPERA);
}

And after finding out (the value here was 4600.00) I put the value in the factor of this other code:

//adiciona as bibliotecas ao codigo
#include <HX711.h> 


//configuracao dos pinos para o modulo HX711
const int PINO_DT = 5;
const int PINO_SCK = 18;

//declaracao do intervalo de espera
const int TEMPO_ESPERA = 500;

HX711 escala; //declaracao do objeto ESCALA na classe HX711 da biblioteca

const int FATOR_CALIBRACAO = -4600; //esse valor deve ser alterado para o valor de calibracao obtido com o outro codigo

void setup ()
{
  Serial.begin(250000);
  delay(TEMPO_ESPERA);

  escala.begin (PINO_DT, PINO_SCK); //inicializacao e definicao dos pinos DT e SCK dentro do objeto ESCALA
  
  escala.tare(); //zera a escala
  Serial.println("CALIBRANDO");
  escala.set_scale(FATOR_CALIBRACAO); //ajusta a escala para o fator de calibracao
  
}

void loop ()
{
  //verifica se o modulo esta pronto para realizar leituras
  if (escala.is_ready())
  {
  //mensagens de leitura no monitor serial
    Serial.println(" Peso: ");
    Serial.println(escala.get_units(20), 3); //retorna a leitura da variavel escala com a unidade quilogramas
    Serial.println(" kg");
  
  }
  else
  {
    Serial.println(" Aguarde  . . . ");
  }
  delay(TEMPO_ESPERA); //intervalo de espera para leitura

It turns out that even without any load, it still shows me 1kg. If I add 1kg to the scale, it changes to 1,700 but then a second later, it starts to go down and stays around 0,900~1,000. The issue is that the cell gives me 1kg without any load, and after I actually add 1kg to the scale, it increases a little and starts to lower the value by itself. If I take it off, it goes down a little and then it stabilizes again at 0.900 ~~ 1000 kg.

I don't know if I'm calibrating wrong, or if it's a hardware problem.

But I've already tested the examples from the library itself and something similar happens to me.

I don't know what else I can do...

Sounds strange for me, but if the manufacturer says so...

Most probably a hardware problem. You´re using the code that they provide, with the commonly used library. So, small chances of being the code.

The only thing that still comes to my mind is that you´re using an ESP32 (3.3V device) when the HX711 expects 5V (and if you provide it 5V, data line will give you 5V signal, which can burn out the ESP pin).

Do you have another board (Uno or Nano) where you can test the same setup?

But I'm powering the 5V through the VIN. Is the connected usb output not 5V?

I don't have another board :cry:

You will be much better off using a 4-cell setup connected in a Wheatstone Bridge configuration. This gives good sensitivity and some compensation against temperature variation, etc. Here's a connection diagram from an Old Forum Post

I would get that working first using just raw counts from the ADC before I started worrying about engineering units, calibration, etc. Keep in mind that the HX711's raw counts are 24-bit Two's Complement.

The problem is that the kit already comes with the circuit ready, I didn't assemble the circuit and I didn't even do the wiring part.

With the four cells, the raw value is a very high value that doesn't change if I add weight on the scale, and the average returns "NaN".

With just one cell the raw value changes, but it's very random...

It could be that one of the three-wire cells is a bit unbalanced or defective and pulling the balance of the Wheatstone bridge too far from zero for the HX711 to deal with it. I'd check that their resistances are all similar. Swapping them around might help.

And how are you connecting it to the ESP32? The HX711 is a 5V part, while the ESP32 I/Os operate at 3.3V. Directly connecting the two can easily damage the ESP32.

I'm powering the ESP32 through the notebook's usb, and then I connect the VIN pin to the module's 5V, is that wrong? I followed examples I saw on the internet.

How should it be done then?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.