How can we define kilograms and grams in arduino?

how can we define kilograms and grams in arduino??

const uint8_t gramm = 1;
const uint16_t kilogramm = 1000 * gramm;
1 Like

its unit
or
uint

irrelevant.
What is the question?

and
can i say that if the loadcell gets weight greater than 250 grams the high voltage at pin 13
by this code?? as in this the first line i have just written it 250 so how the program know that this is 250 grams

 if (scale.get_units() <= 250)
 {
   digitalWrite(13, HIGH);
    }
  else {
       digitalWrite(13, LOW);
          }

Hello good morning
How to define grams and kilograms in HX711?
as i am did some experiment using some illogical formulas

grams = weight * 1000;

But that doesn't working.

So, any help?

Thank you!

What units do you have the weight in at the moment ?

Please post your code

Yes, you can code that if the loadcell gets weight greater than 250 the pin 13 should go high.

@ dssingh
Your duplicate topics have been merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

so i can direct write 250 or i have to write grams

 if (scale.get_units() <= 250)
 {
   digitalWrite(13, HIGH);
    }
  else {
       digitalWrite(13, LOW);
          }

what do you get from scale.get_uints()?
a) a number like 250
b) a char array, string, String object like "250 gram"

My whole code

#include <HX711.h>
HX711 scale;

#define DT A0
#define SCK A1
#define sw 9

const uint8_t gramm = 1;
const uint16_t kilogramm = 1000 * gramm;

long sample=0;
float val=0;
long count=0;

unsigned long readCount(void)
{
unsigned long Count;
unsigned char i;
pinMode(DT, OUTPUT);
digitalWrite(DT,HIGH);
digitalWrite(SCK,LOW);
Count=0;
pinMode(DT, INPUT);
while(digitalRead(DT));
for (i=0;i<24;i++)
{
digitalWrite(SCK,HIGH);
Count=Count<<1;
digitalWrite(SCK,LOW);
if(digitalRead(DT))
Count++;
}
digitalWrite(SCK,HIGH);
Count=Count^0x800000;
digitalWrite(SCK,LOW);
return(Count);
}

void setup()
{
pinMode(13, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(sw, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.print(" Weight ");
lcd.setCursor(0,1);
lcd.print(" Measurement ");
delay(1000);
lcd.clear();
calibrate();
}

void loop()
{

 if (scale.get_units() <= 250)
 {
   digitalWrite(13, HIGH);
    }
  else {
       digitalWrite(13, LOW);
          }
count= readCount();
int w=(((count-sample)/val)-2*((count-sample)/val));
lcd.setCursor(0,0);
lcd.print("Measured Weight");
lcd.setCursor(0,1);
lcd.print(w);
lcd.print("g ");

if(digitalRead(sw)==0)
{
val=0;
sample=0;
w=0;
count=0;
calibrate();
}
}

void calibrate()
{
lcd.clear();
lcd.print("Calibrating...");
lcd.setCursor(0,1);
lcd.print("Please Wait...");
for(int i=0;i<100;i++)
{
count=readCount();
sample+=count;
}
sample/=100;
lcd.clear();
lcd.print("Put 100g & wait");
count=0;
while(count<1000)
{
count=readCount();
count=sample-count;
}
lcd.clear();
lcd.print("Please Wait....");
delay(2000);
for(int i=0;i<100;i++)
{
count=readCount();
val+=sample-count;
}
val=val/100.0;
val=val/100.0; // put here your calibrating weight
lcd.clear();
}

hey man i don't know too much about arduino coding i am new to it
i wanted to know that if i put this code in arduino then if i put 250 grams on loadcell then led will be ONN or OFF ? I just wanted to know that only

this is my code

#include <HX711.h>
HX711 scale;

#define DT A0
#define SCK A1
#define sw 9

const uint8_t gramm = 1;
const uint16_t kilogramm = 1000 * gramm;

long sample=0;
float val=0;
long count=0;

unsigned long readCount(void)
{
unsigned long Count;
unsigned char i;
pinMode(DT, OUTPUT);
digitalWrite(DT,HIGH);
digitalWrite(SCK,LOW);
Count=0;
pinMode(DT, INPUT);
while(digitalRead(DT));
for (i=0;i<24;i++)
{
digitalWrite(SCK,HIGH);
Count=Count<<1;
digitalWrite(SCK,LOW);
if(digitalRead(DT))
Count++;
}
digitalWrite(SCK,HIGH);
Count=Count^0x800000;
digitalWrite(SCK,LOW);
return(Count);
}

void setup()
{
pinMode(13, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(sw, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.print(" Weight ");
lcd.setCursor(0,1);
lcd.print(" Measurement ");
delay(1000);
lcd.clear();
calibrate();
}

void loop()
{

 if (scale.get_units() <= 250)
 {
   digitalWrite(13, HIGH);
    }
  else {
       digitalWrite(13, LOW);
          }
count= readCount();
int w=(((count-sample)/val)-2*((count-sample)/val));
lcd.setCursor(0,0);
lcd.print("Measured Weight");
lcd.setCursor(0,1);
lcd.print(w);
lcd.print("g ");

if(digitalRead(sw)==0)
{
val=0;
sample=0;
w=0;
count=0;
calibrate();
}
}

void calibrate()
{
lcd.clear();
lcd.print("Calibrating...");
lcd.setCursor(0,1);
lcd.print("Please Wait...");
for(int i=0;i<100;i++)
{
count=readCount();
sample+=count;
}
sample/=100;
lcd.clear();
lcd.print("Put 100g & wait");
count=0;
while(count<1000)
{
count=readCount();
count=sample-count;
}
lcd.clear();
lcd.print("Please Wait....");
delay(2000);
for(int i=0;i<100;i++)
{
count=readCount();
val+=sample-count;
}
val=val/100.0;
val=val/100.0; // put here your calibrating weight
lcd.clear();
}

This is another link of my one of the problem
please solve it

How can I glow an led when the loadcell measures weight smaller than 250 grams
I am using 20 kg loadcell, HX711, lcd, Arduino uno

Main Question:-
how can i modify this code so i can glow light if i put a weight smaller than 250 grams??

this is my code

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <HX711.h>
HX711 scale;

#define DT A0
#define SCK A1
#define sw 9

long sample=0;
float val=0;
long count=0;

unsigned long readCount(void)
{
unsigned long Count;
unsigned char i;
pinMode(DT, OUTPUT);
digitalWrite(DT,HIGH);
digitalWrite(SCK,LOW);
Count=0;
pinMode(DT, INPUT);
while(digitalRead(DT));
for (i=0;i<24;i++)
{
digitalWrite(SCK,HIGH);
Count=Count<<1;
digitalWrite(SCK,LOW);
if(digitalRead(DT))
Count++;
}
digitalWrite(SCK,HIGH);
Count=Count^0x800000;
digitalWrite(SCK,LOW);
return(Count);
}

void setup()
{
pinMode(SCK, OUTPUT);
pinMode(sw, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.print(" Weight ");
lcd.setCursor(0,1);
lcd.print(" Measurement ");
delay(1000);
lcd.clear();
calibrate();
}

void loop()
{
count= readCount();
int w=(((count-sample)/val)-2*((count-sample)/val));
lcd.setCursor(0,0);
lcd.print("Measured Weight");
lcd.setCursor(0,1);
lcd.print(w);
lcd.print("g ");

if(digitalRead(sw)==0)
{
val=0;
sample=0;
w=0;
count=0;
calibrate();
}

i am new to arduino programming
Please help me

if (w<250) analogWrite(pwmPin,pwm250) else analogWrite(pwmPin,255);
lcd.print(w);
lcd.print("g ");
digitalWrite(LEDPin, w < 250);

Or, to also be compatible with the NANO Every:

digitalWrite(LEDPin, (w < 250) ? HIGH : LOW);

Hello, Good Afternoon
I am making a project in which if the loadcell gets weight more than "X" the led should blink.
Suppose :- If loadcell gets weight more than 1kg the LED1 should be continuous ONN, and if loadcell gets weight more than 5kg the LED2 should be continuous ONN , And If loadcell gets weight more than 19kg the BUZZER1 should be continuous ONN as it gets near to max weight of loadcell which is 20kg.

I am using
Arduino UNO, LCD, Loadcell 20kg, HX711 Amplifier

My code is

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <HX711.h>
HX711 scale;

#define DT A0
#define SCK A1
#define sw 9

long sample=0;
float val=0;
long count=0;

unsigned long readCount(void)
{
unsigned long Count;
unsigned char i;
pinMode(DT, OUTPUT);
digitalWrite(DT,HIGH);
digitalWrite(SCK,LOW);
Count=0;
pinMode(DT, INPUT);
while(digitalRead(DT));
for (i=0;i<24;i++)
{
digitalWrite(SCK,HIGH);
Count=Count<<1;
digitalWrite(SCK,LOW);
if(digitalRead(DT))
Count++;
}
digitalWrite(SCK,HIGH);
Count=Count^0x800000;
digitalWrite(SCK,LOW);
return(Count);
}

void setup()
{
pinMode(SCK, OUTPUT);
pinMode(sw, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.print(" Weight ");
lcd.setCursor(0,1);
lcd.print(" Measurement ");
delay(1000);
lcd.clear();
calibrate();
}

void loop()
{
count= readCount();
int w=(((count-sample)/val)-2*((count-sample)/val));
lcd.setCursor(0,0);
lcd.print("Measured Weight");
lcd.setCursor(0,1);
lcd.print(w);
lcd.print("g ");

if(digitalRead(sw)==0)
{
val=0;
sample=0;
w=0;
count=0;
calibrate();
}
}

void calibrate()
{
lcd.clear();
lcd.print("Calibrating...");
lcd.setCursor(0,1);
lcd.print("Please Wait...");
for(int i=0;i<100;i++)
{
count=readCount();
sample+=count;
}
sample/=100;
lcd.clear();
lcd.print("Put 100g & wait");
count=0;
while(count<1000)
{
count=readCount();
count=sample-count;
}
lcd.clear();
lcd.print("Please Wait....");
delay(2000);
for(int i=0;i<100;i++)
{
count=readCount();
val+=sample-count;
}
val=val/100.0;
val=val/100.0; // put here your calibrating weight
lcd.clear();
}

Somebody help me

Hello Good afternoon
I want to build a project in which i can enter value then the value i have put in the machine will fill that much grams only.
Note:- 1) The value can be changeable
2)The code and circuit diagram should be provided.
3) Most Important- NO pcbs should be used

Hope some body helpss

This seems a great ask for the Gigs and Collaboration forum. Make sure you mention your budget.

1 Like