Hi everyone,
I’m looking to built a multi-sensor for home with ESP8266, DHT11 and blynk.
That’s my first project with Arduino-Blynk and I don’t find what is the fault in my prog.
I copy my prog here and wish someone can help me to find the problem.
//DHT11 And NodeMCU With Blynk
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
#define DHTPIN 0 // D3
#define DHTPIN 1 // D4
#define DHTPIN 2 // D5
#define DHTPIN 3 // D6
// 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 0 (D3, DHTTYPE);
DHT 1 (D4, DHTTYPE);
DHT 2 (D5, DHTTYPE);
DHT 3 (D6, DHTTYPE);
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 h1 = dht1.readHumidity();
float t1 = dht1.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h1) || isnan(t1)) {
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(V1, t1);
Blynk.virtualWrite(V2, h1);
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h2) || isnan(t2)) {
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(V3, t2);
Blynk.virtualWrite(V4, h2);
float h3 = dht3.readHumidity();
float t3 = dht3.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h3) || isnan(t3)) {
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, t3);
Blynk.virtualWrite(V6, h3);
float h4 = dht4.readHumidity();
float t4 = dht4.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h4) || isnan(t4)) {
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(V7, t4);
Blynk.virtualWrite(V8, h4);
float h = dht4.readHumidity();
float t = dht4.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(V1, t1);
Blynk.virtualWrite(V2, h1);
Blynk.virtualWrite(V3, t2);
Blynk.virtualWrite(V4, h2);
Blynk.virtualWrite(V5, t3);
Blynk.virtualWrite(V6, h3);
Blynk.virtualWrite(V7, t4);
Blynk.virtualWrite(V8, h4);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, IPAddress(192,168,15,200), 8080);
dht1.begin();
dht2.begin();
dht3.begin();
dht4.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
Thank to help me, I’m sure I’m not so far to be good.
Pierre Paulus