DHT11 with Uno and Blynk app

Hello there, I am using USB example to control my Arduino with my iPhone, I was successfully able to control two LEDs, But I want to use the DHT11 alongside them, can you help me by providing code or libraries needed?
Thank you :slight_smile:

Hello

I’m using this lib https://github.com/adafruit/DHT-sensor-library maybe it will be useful for you as well

First of all you’ll need to get sensor data from DHT11 with Arduino. There are lot’s of tutorials on the web - please do your research.

When you can get them - showing them in Blynk is super easy: check the example sketch called PushData. Virtual pins were designed specifically for such cases.

Thanks a lot, I have written a code and I am measuring humidity and temperature by my DHT22 (not DHT11), but I have a problem with BlynkServer which I use to control my arduino thorugh my pc’s connection with, I keep losing connection, is it a server error or it’s my pc which is causing this?
Last thing; I have those following lines in the code which I didn’t clearly get what they mean:

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11);
#define BLYNK_PRINT SwSerial

What is the SwSerial or SoftwareSerial and what is it used for?
Thank you :slight_smile:

my current code is:

#include <BlynkSimpleSerial.h>
#include <dht22.h>
dht22 DHT22;

char auth[] = "xxxxxxxxxxxxxxxxxxxxxx";

void setup()
{
  DHT22.attach(2);
  Blynk.begin(auth);
}

void loop()
{
    Blynk.run();
    int chk = DHT22.read();
    Blynk.virtualWrite(1, DHT22.temperature); 
    Blynk.virtualWrite(2, DHT22.humidity); 
    delay(1000);
}

All the "PRINT" functions are for debugging, you can skip them

Your code will cause lot’s of messages to server, which is bad. Please follow all the steps in the PushData Example and use Timer Library to limit the amount of messages by sending them periodically. Also, avoid using delay with Blynk since it may cause connection drops.

There is a thread on this forum about the same question.

@Pavel
Thank you, But can you please tell me what to use instead of Delay? How can I use your timer library?

I rewrote the code with the SimpleTimer lib used, can you confirm whether I did it right or wrong?

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
#include <dht22.h>
dht22 DHT22;
SimpleTimer timer;

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

void setup()
{
  DHT22.attach(2);
  Blynk.begin(auth);
  timer.setInterval(1000, sendUptime);
}

void sendUptime()
{
  Blynk.virtualWrite(1, DHT22.temperature);
  Blynk.virtualWrite(2, DHT22.humidity);
}

void loop()
{
  Blynk.run();
  timer.run();
  int chk = DHT22.read();
}
1 Like

@zaid_riadh

Seems ok. Should work I think.

1 Like

I’m trying tom make my DHT11 show the values in percentage (e.g. Humidity 60% instead of huminity 60) but I don´t know what I have to add in my code…

I’m using this code

Blynk.run();
int chk = DHT.read11(dht_dpin);
Blynk.virtualWrite(1, DHT.temperature); 
Blynk.virtualWrite(2, DHT.humidity); 
delay(1000);

@jesio94 I already answered you in one of your posts. Please do not spam same questions over many topics.