#define BLYNK_PRINT Serial
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
#define BLYNK_TEMPLATE_ID "TMPLAoKiD7RF"
#define BLYNK_DEVICE_NAME "Home"
#define BLYNK_AUTH_TOKEN "**************************"
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_Sensor.h>
#include <WidgetRTC.h>
#include <TimeLib.h>
#include <NTPClient.h>
#include <EthernetUdp.h>
#include <EmonLib.h>
//definizione variabili sensore temp e volt watt
#define W5100_CS 10
#define SDCARD_CS 4
#define DHT1PIN 2 //pin sensore giorno dht22
#define DHT2PIN 3 //pin sensore esterno dht22
#define DHT3PIN 5 // pin sensore notte dht22
#define DHT1TYPE DHT22
#define DHT2TYPE DHT22
#define DHT3TYPE DHT22
//definizione temperatura variabili
DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);
DHT dht3(DHT3PIN, DHT3TYPE);
float hum1, temp1;
float hum2, temp2;
float hum3, temp3;
BlynkTimer timer;
char auth[] = "****************************";
//sync time ntp
EthernetUDP Udp;
NTPClient timeClient(Udp, "europe.pool.ntp.org", 3600, 60000);
IPAddress server_ip (139, 59, 206, 133); //cloud blynk
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip ( 192, 168, 178, 58);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip ( 192, 168, 178, 1);
IPAddress subnet_mask(255, 255, 255, 000);
EthernetServer server = EthernetServer(80);
void sendSensor()
{
float hum1 = dht1.readHumidity();
float temp1 = dht1.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(hum1) || isnan(temp1)) {
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, hum1);
Blynk.virtualWrite(V2, temp1);
Serial.print("Temperatura : ");
Serial.print(temp1);
Serial.print(" Umidità : ");
Serial.println(hum1);
}
void sendSensor1()
{
float hum2 = dht2.readHumidity();
float temp2 = dht2.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(hum2) || isnan(temp2)) {
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, hum2);
Blynk.virtualWrite(V4, temp2);
Serial.print("Temperatura : ");
Serial.print(temp2);
Serial.print(" Umidità : ");
Serial.println(hum2);
}
void sendSensor2()
{
float hum3 = dht3.readHumidity();
float temp3 = dht3.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(hum3) || isnan(temp3)) {
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, hum3);
Blynk.virtualWrite(V6, temp3);
Serial.print("Temperatura : ");
Serial.print(temp3);
Serial.print(" Umidità : ");
Serial.println(hum3);
}
WidgetRTC rtc;
WidgetLCD lcd(V52); //lcd supporto blynk app
// Digital clock display
void clockDisplay()
{
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + " " + month() + " " + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
// Send time to the App
Blynk.virtualWrite(V50, currentTime );
// Send date to the App
Blynk.virtualWrite(V51, currentDate );
}
//definizione pulsanti virtuali per ifttt
BLYNK_WRITE(V10) //soggiorno Tetto
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(22, LOW); // Set GPIO 22 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(22, HIGH); // Set Pin 22 HIGH
Blynk.virtualWrite(V10, LOW);// Set Virtual Pin 10 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V11) //soggiorno applique
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(34, LOW); // Set GPIO 34 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(34, HIGH); // Set Pin 34 HIGH
Blynk.virtualWrite(V11, LOW);// Set Virtual Pin 11 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V12) //cucina soffusa
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(24, LOW); // Set GPIO 24 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(24, HIGH); // Set Pin 24 HIGH
Blynk.virtualWrite(V12, LOW);// Set Virtual Pin 12 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V13) //Cucina tetto
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(25, LOW); // Set GPIO 25 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(25, HIGH); // Set Pin 25 HIGH
Blynk.virtualWrite(V13, LOW);// Set Virtual Pin 13 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V14) //Bagno piccolo
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(26, LOW); // Set GPIO 26 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(26, HIGH); // Set Pin 26 HIGH
Blynk.virtualWrite(V14, LOW);// Set Virtual Pin 14 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V15) //Corridoio
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(27, LOW); // Set GPIO 27 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(27, HIGH); // Set Pin 27 HIGH
Blynk.virtualWrite(V15, LOW);// Set Virtual Pin 15 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V16) // Stanza 2
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(28, LOW); // Set GPIO 28 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(28, HIGH); // Set Pin 28 HIGH
Blynk.virtualWrite(V16, LOW);// Set Virtual Pin 16 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V17) //Bagno Grande
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(29, LOW); // Set GPIO 29 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(29, HIGH); // Set Pin 29 HIGH
Blynk.virtualWrite(V17, LOW);// Set Virtual Pin 17 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V18) //Stanza 1
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(30, LOW); // Set GPIO 30 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(30, HIGH); // Set Pin 30 HIGH
Blynk.virtualWrite(V18, LOW);// Set Virtual Pin 18 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V19) // Letto Soffusa
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(31, LOW); // Set GPIO 31 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(31, HIGH); // Set Pin 31 HIGH
Blynk.virtualWrite(V19, LOW);// Set Virtual Pin 19 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V20) //Letto Tetto
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(32, LOW); // Set GPIO 32 LOW
timer.setTimeout(100L, []() { // Run after 0.5 seconds second
digitalWrite(32, HIGH); // Set Pin 32 HIGH
Blynk.virtualWrite(V20, LOW);// Set Virtual Pin 20 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V21) //music room
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(33, LOW); // Set GPIO 33 LOW
timer.setTimeout(3400L, []() { // Run after 2.4 seconds second
digitalWrite(33, HIGH); // Set Pin 33 HIGH
Blynk.virtualWrite(V21, LOW);// Set Virtual Pin 21 LOW
}); // END Timer Function
}
}
BLYNK_WRITE(V22) //interruttore camino
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(35, LOW); // Set GPIO 34 LOW
} else {
digitalWrite(35,HIGH);
Blynk.virtualWrite(V22, LOW);// Set Virtual Pin 22 LOW
}
}
BLYNK_CONNECTED() {
rtc.begin();
}
void setup()
{
// Debug console
Serial.begin(115200);
dht1.begin();
dht2.begin();
dht3.begin();
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH);
pinMode(22,OUTPUT); //Luce soggiorno LED
digitalWrite(22, HIGH);
pinMode(23,OUTPUT); //Luce soggiorno LED
digitalWrite(23,HIGH);
pinMode(24,OUTPUT); //Luce cucina soffusa
digitalWrite(24,HIGH);
pinMode(25,OUTPUT); //Luce cucina
digitalWrite(25,HIGH);
pinMode(26,OUTPUT); //Luce bagno zona giorno
digitalWrite(26,HIGH);
pinMode(27,OUTPUT); //Luce Corridoio
digitalWrite(27,HIGH);
pinMode(28,OUTPUT); //Luce Stanza 2
digitalWrite(28,HIGH);
pinMode(29,OUTPUT); //Luce Bagno Zona Notte
digitalWrite(29,HIGH);
pinMode(30,OUTPUT); //Luce Stanza 1
digitalWrite(30,HIGH);
pinMode(31,OUTPUT); //Luce camera letto soffusa
digitalWrite(31,HIGH);
pinMode(32,OUTPUT); //Luce camera letto normale
digitalWrite(32,HIGH);
pinMode(33,OUTPUT); //Music Room
digitalWrite(33,HIGH);
pinMode(34,OUTPUT); //Luce Soggiorno Tetto
digitalWrite(34,HIGH);
pinMode(35,OUTPUT); //luce camino
digitalWrite(35,HIGH);
pinMode(36,OUTPUT);
digitalWrite(36,HIGH);
pinMode(37,OUTPUT);
digitalWrite(37,HIGH);
pinMode(40,INPUT);
digitalWrite(40,LOW);
Blynk.begin(auth, "blynk.cloud", 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
timer.setInterval(3000L, sendSensor);
timer.setInterval(4000L, sendSensor1);
timer.setInterval(5000L, sendSensor2);
timer.setInterval(1000L, clockDisplay);
setSyncInterval(10*60);
}
void loop()
{
Blynk.run();
timer.run();
}
with one sensor all ok, as soon as I connect the other two, no value.
maybe the reading time is too short?