Help with load cell programming with LCD

I'm new to Arduino, I'm writing a sketch to display the weight on load cell on LCD,
this is my sketch:

#include "HX711.h"
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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

#define LOADCELL_DOUT_PIN  3
#define LOADCELL_SCK_PIN  2

HX711 scale;

void setup() {
 lcd.begin(16,2);
  lcd.println("HX711 scale demo");
  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
  lcd.println("Readings:");
}

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

After I upload this sketch, it displays the "HX711 scale demo " correctly but after that, all I get is some gibberish values on the screen.
I'm using Arduino nano and have connected the pins as the described in the sketch.
Can somebody help me with the sketch?

it would help to see exactly what "gibberish" is

 lcd.print(scale.get_units(), 1);

shouldn't the 2nd argument to print() be DEC? i don't believe "1" is a valid base value

Did you create the program in stages? Does the hardware work? Did you first test that you can properly print the scale reading to the Serial Monitor?

Hi @ruhi20
Show a schematic and photos of your project.
I said schematic, not fritzing.

RV mineirin

YES, The hardware worked , I did get the values on serial monitor

I get random alphabet on lcd screen

get_units returns a float so the 2nd argument is the number of decimal places to print.

When you print the value to both the Serial Monitor and the LCD is only the LCD copy messed up?

If so, can you print fixed values to the LCD? Do the example codes that come with the LCD library work for you without including the load cell code?

Why are you trying to use Pins 2 and 3 for BOTH the Load Cell and the LCD?

Yes, the example code that comes in the LCD library works.

Should I change those , I thought it might work to use common pin.

That doesn't appear to be working out. Perhaps you should try separate pins.

And, per my previous hint, print the reading to both the LCD and Serial Monitor so you can compare them.

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