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
}
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;
}
}
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.