DHT11 and DHT22

Anybody made a project using any of these two sensors?

1 Like

Hi, have a look here DHT11 with Uno and Blynk app

What about esp8266. How would i go about making it work with that?

I know it is double, but sorry didn’t find any step-by-step tutorial.
You will have to google and investigate.
Tell us how it goes!

1 Like

@TMS
You may try code below:

DHT dht(DHTPIN, DHTTYPE, 30); 
float humidity, temp_f;  // Values read from sensor

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

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "xxxxxxxx", "xxxxxxxxx");
  dht.begin();           // initialize temperature sensor
}

BLYNK_READ(1) 
{ 
temp_f = dht.readTemperature(false);// Read temperature as Celsius
int value=temp_f*10;
String str;
char result[5];
result[0]=(value/100)+'0';
result[1]=((value/10)%10)+'0';
result[2]='.';
result[3]=(value%10)+'0';
result[4]='\0';
str +=result;
str +="℃";
//char buf[str.length()+1];
char buf[8];
str.toCharArray(buf,sizeof(buf));
Blynk.virtualWrite(1,buf); 
}
BLYNK_READ(2) 
{ 
humidity = dht.readHumidity();           // Read humidity (percent)
int value=humidity*10;
String str;
char result[5];
result[0]=(value/100)+'0'; 
2
result[1]=((value/10)%10)+'0';
result[2]='.';
result[3]=(value%10)+'0';
result[4]='\0';
str +=result;
str +="%";
//char buf[str.length()+1];
char buf[8];
str.toCharArray(buf,sizeof(buf));
Blynk.virtualWrite(2,buf); 
}

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

5 Likes

THX!!! Just replace dht22 with dht11 if i want dht11?

Wow, it looks nice. Could you post it to the “Projects made with Blynk” category?
BTW, now Blynk supports sending String objects, so you may skip using toCharArray… Enjoy!

Hi,

which DHT library did you use?

I want to try this as well on ESP8266

Thanks
Nico

Here is one I did this weekend, using a Arduino Nano V3, ESP8266 as a Shield and a DHT22 connected to Pin 2:

#include <ESP8266.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#include <SimpleTimer.h>

#define DHTPIN 2
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);

// Set ESP8266 Serial object
#define EspSerial Serial

ESP8266 wifi(EspSerial);

SimpleTimer timer;

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

void setup()
{
 //No Serial console as the Nano only has 1 HW Serial
  EspSerial.begin(115200);  // Set ESP8266 baud rate
  delay(10);

  Blynk.begin(auth, wifi, "YourSSID", "Your Wifi PWD");

  timer.setInterval(1000, sendData);
}

void sendData()
{
//Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();

//Write values to V04 and V05
  Blynk.virtualWrite(4, h);
  Blynk.virtualWrite(5, t);
}

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

Which Library did you use? Could you link it or upload it please?

I used the one from here: https://github.com/adafruit/DHT-sensor-library

1 Like

I got Blynk to work on my ESP and DHT11,



Nice and easy!
I am getting errors trying to compile the code to use the ESP as a shield though.

@sel303, For the shield configuration, please read instructions in the sketch carefully. you need a modified ITEAD library.

1 Like

Doh! I figured it out. I was trying to compile it for the ESP. Changed the board to UNO and it compiles fine. Thanks!

Thx to yptsai7 your code works perfectly. Close to 10 days testing now. Is there a way to implement sleep with this code?

Would love it if my esp could run on battery for a month.

I use Notification widget on Android too, but never get a notify. Do you succeed in that? BTW, I use Blynk library with ESP8266 on my Nexus 4.

Did you activated dashboard? Please show your code that sends notifications. Notifications are working. So most probably problem somewhere in your code.

For deep sleep low power - you need to tie pins 13 and 16 (XPD and RST) - then just add in Arduino ide:
ESP.deepSleep(60000000, WAKE_RF_DEFAULT); // Sleep for 60 seconds

the -03 is fairly easy - there are pads to solder together to tie the reset to XPD, -01 is harder.

I’m using one (esp8266-03) with the adafruit dht library and put it to sleep for 10 minutes, then it wakes up, connects, gets a reading and publishes to thingspeak. I’m just starting with Blynk and enjoying this thread :wink:

I did and it worked on my nexus 5. It would notify when the esp was disconnected.

Well the thing is that blynk app does not show anything when esp is offline. There would have to be some buffer or something on the server.