Arduino UNO with HX711

Hi everyone,

With this code snippet I read the data from a 4 wire load cell on the serial monitor. But I want to read only if the "float i" data varies by 5 grams more or less. For example: If the flota i is 100 grams, it shows 100 grams on the serial monitor, but if the float i changes to 103 grams it continues to show 100 grams, if the flota i is 105 grams then it changes on the serial monitor, showing 105 grams and so on onwards of 5 in 5 grams.

static boolean newDataReady = 0;
  const int serialPrintInterval = 0; //increase value to slow down serial print activity

  // check for new data/start next conversion:
  if (LoadCell.update()) newDataReady = true;

  // get smoothed value from the dataset:
  if (newDataReady) {
    if (millis() > t + serialPrintInterval) {
        i = LoadCell.getData();
        Serial.print("Load_cell output val: ");
        Serial.println(i);
      newDataReady = 0;
      t = millis();
    }

Sorry if I posted wrong. Can anyone help? Thanks.

In short, I would like to make the readings less sensitive but without averaging and without taking the passage of time into account. Let the readings occur only if the weight varies by 5 grams more or less.

i = (((int) i ) / 5) * 5;

thank you so much

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