#include <LiquidCrystal_I2C.h> // LiquidCrystal I2C - Version: 1.1.1
#include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
HX711_ADC LoadCell(4, 5); // dt pin, sck pin
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD HEX address 0x27
int taree = 6;
int a = 0;
float b = 0;
int rele1 = 8;
int rele2 = 7;
int vaha = 1000; // hranice vahy pro retrakci (g)
void setup() {
pinMode (taree, INPUT_PULLUP);
LoadCell.begin(); // zahaji komunikaci s HX711
LoadCell.start(1000); // snímače zatížení mají 1000 ms času na stabilizaci a vynulování
/////////////////////////////////////
LoadCell.setCalFactor(0.42); // Calibarate your LOAD CELL with 100g weight, and change the value according to readings
/////////////////////////////////////
//lcd.begin(); // begins connection to the LCD module
lcd.init(); // initialize the lcd
lcd.backlight(); // turns on the backlight
lcd.setCursor(1, 0); // set cursor to first row
lcd.print("Digital Scale "); // print out to LCD
lcd.setCursor(0, 1); // set cursor to first row
lcd.print(" 5KG MAX LOAD "); // print out to LCD
delay(3000);
lcd.clear();
pinMode (rele1, OUTPUT);
pinMode (rele2, OUTPUT);
digitalWrite(rele1, LOW);
digitalWrite(rele2, LOW);
}
void loop() {
lcd.setCursor(1, 0); // set cursor to first row
lcd.print("Digital Scale "); // print out to LCD
LoadCell.update(); // nacte data z vahy
float i = LoadCell.getData(); // get output value
if (i<0)
{
i = i * (-1);
lcd.setCursor(0, 1);
lcd.print("-");
lcd.setCursor(8, 1);
lcd.print("-");
}
else
{
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(8, 1);
lcd.print(" ");
}
lcd.setCursor(1, 1); // set cursor to secon row
lcd.print(i, 1); // vytiskněte načtenou hodnotu do druhého řádku
lcd.print("g ");
float z = i/28.3495;
lcd.setCursor(9, 1);
lcd.print(z, 2);
lcd.print("oz ");
if (i<vaha)
{
digitalWrite(rele2, LOW);
delay(100);
digitalWrite(rele1, HIGH); // pohyb motoru vpred
}
else if (i>=vaha)
{
digitalWrite(rele1, LOW); // pohyb motoru vpred
delay(100);
digitalWrite(rele2, HIGH);
}
if (i>=5000) //pri vaze nad 5kg napis pretizeni
{
i=0;
lcd.setCursor(0, 0); // set cursor to secon row
lcd.print(" Over Loaded ");
delay(200);
}
if (digitalRead (taree) == LOW) //pri stisku tlacitka proved taru
{
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(" Taring... ");
LoadCell.start(1000); // snímače zatížení mají 1000 ms času na stabilizaci a vynulování
lcd.setCursor(0, 1);
lcd.print(" ");
}
}