//Start By The Name Of Allaha
//This Code is written for Weighing scale by Technical minds
#include <HX711_ADC.h>
#include <LiquidCrystal_I2C.h>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif
//pins:
const int HX711_dout = 5; //mcu > HX711 dout pin
const int HX711_sck =18; //mcu > HX711 sck pin
const int tpin = 15; // the pin that the tare pushbutton is attached to
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
//LCD_12C:
LiquidCrystal_I2C lcd(0x27, 2, 16);
//EEPROM:
const int calVal_eepromAdress = 0;
unsigned long t = 0;
// Setup:
void setup() {
Serial.begin(57600); delay(10);
//Serial.println();
//Serial.println("Starting...");
pinMode(tpin, INPUT_PULLUP);
lcd.init();
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("BIN SHARIF");
lcd.setCursor(1, 1);
lcd.print("WEIGHING SCALE");
delay(2000);
lcd.clear();
//Start weighing:
LoadCell.begin();
//LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive
unsigned long stabilizingtime = 2000; // preciscion right after power-up 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() || LoadCell.getSignalTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
while (1);
}
else {
LoadCell.setCalFactor(420.0); // user set calibration value (float), initial value 1.0 may be used for this sketch
Serial.println("Startup is complete");
}
while (!LoadCell.update());
}
void loop() {
static boolean newDataReady = 0;
const int serialPrintInterval = 0; //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);
newDataReady = 0;
t = millis();
lcd.setCursor(0, 0);
lcd.print("BIN SHARIF SCALE:");
lcd.setCursor(0, 1);
lcd.print("WEIGHT :");
lcd.setCursor(9, 1);
lcd.print(i);
lcd.setCursor(14, 1);
lcd.print("KG");
}
}
if (digitalRead(tpin) == LOW) {
LoadCell.tareNoDelay();
}
// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
lcd.clear();
lcd.print("Tare complete");
delay(1000);
lcd.clear();
}
}