Problem about DHT11+NodeMCU+Blynk

My Project for Teacher is to show the Temp and Humidity via NodeMCU+DHT11+Blynk
but I try every code in the two topic below, it’s does work because the code is error

can you help me by the code or the process of it
please, my project is in due time now please help me

The example you posted where for the arduino uno using the ESP as a shield only. I assume you want the ESP as a standalone.

I’m using ESP8266 standalone with an DHT11. You need to adapt the following parts:

  1. DHTPIN - the pin, where the data-port of your DHT is connected
  2. auth-key
  3. wifi settings

Blynk should receive data on the virtual ports 4 and 5.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "DHT.h"
#define DHTPIN 4 // The pin you connect to
#define DHTTYPE DHT11   // DHT 11 Change this if you have a DHT22
DHT dht(DHTPIN, DHTTYPE,16); // Change this to 

SimpleTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Your Auth";
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "XXXX", "XXXX");
  timer.setInterval(2000, sendDHT);
}

void sendDHT()
{
//Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  int hum = (int) h;
  int tem = (int) t;
//Write values to V04 and V05
  Blynk.virtualWrite(4, hum);
  Blynk.virtualWrite(5, tem);
}
void loop()
{
  Blynk.run();
  timer.run();
}
2 Likes

hey Mr.Minc , thank for your help again
but the problem is on the blynk it’s show the result " 2.147 " both v4 and v5 virtual
I don’t know why is it
the code that I use is

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "DHT.h"
#define DHTPIN 2 // The pin you connect to
#define DHTTYPE DHT11   // DHT 11 Change this if you have a DHT22
DHT dht(DHTPIN, DHTTYPE,16); // Change this to 

SimpleTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "279950f911cb4fb1b957a272a9a17124";
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "myID", "myPaSSword");
  timer.setInterval(2000, sendDHT);
}

void sendDHT()
{
//Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  int hum = (int) h;
  int tem = (int) t;
//Write values to V04 and V05
  Blynk.virtualWrite(4, hum);
  Blynk.virtualWrite(5, tem);
}
void loop()
{
  Blynk.run();
  timer.run();
}

did I miss something or
can you tell me the process

thank a lot again man

Format the code so that it’s easier to read. Use the </> button

I’ve just uploaded the code once more and it does work. However I can replicate your error when connecting the sensor data pin to the wrong GPIO. In your code you stated that you use GPIO 2. Make sure, that the data-pin is really in GPIO 2.

I get 21474 as values for both virtual pins when declaring to use pin 2 but connect to pin 4 or 5.

HTH…

Cheers

:slight_smile: