How to use hx711 to light up led wedget

Hello, i had face some problem between the hx711 to light up my led wedget in my blynk app, here is my source code, hope someone show me the way, thanks.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "HX711.h"
 
const int LOADCELL_DOUT_PIN = D4; 
const int LOADCELL_SCK_PIN = D3; 

HX711 scale;

char auth[] = "4300a1aecd4f47d296d6769ef064d440";
char ssid[] = "oh";
char pass[] = "1234567890";

BLYNK_WRITE(V5) 
{ 
  scale.tare(); 
}

 BLYNK_READ(V3)
 {
  Blynk.virtualWrite(V3, scale.get_units(20));  
 }

WidgetLED led(V2);

void setup() 
{
  Serial.begin(57600);
  Blynk.begin(auth, ssid, pass);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(1040.f);
  BLYNK_CONNECTED();
  Blynk.syncAll();
 HX711limit();
}

void HX711limit()
{
  if (scale.get_units(20) >= 10) 
  {
  led.setValue(255);
  }
  else
  {
  led.setValue(0);
  }
}

void loop()
{
  Blynk.run();
}

sorry may i know how to upload my code?

The same way you did last time… but with the formatting characters at the beginning and the end of the code… as clearly explained in those links above :wink:

thanks

Good… thank you :slight_smile:

Now these should NOT be in your void setup()

But you do need to add in a Blynk timer that calls HX711limit() at whatever interval you want it to…

Or add a Blynk Write function to a virtual button and use that to call HX711limit()

More info here…

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/how-to-display-any-sensor-data-in-blynk-app

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/how-to-control-anything-with-blynk-app

thanks… is something look like this?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "HX711.h"
BlynkTimer timer;
 
const int LOADCELL_DOUT_PIN = D4; 
const int LOADCELL_SCK_PIN = D3; 

HX711 scale;

char auth[] = "4300a1aecd4f47d296d6769ef064d440";
char ssid[] = "oh";
char pass[] = "1234567890";

BLYNK_WRITE(V5) 
{ 
  scale.tare(); 
}

 BLYNK_READ(V3)
 {
  Blynk.virtualWrite(V3, scale.get_units(20));  
 }

WidgetLED led(V2);

void setup() 
{
  Serial.begin(57600);
  Blynk.begin(auth, ssid, pass);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(1040.f);
  timer.setInterval(500L, HX711limit);
}

void HX711limit()
{
  if (scale.get_units(20) >= 10) 
  {
  led.setValue(255);
  }
  else
  {
  led.setValue(0);
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}

That is one way… but you must have a display widget set to V3 and a reading rate of your choice for that to work (NOT PUSH) and it will only work when the App is open.

Another way is a Button set to something like V2 and using the BLYNK_WRITE() function that will send the value to the Display Widget on V3 (this time set to PUSH) each time you press a button…

 BLYNK_WRITE(V2)  {
   if (param.asInt == 1) {  // get the state of the button
     Blynk.virtualWrite(V3, scale.get_units(20));  
   }
}

thanks for the suggestion, but now my program need to use the hx711 to detect the load, if the load excess the limit like 2 kg will send data to V2 to activate the led widget.

That starts getting into “how to program”… not something I tend to start teaching new users about… besides, I am still teaching myself :stuck_out_tongue: But the if() processes and comparison logic like you started out with seems to be one way to go.

may i know what is one way to go?

Again, I am not going to get into “how to program”… I do have other things to do with my time :slight_smile:

But you did appear to have the basis already. Just learn to merge it into what you are also learning about Blynk functions, and keep experimenting.

ok thanks

Hi, i had a problem in read the value of hx711 in serial monitor, need to figure out why, could someone help out? thanks

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "HX711.h"

const int LOADCELL_DOUT_PIN = D4; 
const int LOADCELL_SCK_PIN = D3; 

HX711 scale;

char auth[] = "4300a1aecd4f47d296d6769ef064d440";
char ssid[] = "oh";
char pass[] = "1234567890";

void setup() 
{
 Serial.begin(57600);
 Blynk.begin(auth, ssid, pass);
 scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}

void loop() 
{
  Serial.println(scale.read());
  delay(500);
}

your loop does not meet the requirements of blynk :wink:

void loop() 
{
 timer.run();
 Blynk.run();
}

and Serial.println(scale.read()); need to be call with a timer

1 Like

:point_up: also what do you get in your serial monitor?

@Oh_Jia_Ming Please do NOT create multiple topics (or accounts :wink: ) for your same issues… I merged your two topics here.

1 Like