Dear ALL, I'm very new on arduino ,
I need help to solve at my project.
Description on my project
I use load cell, motor stepper (to move chain), motor servo (to reject product), LCD, Keypad
and the Function
If I push button "A" Motor running
If I push button "B" load cell Weighing after 2 second arduino will decided good/bad product and send order to servo to move from position 0 to 90.(problem motor servo can't hold position at least 2 second) another problem how to make motor stepper move after 2 second arduino decide good/bad product)
Problem:
- How to show up the text on LCD while i turn on the motor(Fyi, i already try to combine on void motor i input "program LCD" but the result is LCD blank and motor run very slow?
- How to make servo at pos 90'(bad) little bit hold the position while we push the product?
- How to make stepper move while arduino decide product good/bad?
Thanks
Best Regards
Doni
this is the program:(i combine all programs as possible)
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Keypad.h>
#include <HX711_ADC.h>
#include <EEPROM.h>
#include <Servo.h>
//Servo
Servo servo;
int pos = 0;
// Keypad
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
 {'1', '2', '3', 'A'},
 {'4', '5', '6', 'B'},
 {'7', '8', '9', 'C'},
 {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {46, 44, 42, 40};
byte colPins[COLS] = {38, 36, 34, 32};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
// LCD
LiquidCrystal_I2C lcd(0x27, 20, 4);
//HX711
const int HX711_dout = 6; //mcu > HX711 dout pin
const int HX711_sck = 7; //mcu > HX711 sck pin
const int calVal_calVal_eepromAdress = 0;
long t;
HX711_ADC LoadCell(HX711_dout, HX711_sck);
//Sensor PX dan IR
int ir = 31;
int px = 30;
unsigned long preMil = 0;
unsigned long previousMicros = 0;
const long interval = 1500;
int PULPin = 3;Â Â // PUL- pin
int DIRPin = 2;Â Â // DIR- pin
int PULState = HIGH;
int B = 0;
float j;
float i;
void setup() {
 // servo
 servo.attach(9);
 // Setup HX711
 Serial.begin(9600); delay(10);
 Serial.println();
 Serial.println("Starting...");
 float calibrationValue; // calibration value
 calibrationValue = 696.0; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266) || defined(ESP32)
#endif
 value from eeprom
 LoadCell.begin();
 long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time
 boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
 LoadCell.start(stabilizingtime, _tare);
 if (LoadCell.getTareTimeoutFlag()) {
  Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
 }
 else {
  LoadCell.setCalFactor(calibrationValue); // set calibration factor (float)
  Serial.println("Startup is complete");
 }
 while (!LoadCell.update());
 Serial.print("Calibration value: ");
 Serial.println(LoadCell.getCalFactor());
 Serial.print("HX711 measured conversion time ms: ");
 Serial.println(LoadCell.getConversionTime());
 Serial.print("HX711 measured sampling rate HZ: ");
 Serial.println(LoadCell.getSPS());
 Serial.print("HX711 measured settlingtime ms: ");
 Serial.println(LoadCell.getSettlingTime());
 Serial.println("Note that the settling time may increase significantly if you use delay() in your sketch!");
 if (LoadCell.getSPS() < 7) {
  Serial.println("!!Sampling rate is lower than specification, check MCU>HX711 wiring and pin designations");
 }
 else if (LoadCell.getSPS() > 100) {
  Serial.println("!!Sampling rate is higher than specification, check MCU>HX711 wiring and pin designations");
 }
 //Setup LCD
 lcd.clear();
 lcd.begin();
 lcd.backlight();
 //Setup Stepper
 pinMode (PULPin, OUTPUT);
 pinMode (DIRPin, OUTPUT);
 //Setup Sensor PX dan IR
 pinMode(px, INPUT);
 pinMode(ir, INPUT);
}
void MSON()//Motor Stepper ON
{
 digitalWrite(DIRPin, LOW);
 unsigned long currentMicros = micros();
 if (currentMicros - previousMicros >= interval)
 {
  previousMicros = currentMicros;
  if (PULState == HIGH)
  {
   PULState = LOW;
  }
  else {
   PULState = HIGH;
  }
  digitalWrite(PULPin, PULState);
 }
 // unsigned long curMil = millis();
 // if (curMil - preMil >= 100)
 // {preMil = curMil;
 // }
}
void weighing()
{
 lcd.print("weight : ");
 lcd.setCursor(15, 2);
 lcd.print("gram");
 static boolean newDataReady = 0;
 const int serialPrintInterval = 500; //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)
  {
   float i = LoadCell.getData();
   Serial.print("Load_cell output val: ");
   Serial.println(i);
   float j = i / 10;
   lcd.setCursor(8, 2);
   lcd.print(j);
   if (j >= 60 && j <= 71.0)
   {
    lcd.setCursor(0, 3);
    lcd.print("Good");
   }
   if (j < 60 || j > 71.0)
   {
    lcd.setCursor(0, 3);
    lcd.print("Bad");
   }
   newDataReady = 0;
   t = millis();
  }
 }
 // receive command from serial terminal, send 't' to initiate tare operation:
 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");
 }
}
void loop()
{
 if (B == 0)
 {
  lcd.setCursor(0, 0);
  lcd.print("Tekan tombol untuk");
  lcd.setCursor(1, 1);
  lcd.print("A : START MOTOR");
  lcd.setCursor(2, 2);
  lcd.print("B : START Weighing");
 }
 char customKey = customKeypad.getKey();
 switch (customKey)
  if (B == 3)
  {
   lcd.setCursor(0, 0);
   lcd.print("Press button for");
   lcd.setCursor(1, 1);
   lcd.print("A : START MOTOR");
   lcd.setCursor(2, 2);
   lcd.print("B : START Weighing");
  }
 if (B == 1)
 { MSON();
 }
 if (B == 2)
 {
  for (int x = 0; x < 201 ; x++)
  { weighing();
   Serial.println("Progress Weighing");
  }
  for (int x = 200; x >= 1 ; x--)
  {
   Serial.println("Servo");
   if (j >= 60 && j <= 71.0)
   {
    Serial.println("good");
    servo.write(0);
   }
   else
   { Serial.println("bad");
    servo.write(90);
   }
   lcd.clear();
   B = 1;
  }
 }
}