0% found this document useful (0 votes)
14 views2 pages

20Kg Scale Code

This document contains code for a 20KG digital scale using a Nextion display and HX711 load cell. It initializes the load cell, updates weight readings, and allows for unit conversion between kilograms and pounds. The code also includes functionality for tare operations and user input handling via serial communication.

Uploaded by

Adama Meite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

20Kg Scale Code

This document contains code for a 20KG digital scale using a Nextion display and HX711 load cell. It initializes the load cell, updates weight readings, and allows for unit conversion between kilograms and pounds. The code also includes functionality for tare operations and user input handling via serial communication.

Uploaded by

Adama Meite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//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;
}
}
}

You might also like