//20KG Digital Scale Using Nextion Display by:
// Engineer USMAN AHMAD
// Easy HomeMade Projects (YouTube)
#include <HX711_ADC.h>
#include <Wire.h>
HX711_ADC LoadCell(4, 5); // data pin, clock pin
int u = 0;
int unit = 0;
void setup() {
Serial.begin(9600); //The default baud rate of the
Nextion TFT is 9600.
LoadCell.begin(); // start connection to HX711
LoadCell.start(1000); // load cells gets 500ms of time to stabilize
LoadCell.setCalFactor(103);
void loop()
{
Serial.print("t0.txt=\"TARE\""); //We print the variable we
want to cahnge on the screen
Serial.write(0xff); //Always add 3 full bytes
after...
Serial.write(0xff);
Serial.write(0xff);
if(u==0)
{
LoadCell.update();
int i = LoadCell.getData();
int Value = i;
Serial.print("data.val="); //We print the variable we want to
cahnge on the screen
Serial.print(Value); //Print the value we want to be
displayed
Serial.write(0xff); //Always add 3 full bytes after...
Serial.write(0xff);
Serial.write(0xff);
Serial.print("t2.txt=\"KG\""); //We print the variable we want
to cahnge on the screen
Serial.write(0xff); //Always add 3 full bytes
after...
Serial.write(0xff);
Serial.write(0xff);
}
if(u==1)
{
LoadCell.update();
int i = LoadCell.getData();
int Value = i*2.2046;
Serial.print("data.val="); //We print the variable we want to cahnge
on the screen
Serial.print(Value); //Print the value we want to be
displayed
Serial.write(0xff); //Always add 3 full bytes after...
Serial.write(0xff);
Serial.write(0xff);
Serial.print("t2.txt=\"LB\""); //We print the variable we want
to cahnge on the screen
Serial.write(0xff); //Always add 3 full bytes
after...
Serial.write(0xff);
Serial.write(0xff);
}
if(Serial.available()>0)
{
String Received = Serial.readString();
if(int(Received[0]) == 1)
{
Serial.print("t0.txt=\"TARING\""); //We print the variable we
want to cahnge on the screen
Serial.write(0xff); //Always add 3 full bytes
after...
Serial.write(0xff);
Serial.write(0xff);
LoadCell.start(1000);
}
if((int(Received[0]) == 2)&&(u==1))
{
u=0;
Received[0]=0;
}
if((int(Received[0]) == 2)&&(u==0))
{
u=1;
Received[0]=0;
}
}
}