How to make the coding math below ?

I want to make the code to calculate the differences of weight per second(g/s or kg/hr) from 20 kg load cell and HX711 module but i do not know how to make the code. Would you mind to give me advice about the code? thanks.

Are you stuck reading the values from the load cell or with calculating the result ?
If you can read the values then please post the code that you are using.

Here the coding I had made.

#include “HX711.h”
#include “math.h”

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

#define DOUT 3
#define CLK 2

HX711 scale(DOUT, CLK);

float nilai;
float p1;
float p2;
float berat_awal;
float berat_akhir;
float selisih_berat;

char reset = 0;

void setup() {
Serial.begin(9600);
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

}

void loop() {

p1= scale.get_units();
p2= scale.get_units();
if (p1 < 0 || p2 < 0) {
p1 = 0;
p2 = 0;
}
delay(1);
berat_awal = p1; //first weight sample
delay(1);
berat_akhir = p2; //second weight sample
selisih_berat = ((berat_awal - berat_akhir)/1)*0.001/(1/3600000); //calculation for make kg/hr

if (Serial.available() > 0) {
reset = Serial.read();

if ( (reset = ‘r’) || (reset = ‘R’) ) {
scale.tare();
}
}

Serial.print("p1 = ");
Serial.println(p1,2);
Serial.print("p2 = ");
Serial.println(p2);
Serial.print("selisih berat = ");
Serial.println(selisih_berat);
Serial.print("berat awal = ");
Serial.println(berat_awal);
Serial.print(“berat akhir = “);
Serial.println(berat_akhir);
Serial.println(”-----------------------------------------------------”);
}

Rickysanjaya:
Here the coding I had made.

You need to tell us what it actually does and what you want it to do that is different.

Also please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

…R

i am stuck with calculating the values

this is the code

#include "HX711.h"
#include "math.h"

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

#define DOUT  3
#define CLK  2

HX711 scale(DOUT, CLK);

float nilai;
float p1;
float p2;
float berat_awal;
float berat_akhir;
float selisih_berat;

char reset = 0;

void setup() {
  Serial.begin(9600);
  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

}

void loop() {
  
p1= scale.get_units();
p2= scale.get_units();
if (p1 < 0 || p2 < 0) {
  p1 = 0;
  p2 = 0;
}
delay(1);
berat_awal = p1; //first weight sample
delay(1);
berat_akhir = p2; //second weight sample
selisih_berat = ((berat_awal - berat_akhir)/1)*0.001/(1/3600000); //calculation for make kg/hr

if (Serial.available() > 0) {
  reset = Serial.read();

  if ( (reset = 'r') || (reset = 'R') ) {
    scale.tare();
  }
}

Serial.print("p1 = ");
Serial.println(p1,2);
Serial.print("p2 = ");
Serial.println(p2);
Serial.print("selisih berat = ");
Serial.println(selisih_berat);
Serial.print("berat awal = ");
Serial.println(berat_awal);
Serial.print("berat akhir = ");
Serial.println(berat_akhir);
Serial.println("-----------------------------------------------------");
}
berat_awal = p1; //first weight sample
delay(1);
berat_akhir = p2; //second weight sample
selisih_berat = ((berat_awal - berat_akhir)/1)*0.001/(1/3600000); //calculation for make kg/hr

This portion of code appears to take 2 readings 1 millisecond apart and perform a calculation based on them. Is 1 millisecond a reasonable time to wait between readings (I don't know the answer). Why subtract one reading from another and divide the result by 1 ?

Rickysanjaya:
i am stuck with calculating the values

What exactly do you mean by that - give some examples.

...R

UKHeliBob:

berat_awal = p1; //first weight sample

delay(1);
berat_akhir = p2; //second weight sample
selisih_berat = ((berat_awal - berat_akhir)/1)*0.001/(1/3600000); //calculation for make kg/hr



This portion of code appears to take 2 readings 1 millisecond apart and perform a calculation based on them. Is 1 millisecond a reasonable time to wait between readings (I don't know the answer). Why subtract one reading from another and divide the result by 1 ?

I think I want make it to be delta gram/ms so I substract one reading from another and divide the result by 1ms. I take two readings in 1 millisecond due to I think its possibility for accurate.