Compare First Value with the New Values of Load Cell

I am working on Load Cell. I want to compare initial value of load Cell with the new Values after removing the weight from the sensor.

Code:

/*
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 "HX711.h"

#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);
Serial.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

Serial.println("Readings:");
}

void loop() {
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
// If I will an amount of weight the load cell will give a new value.
// I want to calculate difference between initial value and the new value
Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
}

Hello ashhadibrar
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.

Have a nice day and enjoy coding in C++.
Дайте миру шанс

/*
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 "HX711.h"

#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);
Serial.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

Serial.println("Readings:");
}

void loop() {
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
// If I will remove amount of weight the load cell will give a new value.
// I want to calculate difference between initial value and the new value
Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
}

Hello ashhadibrar
My proposal is to get the inital vale during the run of the setup() function.
The difference between this inital value and new value should be calculated inside the loop() function for all new values.

Have a nice day and enjoy coding in C++.
Дайте миру шанс!

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

Doesn't the tare operation in

do this functionality for you? If you start up the scale with your initial value on the scale, it will read that as zero, and then all future readings will be relative to that initial weight.

1 Like

It was too early in the morning for this simple solution and I had not yet had any coffee.
:coffee:

1 Like

I want to save first initial value and want to compare it with next Values. How can I do it?

By starting to modify your posts to add code tags. :roll_eyes:

My grandfather would say: "Es bleibt schwierig".

Mine wouldn't. :rofl:

Try this sketch by Bogden Necula

along with this tutorial:

https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide

I think Bogden's sketch will do exactly what you asked for:

https://study.com/academy/lesson/tare-weight-vs-net-weight.html

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