Help me: Control weight with Arduino+ Loadcel+Keypad 4x4+ LCD 16x2+ 2 Step motor

I have 1 project about : Loadcell + Keypad 4x4+ Lcd 16x2+ 2 Stepmotor.

Operating principle my project :

  1. Set the display value to LCD (Value not to exceed 6000 ~ 6 kg)

  2. Press the "A" key to start the quantification process.

  3. Step motor 1 open rice farm in tank 1 into tank 2 with loadcell (Step motor rotate)

  4. When loadcell = Set value, Step motor 1 (Reverse)

  5. Step motor 2 open the tank door 2 (turn it) when the loadcell value is 0, the stepper motor 2 closes (Reverse)

  6. Repeat the process by pressing "A"

  7. Press "B" to set new volume if needed.


Because im newbie so i dont understand anthing about Arduino. I write code in IDE have many error.I hope to get help from forum arduino... Thanks so much, because this is the important project.

1 Like

Because im newbie so i dont understand anthing about Arduino.

This classroom assignment is too difficult for a beginner.

Start with the basic examples provided with the Arduino IDE (software development package, File>Examples>...).

Learn how to blink an LED, read a voltage using the analog input, etc.

1 Like

My code... I dont new idea ! :cry: :"( :"(

LHD_2017.ino (5.18 KB)

1 Like

Delta_G:
You said you had lots of errors. You can't have errors without code. Please post the code and the text of the errors. Without that there is nothing anyone can do to help you. How can we help you fix errors that we can't see?

If you don't want to post the code then you are wasting your time and our time here.

I do not know how to enter the value from the keypad and show up on the LCD. I do not know how to compare the input value with the value received from loadcell to output stepper motor control signal.
Can you help me improve my program? My English not good. But i hope u understand me.

1 Like

Delta_G:
Improve what program. You haven't shown us any program. I know your english isn't good, but hopefully you understand that you won't get anywhere here without posting your code. This is the last time I am asking. If your next post doesn't include the code you want help with then I will simply ignore you from now on.

So sorry.
I'm sorry to bother you !


My code:

#include <Keypad.h>

/* LOADCELL VS LCD*/
#include "HX711.h" //You must have this library in your arduino library folder
#include <LiquidCrystal.h>
/*********** LOAD CELL ************/
#define DOUT 3
#define CLK 2
HX711 scale(DOUT, CLK);

/*********** KEYPAD************/

volatile int firstnumber=99; // used to tell how many numbers were entered on keypad
volatile int secondnumber=99;
volatile int thirdnumber=99;
const byte rows = 4; //sô´ ha`ng
const byte columns = 4; //sô´ cô?t

int holdDelay = 700; //Thoi gian trê~ dê? xem la nhâ´n 1 nu´t nham tra´nh nhiê~u int n = 3; // int state = 0; //nê´u state =0 ko nhâ´n,state =1 nhâ´n thoi gian nho? , state = 2 nhâ´n giu~ lâu
char key = 0;

//Ði?nh nghi~a ca´c gia´ tri? tra? vê`
char keys[rows][columns] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'},
};

byte rowPins[rows] = {28, 30, 32, 34}; //Ca´ch nô´i chân vo´i Arduino
byte columnPins[columns] = {36, 38, 40, 42};

//cĂ i d?t thu vi?n keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, columnPins, rows, columns);
/*********** LCD ************/
LiquidCrystal lcd(9, 8 , 7, 6, 5, 4);

//Change this calibration factor as per your load cell once it is found you many need to vary it in thousands
float calibration_factor = -96650; //-106600 worked for my 40Kg max scale setup

//=============================================================================================
// SETUP
//=============================================================================================
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
lcd.print(" CAN DINH LUONG");
delay (1000);
lcd.setCursor (0, 1);
lcd.print ("Khoi luong");
lcd.setCursor (14, 1);
lcd.print ("Gr");
Serial.println("Thu HX711");
Serial.println("Truoc khi set ti le:");
Serial.print("doc: \t\t");
Serial.println(scale.read());
Serial.print("doc gia tri trung binh: \t\t");
Serial.println(scale.read_average(20));

Serial.print("lay gia tri: \t\t");
Serial.println(scale.get_value(5));
Serial.print("lay don vi: \t\t");
Serial.println(scale.get_units(5), 1);

scale.set_scale(-169.44444);
scale.tare();
Serial.println("Sau khi thiet lap ti le:");

Serial.print("doc : \t\t");
Serial.println(scale.read());

Serial.print("doc gia tri trung binh : \t\t");
Serial.println(scale.read_average(20));

Serial.print("lay gia tri: \t\t");
Serial.println(scale.get_value(5));
Serial.print("lay don vi: \t\t");
Serial.println(scale.get_units(5), 1);
Serial.println();
Serial.println("DOC GIA TRI:");
}

void loop() {
/* LOADCELL*/

Serial.print("doc 1 lan:\t");
Serial.print(scale.get_units(), 1);
Serial.print("\t| trung binh 10 lan doc:\t");
Serial.println(scale.get_units(10), 1);
/* SET VALUE KEYPAD AND DISPLAY LCD*/
char key = keypad.getKey ();
if (key != NO_KEY)
{ // If keypad button pressed check which key it was
switch (key) {

case '1':
checknumber(1);
break;

case '2':
checknumber(2);
break;

case '3':
checknumber(3);
break;

case '4':
checknumber(4);
break;

case '5':
checknumber(5);
break;

case '6':
checknumber(6);
break;

case '7':
checknumber(7);
break;

case '8':
checknumber(8);
break;

case '9':
checknumber(9);
break;

case '0':
checknumber(0);
break;

case '*':
deletenumber();
break;

case '#':
break;
}
}

}

void checknumber(int x){
if (firstnumber == 99)
{ // Check if this is the first number entered
firstnumber=x;
String displayvalue = String(firstnumber); // Transform int to a string for display
lcd.setCursor(9,1);
lcd.print(displayvalue); // Redraw Nokia lcd

}
else {
if (secondnumber == 99) { // Check if it's the second number entered
secondnumber=x;
String displayvalue = (String(firstnumber) + String(secondnumber));
lcd.setCursor (9,1);
lcd.print (displayvalue);

} else { // It must be the 3rd number entered
thirdnumber=x;
String displayvalue = (String(firstnumber) + String(secondnumber) + String(thirdnumber));
lcd.setCursor (9,1);
lcd.print (displayvalue);

}
}
}

void deletenumber() { // Used to backspace entered numbers
if (thirdnumber !=99) {
String displayvalue = (String(firstnumber) + String(secondnumber));
lcd.setCursor (9,1);
lcd.print (displayvalue);

thirdnumber=99;
}
else {
if (secondnumber !=99) {
String displayvalue = String(firstnumber);
lcd.setCursor (9,1);
lcd.print (displayvalue);

secondnumber=99;
}
else {
if (firstnumber !=99) {
String displayvalue = "";
lcd.setCursor (9,1);
lcd.print (displayvalue);

firstnumber=99;
}
}
}
}

/* CONTROL 2 STEP MOTOR*/

There is a program attached in reply #3 :wink: Not quite as we like it but that is a next step.

@Sakutaro1994
Nearly there; please use code tags; you can edit your previous post and add
** **[code]** **
before your code and
** **[/code]** **
after your code.

Please read "How to use this forum" and follow the directions. Edit your post to add code tags, and describe the errors.