HX711 weight scale without tare button

Hello

Watch a video of a digital scale with Arduino that includes calibration, but does not include the button. Only you can add it to this program because you don't use the normal sentences from the HX711 book.

I hope I can help you with this!

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

// Se declaran los pines a utilizar
#define DT A0
#define SCK A1
#define sw 9
#define tarar 8

// Se declaran las variables a utilizar
long sample=0;
float val=0;
long count=0;
  
unsigned long readCount(void)
{
  unsigned long Count;
  unsigned char i;
  pinMode(DT, OUTPUT);
  digitalWrite(DT,HIGH);
  digitalWrite(SCK,LOW);
  Count=0;
  pinMode(DT, INPUT);
  while(digitalRead(DT));
  for (i=0;i<24;i++)
  {
    digitalWrite(SCK,HIGH);
    Count=Count<<1;
    digitalWrite(SCK,LOW);
    if(digitalRead(DT))
    Count++;
  }
  digitalWrite(SCK,HIGH);
  Count=Count^0x800000;
  digitalWrite(SCK,LOW);
  return(Count);
}
  
void setup()
{
  pinMode(SCK, OUTPUT);
  pinMode(sw, INPUT_PULLUP);
  lcd.init();
  lcd.backlight();
  lcd.print(" Medicion ");
  lcd.setCursor(0,1);
  lcd.print(" de peso ");
  delay(1000);
  lcd.clear();
  calibrate();
  //tare (); // Le agregué la función de tara
}

// Sección de impresion de peso
void loop()
{
  count= readCount();
  float w=(((count-sample)/val)-2*((count-sample)/val))/10; //Cambie el tipo int por float para tener mas decimales
  lcd.setCursor(0,0);
  lcd.print("Peso");
  lcd.setCursor(0,1);
  lcd.print(w);
  lcd.print("Kg ");
  
  if(digitalRead(sw)==0)
  {
    val=0;
    sample=0;
    w=0;
    count=0;
    calibrate();
  }
} 

// Sección de calibración
void calibrate()
{
  lcd.clear();
  lcd.print("Calibrando...");
  lcd.setCursor(0,1);
  lcd.print("Por favor espere...");
  for(int i=0;i<100;i++)
  {
    count=readCount();
    sample+=count;
  }
  sample/=100;
  lcd.clear();
  lcd.print("Ponga 10Kg");
  lcd.setCursor(0,1);
  lcd.print("y espere");
  count=0;
  while(count<1000)
  {
    count=readCount();
    count=sample-count;
  }
  lcd.clear();
  lcd.print("Por favor espere...");
  delay(2000);
  for(int i=0;i<100;i++)
  {
    count=readCount();
    val+=sample-count;
  }
  val=val/10000.0; // Pon aquí tu peso de calibración
  lcd.clear();
}

Interesting, but so much simpler using the HX711 library.

There is any way to calibrate the scale with the HX711 library but without doing an extra sketch to know the value of the load cell? Like this sketch

Sure, and I was doing that but eventually took it out as re-calibration was very rare and it simplified the UI.

Can you explain me how to do a calibration that way?

I just read the hdr file and figured it out, here is where to start looking

  ///////////////////////////////////////////////////////////////
  //
  //  CALIBRATION
  //

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