Blynk not displaying any reading?

Hi Guys I’m pretty new to this,
I recently brought a nodemcu esp2866 and a DHT 11 sensor, as I watched a youtube video hooking them up with blynk and they could get humidity and temp readings on their phone with blynk, I spent all night last night trying to install and find all the library’s I needed (pretty hard for me :slight_smile: ) and then today I went and put everything I need in the fields for the code and then uploaded it to my nodemcu. Blynk recognises and can see that it’s online but none of the information is getting displayed on the app I’ve given about 15 minutes but still nothing, I put the code that I ripped off a website :stuck_out_tongue: below, any help would be appricated

// Digital Output on LED 
// Hardware: NodeMCU Blynk Board


#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "DHT.h"           // including the library of DHT11 temperature and humidity sensor
#include <SimpleTimer.h>   //including the library of SimpleTimer
#define DHTTYPE DHT11      // DHT 11

#define dht_dpin 14
DHT dht(dht_dpin, DHTTYPE); 
SimpleTimer timer;
char auth[] = "634f82a7244e47b4b78e459edc2e24ce";            // You should get Auth Token in the Blynk App.
                                          // Go to the Project Settings (nut icon).

char ssid[] = "Zappia's WIFI (2.4GHz)";    // Your WiFi credentials.
char pass[] = "zaq12wsx";  // Set password to "" for open networks.
float t;                                   // Declare the variables 
float h;



void setup()
{
   Serial.begin(9600);// Debug console
   Blynk.begin(auth, ssid, pass);
   dht.begin();
   timer.setInterval(2000, sendUptime);
}

void sendUptime()
{
 
 float h = dht.readHumidity();
 float t = dht.readTemperature(); 
 Serial.println("Humidity and temperature\n\n");
 Serial.print("Current humidity = ");
 Serial.print(h);
 Serial.print("%  ");
 Serial.print("temperature = ");
 Serial.print(t); 
 Blynk.virtualWrite(V5, t);
 Blynk.virtualWrite(V6, h);
 
}

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



void loop()

Here are some screenshots from the blynk app

Thanks

~Tom

You have a 2nd void loop()? Since you are apparently online that may not be your issue, but get rid of it anyhow :slight_smile:

Get rid of this… it has been replaced with a built-into-the-library version called BlynkTimer

And change this to BlynkTimer timer;

Here is a link to the more current example…

Minus a bunch of Serial.print() commands, which you can add back in if you want.

Incidentally… are you getting the correct values printed out to your Serial Monitor?

And finally, for now… since these are already declared in pre-setup as global variables…

https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/

… you can remove the word float from the beginning of each of these.

Ok so I’ve used the example you linked below I’ll see if it works now

Still no go here is the code I’m using now

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "634f82a7244e47b4b78e459edc2e24ce";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Zappia's WIFI (2.4GHz)";
char pass[] = "zaq12wsx";

#define DHTPIN 2          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
 float h = dht.readHumidity();
 float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

 if (isnan(h) || isnan(t)) {
   Serial.println("Failed to read from DHT sensor!");
   return;
 }
 // You can send any value at any time.
 // Please don't send more that 10 values per second.
 Blynk.virtualWrite(V5, h);
 Blynk.virtualWrite(V6, t);
}

void setup()
{
 // Debug console
 Serial.begin(9600);

 Blynk.begin(auth, ssid, pass);
 // You can also specify server:
 //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
 //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

 dht.begin();

 // Setup a function to be called every second
 timer.setInterval(1000L, sendSensor);
}

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

OK, now what are you seeing on the Serial monitor? The message “Failed to read from DHT sensor!” or nothing?

Add in the regular serial print commands from your last code and see if they show the proper values or not.

You may wish to change the timer back to 2000L (2 seconds) or even 5000L (5 seconds) as the DHT11 is a notoriously slow sensor.

I’m sorry like I said I’m pretty new to all this, I don’t know where the serial monitor is.

And your last sketch was using pin 14, now this one is using pin 2… which actual pin is your sensor hooked up to?

BTW please use the Arduino (GPIO) pin numbering, NOT the Dx silkscreened on the board…

I;m using pins D4 for the middle connector on the dht11, pin G of the left connector and the 3V pin of the right connector

It’s in the Arduino IDE. Hit the button in the top right hand corner and a new window will open. Go to the bottom right hand corner of the Serial Monitor window and select the baud rate of 9600 as defined in your sketch.
Sorry, I’m on an iPhone at the moment or I’d upload some screenshots.

Pete.

Got ya covered :slight_smile:

image

image

1 Like

Yep I’m getting failed to read from DHT

Thanks!

Change to one of the dark green pins (from the chart above) and enter the GPIO pin number into your sketch

Sorry I’m a bit confused

I’m using cables 3 of them from my nodemcu to my dht 11 what cable to change?

I’ve also set the blynk app to use virtual pins 5 & 6

Well, Power (probably should be the 5v pin as that sensor may not work on 3.3v) and Ground will never change :stuck_out_tongue:

So that leaves the data / signal pin, which sends the signal to the NodeMCU.

But in the code you need to match the physical GPIO pin used with what you are actually connecting that signal wire to. And when we say GPIO we meen the “universal” numbering used, not the identifier silk screened on the board… as while that can work if properly understood, it makes the code harder to “transfer” to other types of boards you may start to use in the future. Now if they had properly labeled them as how the Arduinos did… oh well…