//Program code for digital weighing scale using Arduino and HX711 with load cell
#include <LiquidCrystal_I2C.h>
#include "HX711.h"
 
#define DEBUG_HX711
 
// calibration parameter from calibrating code with known values
#define CALIBRATION_FACTOR 38980.0
 
// Create the lcd object address 0x3F and 16 columns x 2 rows 
LiquidCrystal_I2C lcd (0x27, 16,2);
 
// data pin and clock pin
byte pinData = 3;
byte pinClk = 2;
 
// define HX711
HX711 scale;
 
void setup() {
   
  lcd.init();
  lcd.backlight();
  lcd.print( "ECHELLE DE POIDS" );
  lcd.init();
  //lcd.setCursor (0, 0);
 


#ifdef DEBUG_HX711
  // Initialize serial communication
  Serial.begin(9600);
  Serial.println("[HX7] Sensor start HX711");

#endif
 
  //Initializing sensor
  scale.begin(pinData, pinClk);
  // apply the calibration value
  scale.set_scale(CALIBRATION_FACTOR);
  // Initialize the tare
  //Assuming there is no weight on the scale at start up, reset the scale to 0
  scale.tare();
}
 
void loop() {
#ifdef DEBUG_HX711
  Serial.print("LECTURE DE POIDS: ");
  Serial.print(scale.get_units(), 2);
  Serial.print(" Kgs");
  Serial.println();
#endif
lcd.setCursor (0, 0);
lcd.print( "LECTURE DE POIDS:" );
lcd.setCursor (0, 1);
lcd.print(scale.get_units(), 3);
lcd.print(" Kgs");
if( scale.get_units()>=3){ 
  lcd.setCursor (9, 1);
  lcd.print(" S1:ON ");
 
 }
 else{ 
  lcd.setCursor (9, 1);
  lcd.print(" S1:OFF ");
  }
}