Hello to all Arduino Community,
At First, I want to tell you the hardware of my setup.
- Arduino Mega,
- Loadcell 100 Kgs,
- HX711 (weight sensor),
- LCD Keypad Shield,
- 4x4 Keypad,
- 4 Channel relay module,
Sir, I want to make a batching System, Where I want to input the weight of the batch manually by 4x4 keypad currently modify the weight in the program, i am confused how to use multiple digit input with 4x4 keypad.
i will try to explain what i want to do in simple words,
every time i power up the arduino it ask to enter the weight, i will enter the weight with the help of 4x4 keypad e.g. 70 kgs for that I will press 7, 0, and to confirm the weight I will press #,
After the confirmation i will put the weight over load cell and the LCD indicates that the weight is increasing, as the loadcell detect the 70 Kgs a relay is on. and as i remove the weight the relay will off again.
Here i am giving you my codes, where i have reached so far.
#define RELAY_ON 0
#define RELAY_OFF 1
const int rly = 12;
const int rly2 = 11;
#include "HX711.h"
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {21, 20, 19, 18}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {17, 16, 15, 14}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
#define calibration_factor -42990.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define zero_factor -51468 //This large value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT 3
#define CLK 2
HX711 scale(DOUT, CLK);
void setup() {
digitalWrite(rly, RELAY_OFF);
digitalWrite(rly2, RELAY_OFF);
lcd.begin(16,2);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor
lcd.setCursor(0,0);
lcd.print("Readings:");
pinMode(rly, OUTPUT);
pinMode(rly2, OUTPUT);
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Reading: ");
lcd.setCursor(2,1);
lcd.print(scale.get_units(), 1); //scale.get_units() returns a float
lcd.print("0 kg "); //You can change to kg but you'll need to change the calibration_factor
if (scale.get_units() > 3) { // here, in place of 3 Kgs i want to input the weight through 4x4 keypad
digitalWrite(rly, RELAY_ON);
}
else {
digitalWrite(rly, RELAY_OFF);
}
if (scale.get_units() > 5) {
digitalWrite(rly2, RELAY_ON);
}
else {
digitalWrite(rly2, RELAY_OFF);
}
}