/**************************************************************
-
Home IoT - Based on Arduino/Blynk framework
-
Arduino Yun 192.168.1.250
-
Virtual Pin assignments:
-
V0 - Target temperature
-
V1/V11 - Temperature/Humidity Main Sensor (DHT22)
-
V2/V12 - Temperature/Humidity Kitchen (DHT22)
-
V3/V13 - Temperature/Humidity Master Bedroom (DHT22)
-
V4/V14 - Temperature/Humidity Top Floor (DHT22)
-
V5/V15 - Temperature/Humidity Outside (DHT22)
-
V6 - Temperature Hot Water
-
V7 - Temperature Radiator Water
-
V20 - Timer Morning
-
V21 - Timer Afternoon
-
V22 - Relay Water/Burner
-
V23 - Relay Radiator Pump
-
V24 - Led Radiator
-
V25 - Led Water
-
V30 - LCD Display Widget
-
V31 - Terminal
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <Bridge.h>
#include <BlynkSimpleYun.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <Console.h>
// Initialize the DHT
#include <DHT.h>
#define DHTTYPE DHT22
#define DHTPIN 7
DHT dht(DHTPIN, DHTTYPE, 30);
float humidity, temp_f; // Values read from sensor
// Other global variables
float targetTemp = 21;
float Hysteresis = 0.5;
int TimerMorningOn = false;
int TimerAfternoonOn = false;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth = " ";
SimpleTimer timer;
WidgetLCD lcd(V30);
WidgetLED ledRadiator(V24);
WidgetLED ledWater(V25);
// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
if (isFirstConnect) {
Console.println(“*** Sync All ? ***”);
Blynk.syncAll();
isFirstConnect = false;
}
Blynk.virtualWrite(V0, targetTemp);
Blynk.virtualWrite(V26, false); // Shower Button off
}
BLYNK_WRITE(V0) //Slider Widget V0 - Target Temperature
{
targetTemp = param.asInt();
Console.print("V0 Target Temp → ");
Console.println(targetTemp);
}
BLYNK_WRITE(V20) //Timer Widget V20 - Timer Morning
{
TimerMorningOn = param.asInt();
Console.print("V20 Timer Morning → ");
Console.println(TimerMorningOn);
}
BLYNK_WRITE(V21) //Timer Widget V21 - Timer Afternoon
{
TimerAfternoonOn = param.asInt();
Console.print("V20 Timer Afternoon → ");
Console.println(TimerAfternoonOn);
}
void HomeWork()
{
temp_f = dht.readTemperature(false)- 1.8;// Read temperature as Celsius
humidity = dht.readHumidity();
Blynk.virtualWrite(V1, temp_f);
Blynk.virtualWrite(V11, humidity);
Console.println();
Console.print(“Uptime:”);
Console.print(millis()/1000);
Console.println(" --------------------");
Console.print("Temp : ");
Console.println(temp_f);
Console.print("Target T : ");
Console.println(targetTemp);
Console.print("Timer Mon : ");
Console.println(TimerMorningOn);
Console.print("Timer Aft : ");
Console.println(TimerAfternoonOn);
if (temp_f < targetTemp && (TimerMorningOn == 1 || TimerAfternoonOn == 1))
{
ledRadiator.on();
digitalWrite(8, LOW);
}
else
{
ledRadiator.off();
digitalWrite(8, HIGH);
};
}
void setup()
{
Serial.begin(115200);
Bridge.begin();
Console.begin();
Blynk.begin(auth);
lcd.clear();
lcd.print(0,0, “Starting Sensors”);
dht.begin();
delay(10000); // Allow board to settle
// Setup a function to be called every timer event
timer.setInterval(5000L, HomeWork);
pinMode(8, OUTPUT); // Relay Radiator
digitalWrite(8, HIGH); // Set off
ledRadiator.off();
pinMode(9, OUTPUT); // Relay Water
digitalWrite(9, HIGH); // Set off
ledWater.off();
Blynk.syncVirtual(V20);
Blynk.syncVirtual(V21);
}
void loop()
{
Blynk.run();
timer.run();
}