Problem in intefacing Load Cell

Hello,
I want to connect Load Cell to Wemos D1 mini. My code without blynk displays the output value correct but when I add the blynk code, the output is 0. Please help me with this issue. I am using Blynk on Local Server.

Code Without Blynk:

#include <HX711.h>

// Scale Settings
const int SCALE_DOUT_PIN = D3;
const int SCALE_SCK_PIN = D4;

float threshold = 20.0;
float weight;
float lastWeight;
float height1;

HX711 scale;

void setup() {
  Serial.begin(9600);
  scale.begin(SCALE_DOUT_PIN, SCALE_SCK_PIN);
  scale.set_scale(-1984588.00 / 91.6);// <- set here calibration factor!!!
  scale.tare();
}

void loop() {
  weight = scale.get_units(1);
  lastWeight = weight;
  if (weight > threshold) {
    Serial.println(String(weight, 2));
  }

  else {
    weight = 0.00;
    Serial.println(String(weight, 2));
   }
}

Code with Blynk:

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>

#include <HX711.h>

char auth[] = "XXXXXXXXXXXXXXXXXXXXXX";
char ssid[] = "XXXXXx";
char pass[] = "XXXXXXXXX";

// Scale Settings
const int SCALE_DOUT_PIN = D3;
const int SCALE_SCK_PIN = D4;

float threshold = 20.0;
float weight;

HX711 scale;
BlynkTimer timer;

void sendSensor() {
  
  if (weight > threshold) {
    Blynk.virtualWrite(V1, String(scale.get_units(1),1));
  }

  else {
    weight = 0.00;
    Serial.println(String(weight, 2));
    Blynk.virtualWrite(V1, weight);
   }
}

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(X, X, X, X), 8080);
  scale.begin(SCALE_DOUT_PIN, SCALE_SCK_PIN);
  scale.set_scale(-1984588.00 / 91.6);// <- set here calibration factor!!!
  scale.tare();

  timer.setInterval(1000L, sendSensor);
}

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

Your sendSensor function is missing the bit of code that takes a reading from the HX711 :slightly_smiling_face:

You forgot this line when you moved it out of your void loop:

 weight = scale.get_units(1)

Pete.

1 Like

@PeteKnight Thanks for reply.
I have updated the code and tried it, but still the problem exist. The output still shows 0.

My updated Code:

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial

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

#include <HX711.h>

char auth[] = "XXXXXXXXXXXXXX";
char ssid[] = "XXXXXXXXx";
char pass[] = "XXXXXXXx";

// Scale Settings
const int SCALE_DOUT_PIN = D3;
const int SCALE_SCK_PIN = D4;

float threshold = 20.0;
float weight;

HX711 scale;
BlynkTimer timer;

void sendSensor() {
  weight = scale.get_units(1);
  
  if (weight > threshold) {
    Serial.println(String(weight, 2));
    Blynk.virtualWrite(V1, String(weight, 2));
  }

  else {
    weight = 0.00;
    Serial.println(String(weight, 2));
   }
}

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(X, X, X, X), 8080);
  scale.begin(SCALE_DOUT_PIN, SCALE_SCK_PIN);
  scale.set_scale(-1984588.00 / 91.6);// <- set here calibration factor!!!
  scale.tare();

  timer.setInterval(100L, sendSensor);
}

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

Try adding:

Serial.println(String(weight, 2));

immediately after:

weight = scale.get_units(1);

just to see what value you’re getting before you do any processing on it.

If that still shows zero when you apply some pressure to the load cell (after you’ve booted-up your MCU, as the tare function will zero-out any weight that’s applied at start-up) then check your connections and re-load your original code to make sure it’s still working correctly.

Pete.