How to blink led using loadcell

Hello Everyone
I am new to arduino programming
i have made a weight measurement machine by seeing this Video and in this video i got this Circuit Diagram

I wanted to know that how can i blink a led if the loadcell get weight more than 50 grams.

I am using

Arduino Uno 
16*2 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

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

int gr = gramm;
int kgr = kilogramm;

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()
{
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();
}

 if (scale.get_units() > 50)
 {
   digitalWrite(13, HIGH);
    }
  else {
       digitalWrite(13, LOW);
          }

}

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();
}

I used this but it didnt work

 if (scale.get_units() > 50)
 {
   digitalWrite(13, HIGH);
    }
  else {
       digitalWrite(13, LOW);
          }

Hope this much information is enough.

You will need the loop() function not to be blocked whilst the LED is blinking because you will need to continue reading the load cell

I would read the weight and if it is above the limit set a boolean variable to true, otherwise set it to false. Then in loop() test the boolean and if it is true change the state of the LED with the timing being measured using the value of millis().

See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE

is this the same as Led using loadcell

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.