BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Need help With My Blynk installation and code


#7

Thanks. My blynk says that my aplikation wasnt online yet!


#8

Solved . Thanks very much.


#9

And the solution was?


#10

image


#11

Hi i am new in this, so I must ask for help.
I have DHT12 sensor on ESP Wroom32, and it is work fine, but when I try to conect with Blynk doesnt work. I do not understand why!
I can not make Blynk project to control and show temp. and humidity.

Thanks

Here is the code:

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Blynk.h>
#include <WiFi.h>
const char* ssid = "xxx";
const char* password =  "xxx";
char auth[] = "xxxxx";


#include "Arduino.h"
#include <DHT12.h>

// Set dht12 i2c comunication on default Wire pin
  DHT12 dht12;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.println("Connecting to WiFi..");
}
 Serial.println("Connected to the WiFi network");
 Serial.println(WiFi.localIP());
 Blynk.begin("a390a92761eb4e5c941e8b1741d071b3", ssid, password);
 dht12.begin();
}


int timeSinceLastRead = 0;
void loop() {
   Blynk.run();
  // put your main code here, to run repeatedly:
  if(timeSinceLastRead > 2000) {
// Reading temperature or humidity takes about 250 milliseconds!
// Read temperature as Celsius (the default)
float t12 = dht12.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f12 = dht12.readTemperature(true);
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h12 = dht12.readHumidity();
 
bool dht12Read = true;
// Check if any reads failed and exit early (to try again).
if (isnan(h12) || isnan(t12) || isnan(f12)) {
Serial.println("Failed to read from DHT12 sensor!");
 
dht12Read = false;
}
 
if (dht12Read){
// Compute heat index in Fahrenheit (the default)
float hif12 = dht12.computeHeatIndex(f12, h12);
// Compute heat index in Celsius (isFahreheit = false)
float hic12 = dht12.computeHeatIndex(t12, h12, false);
// Compute dew point in Fahrenheit (the default)
float dpf12 = dht12.dewPoint(f12, h12);
// Compute dew point in Celsius (isFahreheit = false)
float dpc12 = dht12.dewPoint(t12, h12, false);
 
Serial.print("DHT12=> Humidity: ");
Serial.print(h12);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t12);
Serial.print(" *C ");
Serial.print(f12);
Serial.print(" *F\t");
Serial.print(" Heat index: ");
Serial.print(hic12);
Serial.print(" *C ");
Serial.print(hif12);
Serial.print(" *F");
Serial.print(" Dew point: ");
Serial.print(dpc12);
Serial.print(" *C ");
Serial.print(dpf12);
Serial.println(" *F");
}
timeSinceLastRead = 0;
}
delay(100);
timeSinceLastRead += 100;
 
}

#12

And of course your post for me.


#13

Thanks very much.


#14

Well, it looks like the final solution isn’t complete yet… no need for a separate topic, so I moved your post back here.

Also, I fixed your formatting of the code you posted here, as per the directions…

Blynk - FTFC


#15

As for your issue of getting your code to work… it is not well written for Blynk. You have too much in the void loop()

Read through the Help Center for more information…


#16

You are the best . Thanks very much again.:grinning:


#17

I ll try .


#18

@Sosa The DHT12 is downward compatible with the DHT11, this worked for me on my DHT11 so give it a try …

/**************************************************************
   Blynk is a platform with iOS and Android apps to control
   Arduino, Raspberry Pi and the likes over the Internet.
   You can easily build graphic interfaces for all your
   projects by simply dragging and dropping widgets.

     Downloads, docs, tutorials: http://www.blynk.cc
     Blynk community:            http://community.blynk.cc
     Social networks:            http://www.fb.com/blynkapp
                                 http://twitter.com/blynk_app

   Blynk library is licensed under MIT license
   This example code is in public domain.

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

   WARNING :
   For this example you'll need SimpleTimer library:
     https://github.com/jfturcot/SimpleTimer
   and Adafruit DHT sensor library:
     https://github.com/adafruit/DHT-sensor-library

   App project setup:
     Value Display widget attached to V5
     Value Display widget attached to V6

 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>
#include <DHT.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxxxxxx";

#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);
SimpleTimer 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()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth, ssid, pass);

  dht.begin();

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

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}

#19

I cant doasent work. how can I conect the DHT12 with ESP32 like DHT 11?


#20

Only this code work without Blynk!

#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <DHT12.h>
#include <Blynk.h>
#include "Arduino.h"
#define DHTYPE DHT12

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] ="";
char pass[] = "";

DHT12 dht12;        // 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


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 h12 = dht12.readHumidity();
  float t12 = dht12.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h12) || isnan(t12)) {
    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, h12);
  Blynk.virtualWrite(V6, t12);
}

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

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

  dht12.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}
int timeSinceLastRead = 0;
void loop()
{
  Blynk.run();
  timer.run();
  float t12 = dht12.readTemperature();
  float h12 = dht12.readHumidity();
  bool dht12Read = true;
Serial.print("DHT12=> Humidity: ");
Serial.print(h12);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t12);
Serial.print(" *C ");
Serial.print("/n");
timeSinceLastRead = 0;
delay(1000);
timeSinceLastRead += 100;

}

#21

Aaand I solved! It is work fine now.
Thanks a lot of all.


#22

You should have only Blynk.run and timer.run in void loop. Also, you should not use delays with Blynk, especially not that long. @Shadeyman gave you proper code for DHT use with Blynk, just use it, don’t ‘solve’ anything. Read the docs section, as this is a perfect example of bad coding.


#23

@Sosa And a perfect example of not reading instructions… I had to fix your posted code again :face_with_raised_eyebrow:


#24

I am so sorry about that.


#25

This code is used from another guy. And work fine. Thnaks again.


#26

It’s working because anti-flood security included in latest libraries. That does not mean it’s working fine, or that your code is right for Blynk usage, you’re still violating all the rules. Once again, nothing should be included in void loop except blynk.run and timers, read the docs. And I really can’t understand why you are still insisting on using obviously wrong code when @Shadeyman posted proper one for you. I suppose it’s easier to use bad code instead of c/p right one.