Keg Scale

I thought I could get some parts from amazon and copy some directions and create a keg scale. But it has become way more difficult that I had expected. Not quite getting the programming down. Hope I don't mess up on the post rules or sound too dumb. But my code seems to stop when it gets to scale.tare();

</>
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <HX711.h>
HX711 loadcell;
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define LOADCELL_DOUT_PIN 3
#define LOADCELL_SCK_PIN 2

HX711 scale;

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

lcd.init();
lcd.println("HX711 scale demo");

lcd.backlight();
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

Serial.println("Readings:");
}

void loop() {
lcd.setCursor(0,0);
lcd.print("Reading: ");
lcd.print(scale.get_units(), 1); //scale.get_units() returns a float
lcd.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
lcd.println();
}
</>

Hope I don't mess up on the post rules

Please follow the advice on posting code given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

I found the copy for Forums link in the app I am running. Now I should have the </>s in the right place.
where I am having trouble is the line that says scale.tare(); seems to stop the program. I found this by inserting a serial.print("stopshere"); in different places to see when it did not print.

/* 
 Example using the SparkFun HX711 breakout board with a scale
 By: Nathan Seidle
 SparkFun Electronics
 Date: November 19th, 2014
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 This example demonstrates basic scale output. See the calibration sketch to get the calibration_factor for your
 specific load cell setup.

 This example code uses bogde's excellent library:"https://github.com/bogde/HX711"
 bogde's library is released under a GNU GENERAL PUBLIC LICENSE

 The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge
 based load cell which should allow a user to measure everything from a few grams to tens of tons.
 Arduino pin 2 -> HX711 CLK
 3 -> DAT
 5V -> VCC
 GND -> GND

 The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.

*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <HX711.h>
HX711 loadcell;
LiquidCrystal_I2C lcd(0x27, 16, 2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define LOADCELL_DOUT_PIN  3
#define LOADCELL_SCK_PIN  2

HX711 scale;

void setup() {
  Serial.begin(9600);
  
  lcd.init();
  lcd.println("HX711 scale demo");
  
  lcd.backlight();
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");
}

void loop() {
  lcd.setCursor(0,0);
  lcd.print("Reading: ");
  lcd.print(scale.get_units(), 1); //scale.get_units() returns a float
lcd.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
lcd.println();
}

Just to mess around I tried with this code, but my analog.read does not change when I add weight to the sensors. if i change it to digital.read I only get 1's or 0's. does analog read get data from pins A2 and A3 and digital read get data from pins D2 and D3? Do I need to change my inputs to A2 and A3?

#include <HX711.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

#define calibration_factor -0.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define LOADCELL_DOUT_PIN  3
#define LOADCELL_SCK_PIN  2



LiquidCrystal_I2C lcd(0x27, 16, 2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

init units = scale.get_units(), 10;


void setup() {
  lcd.init(); 
  lcd.backlight();
  
  Serial.begin(9600);

}
void loop() {
 // print the sensor values:
  Serial.print(analogRead(LOADCELL_DOUT_PIN));
  // print a tab between values:
  Serial.print("\t");
  Serial.print(analogRead(LOADCELL_SCK_PIN));
  // print a tab between values:
  Serial.print("\t");
  Serial.println();
  // delay before next reading:
  delay(1000);
 
  
 
  
  lcd.clear();
  lcd.print("Keg has ");
  Serial.println(units);
  lcd.setCursor(0,1);
  lcd.print("pints left");
  
 


  
}

Your code seems incomplete, have you got your load cell and HX711 working and seen the values on the terminal?
If not Start with the example HX711_basic_example in the library, go from there.

Hello Matty, when I run the basic example the output is a bunch of backwards questionmarks and other garbage looking text. g⸮⸮g⸮⸮⸮D?V⸮

Set the baud rate on your pc/serial console to match the sketch or change in the sketch
Serial.begin(57600);

Yay! progress, looks like it changes when I add/remove weight. Oddly the number goes up without weight.

HX711 reading: 179309
HX711 reading: 179290
HX711 reading: 179319
HX711 reading: 216348
HX711 reading: 216366

That will be like 0.0001 of your measuring range, once you add the math the numbers make sense, get ready for long longs :slight_smile:

So close, Got it working better. I think if I can just use my variable I called test and subtract the number I get when scale has no weight. then add some weight and dived the number provided by the lbs I added, I might get an output that makes sense.

#include "HX711.h"
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;

int test = 1;

LiquidCrystal_I2C lcd(0x27, 16, 2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

HX711 scale;

void setup() {
  Serial.begin(9600);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  lcd.init(); 
  lcd.backlight();

}

void loop() {

  if (scale.is_ready()) {
    long reading = scale.read();
    Serial.print("HX711 reading: ");
    Serial.println(reading);
    
    test = reading/10000;
    lcd.clear();
    lcd.print("Keg has ");
    lcd.print(test);
    lcd.setCursor(0,1);
    lcd.print("pints left");

  
  } else {
    Serial.println("HX711 not found.");

 
  
  
  
  }
  
 
  delay(1000);
  
}

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