Limited loadcelll

hello...
may some one can help me...
i have made a coding to my automatic feeder, i have aproblem in loadcell coding. if the feeding reach 1000 grams, the relay of feeding suply have to stop. its working, but the loadcell number unstable. if the weigh more than 1000 grams, or less than 1000 grams the feeding suply working again. i need it works once.
this is my coding
#include <HX711_ADC.h> // GitHub - olkal/HX711_ADC: Arduino library for the HX711 24-bit ADC for weight scales
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library

HX711_ADC LoadCell(A0, A1); //
LiquidCrystal_I2C lcd(0x27, 16, 2); //
int wt;
int Relay = 2;
int val;
unsigned long prMillis;

void setup()
{
Serial.begin(9600);
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(968.303); // calibration factor for load cell => strongly dependent on your individual setup
lcd.init();//begin(); // begins connection to the LCD module
lcd.backlight(); // turns on the backlight
pinMode(Relay, OUTPUT);
// pinMode(Relay, OUTPUT); // it was missing in your sketch
}

void loop()
{
wt = wtDisplay();
Serial.print(wt); //185
//---------------------------------------
if (wt > 0)
{
if (wt < 1000)
{
processControl(15000, 15);
}
else
{
if (wt = 1000)
{
processControl(30000, 30);
}
}
}
digitalWrite(Relay, LOW);
delay(1000);
//while (1);
}

int wtDisplay()
{
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
wt = (int)i;
//wt = 615;//185;
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(wt); // print out the retrieved value to the second row
// wt = 90;
//wt = analogRead(A0);
return wt;
}

void processControl(unsigned long x, int value)
{
while (1)
{
digitalWrite(Relay, HIGH);
prMillis = millis();
while (millis() - prMillis < x)
{
wt = wtDisplay();
if (value == 15)
{
if (!(wt > 0 && wt < 1000))
{
break;
}
}
else
{
if (value == 30)
{
if ((!wt > 0 && wt < 1001))
{
break;
}
}
}
}
break;
}
}

Hi, @wiwid
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Also before posting your code, press < CTRL > < T > in the IDE and it will format your code with indents to show your { } config.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Hi,

Can I suggest you draw out a flow diagram showing the process of;
Reading the cell.
Checking the cell reading against the setpoint
Deciding if to keep the feeder open or closed.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

thank u tom... i just learned arduino, and just joined in this forum..so i didnt find "how to use this forum" yet. any way how to paste my coding?

why not something as simple as

// GitHub - olkal/HX711_ADC: Arduino library for the HX711 24-bit ADC for weight scales

#include <Wire.h>

#undef MyHW
#ifdef MyHW
# include "sim.h"

#define MAX_WT  400

const int pinBut = A1;
const int Relay  = LED_BUILTIN;

#else
# include <HX711_ADC.h>
# include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library

#define MAX_WT  1000

const int pinBut = A1;
const int Relay = 2;
#endif

HX711_ADC LoadCell (A0, A1); //
LiquidCrystal_I2C lcd (0x27, 16, 2); //

int wt;
int loadFlag;

enum { Off = LOW, On = HIGH };

// -----------------------------------------------------------------------------
void setup ()
{
    Serial.begin (9600);

    LoadCell.begin (); // start connection to HX711
    LoadCell.start (2000); // load cells gets 2000ms of time to stabilize
    LoadCell.setCalFactor (968.303); // calibration factor for load cell => strongly dependent on your individual setup

    lcd.init ();//begin (); // begins connection to the LCD module
    lcd.backlight (); // turns on the backlight

    pinMode (pinBut, INPUT_PULLUP);
    pinMode (Relay,  OUTPUT);
    digitalWrite (Relay, Off);
}

// -----------------------------------------------------------------------------
void 
loop ()
{
    LoadCell.update ();             // retrieves data from the load cell
    wt = LoadCell.getData ();  // get output value

    wtDisplay ();

    if (MAX_WT <= wt && loadFlag)  {
        digitalWrite (Relay, Off);
        Serial.println (" stop");
        loadFlag = 0;
    }

    if (LOW == digitalRead (pinBut))  {
        digitalWrite (Relay, On);
        loadFlag = 1;
    }

    delay (1000);
}

// -----------------------------------------------------------------------------
int
wtDisplay ()
{
    Serial.print   (" ");
    Serial.println (wt);

    lcd.setCursor (0, 0);           // set cursor to first row
    lcd.print ("Weight[g]:");       // print out to LCD
    lcd.setCursor (0, 1);           // set cursor to secon row
    lcd.print (wt);         // print out the retrieved value to the second row

    return wt;
}