Need to activate four servo motors based on load cell data for development of weight base grader.
I'm new for this for I tried my best and created a programme.
On LCD it showing the exact weight but the servo motors are getting fluctuations.
can you please help by checking the below mentioned programme..
#include <Servo.h>
#include <HX711_ADC.h>
#include <Wire.h>
#include <LiquidCrystal.h>
HX711_ADC LoadCell(3, 2);
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
float calibration_factor = 135; // this calibration factor is adjusted according to my load cell
float units;
float ounces;
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
void setup() {
Serial.begin(9600);
LoadCell.begin();
LoadCell.start(2000.10);
LoadCell.setCalFactor(399.30);
myservo1.attach(8); //servo pins digital
myservo2.attach(9);//servo pins
myservo3.attach(10);//servo pins
myservo4.attach(13);//servo pins
//scale.set_scale();
//scale.tare(); //Reset the scale to 0
//long zero_factor = scale.read_average(); //Get a baseline reading
//Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
//Serial.println(zero_factor);
lcd.begin(16, 2);
}
void loop() {
LoadCell.update();
float i = LoadCell.getData();
Serial.println ("i");
lcd.setCursor(0, 0);
lcd.print("Weight[g]:");
lcd.setCursor(0, 1);
lcd.print(i);
// scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
//units = scale.getData(), 10;
if (i < 0)
{
i = 0.00;
}
ounces = i * 0.035274;
Serial.print(i);
Serial.print(" grams");
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
if (i >100 && i <105)
{
myservo1.write(180); // if weight is more than 100 gm then servo motor move 180 degree anti clockwise
delay(5); // waits 15ms for the servo to reach the position
myservo1.write(-180);
}
if (i > 105 && i <110) // if weight is more than 105 gm then servo motor move 180 degree clockwise
{
myservo2.write(180); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
myservo2.write(-180);
}
if (i > 110 && i <115) // if weight is more than 110 gm then servo motor move 180 degree clockwise
{
myservo3.write(180); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
myservo3.write(-180);
}
if (i > 115 && i <120) // if weight is more than 115 gm then servo motor move 180 degree clockwise
{
myservo4.write(180); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
myservo4.write(-180);
}
delay(5);
lcd.setCursor(0, 0);
{
lcd.print("Weight(g)="); // Weight print in lcd
lcd.println(i);
}
}