Store Load Cell value in a variable when pushbutton is pressed.

hello everyone,

i am working on a project of fuel guage and facing some problems regarding it.
i am using 1 load cell with HX711 with one push button,
i want whenever pushbutton is pressed the current reading of load cell get stored (suppose current weight is 2 Kg ). and after some time when pushbutton is released then again it takes the reading of the load cell
(suppose this time weight is 6 kg now). and now it subtract between these two values and shows in 16*2 display.

and again start giving continues reading of weight until pushbutton get pressed.

#include<LiquidCrystal.h>
int contrast=100;
LiquidCrystal lcd(12,11,5,4,3,2);
#include “HX711.h”

#define calibration_factor -235000.0

#define DOUT 8
#define CLK 7
const int buttonPin = 9;
int buttonState = 0;

HX711 scale;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
analogWrite(6,contrast);
lcd.begin(16,2);
Serial.println(“HX711 scale demo”);

scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor);
scale.tare();

}

void loop()
{
lcd.setCursor(0,0);
lcd.print(" WEIGHT [L]");

lcd.setCursor(0,1);

Serial.print(scale.get_units(), 3);
Serial.print(" kg");
Serial.println();

if (buttonState == HIGH) {
float i = scale.get_units();
lcd.print( i,3 );
lcd.print(" Litre");
} else {
float j = scale.get_units();
lcd.print( j,3 );
lcd.print(" jLitre");
}
}

P.S : i am not good in programming :’(

Instead of taking the reading on a high button state use the state change detection method to take the reading on the transition from low to high.

Before you get and record a new reading, record the old reading in a variable. Then take a new reading and compare the new with the old to see the change.

can you please modify my given code?
pleaseeeee.... :slight_smile:

No, I cannot. But if you try I (and, I am sure, others) will be glad to help you make it work.