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