hx711 to condition work

hi guys
i am using at the end a load cell with the hx711

#include <HX711_ADC.h>

//HX711 constructor (dout pin, sck pin)
HX711_ADC LoadCell(8, 9);

long t;

void setup() {
  Serial.begin(250000);
  Serial.println("Wait...");
  LoadCell.begin();
  long stabilisingtime = 4000; // tare preciscion can be improved by adding a few seconds of stabilising time
  LoadCell.start(stabilisingtime);
  LoadCell.setCalFactor(696.0); // user set calibration factor (float)
  Serial.println("Startup + tare is complete");
}

void loop() {
  //update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
  //longer delay in scetch will reduce effective sample rate (be carefull with delay() in loop)
  LoadCell.update();

  //get smoothed value from data set + current calibration factor
  if (millis() > t + 20) {
    float i = LoadCell.getData();
    Serial.print("Load_cell output val: ");
    Serial.println(i);
    t = millis();
  }

  //receive from serial terminal
  if (Serial.available() > 0) {
    float i;
    char inByte = Serial.read();
    if (inByte == 't') LoadCell.tareNoDelay();
  }

  //check if last tare operation is complete
  if (LoadCell.getTareStatus() == true) {
    Serial.println("Tare complete");
  }

}

along integrated with my own code

i can serial read the values and it works good

the problem is once i want to use those values to give a condition the “i” used in serial print to display the value doesnt work for me

  if (failsafe> 65 and gear < 95 and (here has to be the hx711 output vale, i have used "i" with no success) > 220 and pot >= 0 and pot <= 25 )

all the other values are in range and work fine, once i want to give it the condition lets say…if wheight is more than … do this… as shown in the part code above.

how can i do this?

thank you for reading

Hi,
Please post the complete code you are having problems with please?

Try using && instead of and

https://www.arduino.cc/reference/en/language/structure/boolean-operators/logicaland/

Thanks.. Tom... :slight_smile:

the code is this

int QS = A2;         //coil 
int failsafe;    //failsafe
int pot;              //for mapping function
int clutch ;          //for mapping function
#include <HX711_ADC.h>

//HX711 constructor (dout pin, sck pin)
HX711_ADC LoadCell(4, 5);

long t;
void setup() {
pinMode (QS, OUTPUT);
pinMode (failsafe, INPUT);
pinMode (pot, INPUT);
pinMode (clutch, INPUT);

  Serial.begin(9600);
  Serial.println("Wait...");
  LoadCell.begin();
  long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of    stabilising time
  LoadCell.start(stabilisingtime);
  LoadCell.setCalFactor(696.0); // user set calibration factor (float)
  Serial.println("Startup + tare is complete");


void loop() {

  //update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
  //longer delay in scetch will reduce effective sample rate (be carefull with delay() in loop)
  LoadCell.update();

  //get smoothed value from data set + current calibration factor
  if (millis() > t + 250) {
    float i = LoadCell.getData();
    Serial.print("Load_cell output val: ");
    Serial.println(i);
    t = millis();
  }

  //receive from serial terminal
  if (Serial.available() > 0) {
    float i;
    char inByte = Serial.read();
    if (inByte == 't') LoadCell.tareNoDelay();
  }

  //check if last tare operation is complete
  if (LoadCell.getTareStatus() == true) {
    Serial.println("Tare complete");
  }

  if (clutch > 65 and failsafe < 95 and i > 225 and pot >= 0 and pot <= 25 ) 
                 digitalWrite (QS, LOW),
                 delay (90),
                 digitalWrite (QS, HIGH),
                 delay (60);

the hx711 code prints the obtained vaule to serial monitor, i need to use the given value to condition the action if it goes past a point

Hi,
Did you read post#1 about your "and" functions?

Tom..... :slight_smile: