Projects with DHT22

Good morning everyone, I’m studying Blynk and I still know little, I’m loving this apicativo.
My question is regarding the DHT22 sensor, I did not find any examples, can you help me? Another question is regarding more than one example, how to put several in one project?


Have you looked here

Thanks, it’s for DHT11, would it be the same example, does it work for DHT22?

No. Have a look into code :

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

Thanks for the help, I’ll do the tests.

Please, where is the error?

Arduino: 1.8.1 (Windows 10), Placa:“Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)”

C:\Users\Rock\AppData\Local\Temp\arduino_modified_sketch_299176\Arduino_Ethernet.ino:40:17: fatal error: DHT.h: No such file or directory

#include <DHT.h>


compilation terminated.

exit status 1
Erro compilando para a placa Arduino/Genuino Mega or Mega 2560

Este relatório teria mais informações com
“Mostrar a saida detalhada durante a compilação”
opção pode ser ativada em “Arquivo -> Preferências”

@Rock please check comments in sketch.

This example shows how value can be pushed from Arduino to
the Blynk App.

For this example you’ll need SimpleTimer library:
and Adafruit DHT sensor libraries:

I am building a larger sketch that uses 2 DHT22s with Arduino and Blynk, so I’ll do my best to filter it down to just that below.

#include <SPI.h>                    // Used by Blynk
#include <Ethernet.h>               // Used by Blynk
#include <BlynkSimpleEthernet.h>    // Used by Blynk
#include "DHT.h"                    // DHT Sensor
#include <SimpleTimer.h>            // used to run functions at preset intervals

#define BLYNK_PRINT Serial
char auth[] = "PasteAuthBetweenQuotes";

DHT dhtA(A0, DHT22);     // DHT instance named dhtA, Analog0 and sensor type
DHT dhtB(A2, DHT22);     // DHT instance named dhtB, Analog2 and sensor type

SimpleTimer timer;       // SimpleTimer instance named timer

void setup()
  //Serial2.begin() // For other baud rates
  //Serial3.begin() // For other baud rates
    pinMode(A0, INPUT_PULLUP);    // DHT22 use internal 20k pullup resistors
    pinMode(A2, INPUT_PULLUP);

    while (Blynk.connect() == false) {}

    timer.setInterval(4700L, climateRoutine); // 4.7 second intervals between climate routines

  void loop()

  void climateRoutine()
    byte h1 = dhtA.readHumidity();          // f1 and h1 are fahrenheit and humidity readings
    byte f1 = dhtA.readTemperature(true);   // from DHT/A
    byte h2 = dhtB.readHumidity();          // f2 and h2 are fahrenheit and humidity readings
    byte f2 = dhtB.readTemperature(true);   // from DHT/B

    Blynk.virtualWrite(V0, f1);      //  Set Virtual Pin 0 frequency to PUSH in Blynk app
    Blynk.virtualWrite(V1, h1);      //  Set Virtual Pin 1 frequency to PUSH in Blynk app
    Blynk.virtualWrite(V3, f2);      //  Set Virtual Pin 2 frequency to PUSH in Blynk app
    Blynk.virtualWrite(V4, h2);      //  Set Virtual Pin 3 frequency to PUSH in Blynk app

Edit - I use 4 ValueDisplay Widgets. Each per virtualWrite command.

Since when did DHT chips output to analog?

To my knowledge, they can output to both Digital and Analog (on Arduino). I’ve used them both ways, but it’s more convenient for my larger project to put them on the analog pins.

1 Like

I don’t think it matters to the library. As it is a 1-wire bus, either Digital or Analog pins (once set to INPUT_PULLUP) will receive it the same way.

1 Like

One wire bus? You sure you mean the dht22?

Or am I thinking Ds18b?

Well, a modified form of it.

(2) Communication and signal
1-wire bus is used for communication between MCU and AM2302. ( Our 1-wire bus is specially designed, it’s
different from Maxim/Dallas 1-wire bus, so it’s incompatible with Dallas 1-wire bus.)

Either way, the reason it works is because the Analog pins are set to emulate digital pins when set to INPUT_PULLUP. So a 1-wire bus, or a simple button, will work the same as on a Digital pin pulled HIGH.


Cool, that’s very useful!

With the help of the forum,

was able to make DHT22 work on my project, thanks to all of you for the help.
This Blynk is really good …
I’m noticing that the sensor is informing me about 2 degrees higher, as you can see in the picture, it’s dialing 24 degrees and it’s actually 22 degrees.

How to make this adjustment?

Silly question, but are you sure it is a DHT22 and not a DHT11? Reason asked is that the DHT11 has a ±2 degree error range.

And while not a guarantee, is it a blue or white covering on the sensor?

The sensor is white, I imagine it’s really DH22.

OK, sounds like it, just making sure :wink:

As for adjustments… I guess that is easily done in code, just subtract 2 from the value. However take into consideration that the sensor may be in close enough proximity to the MCU or something else to pick up that extra two degrees that is not realised by a typical room thermometer.

I am using a thermistor and a calibrated algorithm, but it is still displaying 26.421 C as opposed to my room thermometers 24.8 C sitting only a meter higher.

You’re right, I imagine it could be the difference of location, I put the sensor in a recording studio where it has an acoustic coating with foam “sonex” and heats mutio. Thank you.