#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);
boolean valOnePresent = false;
String num1, num2;
boolean final = false;
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
char key = customKeypad.getKey();
if (key != NO_KEY && (key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9'||key=='0')){
if (valOnePresent != true){
num1 = num1 + key;
int numLength = num1.length();
lcd.setCursor(15 - numLength, 0); //to adjust one whitespace for operator
lcd.print(num1);
}
else if (scale.get_units()> 'num1') {
digitalWrite(rly, RELAY_ON);
}
else {
digitalWrite(rly, RELAY_OFF);
}
}
}