ESP8266 not sending sensor data

I am using a wifi connection, The latest library version, and an esp8266.

I have tried many solutions but none of them worked. I am trying to send load cell sensor data through Blynk servers and have it read out in the phone app. I have tried everything I could find. The sensors have been tested and work on the board, the problem is sending the data, NOT with the sensors themselves. ( I did put in my auth key and network+password. I removed them to post this.) If you know what’s wrong please post about how to fix it. Any help is greatly appreciated.
Here is my code:


#define BLYNK_PRINT Serial


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

char auth[] = "AUTHKEY";
char ssid[] = "NETWORK";
char pass[] = "PASSWORD";

#define calibration_factor -8680.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT  D1
#define CLK  D2
  
HX711 scale;
 

BlynkTimer timer;

void sendSensor()
{
 
  Blynk.virtualWrite(V5, DOUT);
  Blynk.virtualWrite(V6, CLK);
}
void setup() {
 
  // put your setup code here, to run once:
  Serial.begin(9600);
  /*scale.tare();
  Serial.println("HX711 scale");
 
  scale.begin(DOUT, CLK);
  scale.set_scale(-8680.0); 
    Serial.println("Readings:");
//HX711 begin(scale);
  //HX711 begin();*/
  Blynk.begin(auth, ssid, pass);
  scale.tare();
  timer.setInterval(1000L, sendSensor);
  
}
void loop() {
  // put your main code here, to run repeatedly:
   timer.run();
  /*Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();*/
  Blynk.run();

}

The Blynk library can’t read the data directly from the D1 and D2 pins on your NodeMCU and send it to the app via the Blynk server.

Instead, you need to use the HX711 library to take the weight reading and assign the result to a variable. You can then send the value of this variable to the Blynk server/app.

There are quite a few examples of using the HX711 with Blynk, here is one example…

Pete.

I did originally have it on pins d5 and d6 and also tried d3 and d2. That was my last attempt

I tried calling the HX711 read function before the VirtualWrite function but that did not fix it. I Just want it to talk to the phone app, I don’t need to include an additional screen. I have already tried LOTS of sketches but I couldn’t get any of them to work.

From a Blynk point of view, it doesn’t matter which pins you use, it simply can’t talk directly to the HX711 board directly.

The HX711.h library is the interface between the HX711 board and your NodeMCU. This library will be concerned about which pins you use, and that will depend on which type of HX711 board you are using.

If you don’t want to use one of the many examples already on this forum then I’d suggest that you get your code working so that it correctly prints the weight information to the serial monitor, then once you’ve done that add-in the code to send the same data to the Blynk server/app.

Pete.

I think you need to step back a bit. Take the basic sketch builder sketch and let’s get you going with switching on a virtual led with a virtual button.

1 Like

@daveblynk I have done that, I also did one with a DHT11 sensor, and it read the correct data on the app (temp. and humidity) I tried to combine the code that sends the data with this sketch but it clearly didn’t work.


#define calibration_factor -9000.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define DOUT  3
#define CLK  2

HX711 scale;

void setup() {
  Serial.begin(9600);
  Serial.println("HX711 scale demo");

  scale.begin(DOUT, CLK);
  scale.set_scale(-9000.0); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");
}

void loop() {
  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();
}

First of all, posting snippets of code like this doesn’t help us to help you, as lots of the important bits are missing from this sketch.

Secondly, It’s not clear from what you’ve said if the complete sketch that goes with these snippets of code does actually print out the weight readings in the serial monitor. If it does then you at least have a starting point.

Thirdly, you can’t put stuff in your void loop when you’re working with Blynk…

so it will need to be moved into a function which is called with a timer. There is more information about this here…
http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

In an earlier post I said…

The code you are using doesn’t take that approach, it simply takes the reading and sends it directly to the serial monitor…

A better approach would be…

float weight_reading = scale.get_units(); // take a weight reading and store it in the weight_reading variable
Serial.print("Reading: ");
Serial.print(weight_reading , 1);
Serial.print(" lbs");
Blynk.virtualWrite(V1, weight_reading); // Send the weight reading to the widget on pin V1

However, DO NOT put this code in your void loop, as it will flood the Blynk server with data. Instead, put it in a function and call it with a timer as explained in the “keep your void loop clean” document.

Can you see now why I suggested using an existing HX711 sketch, rather than trying to re-invent the wheel - with limited wheel building skills?

Pete.