#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxx";
#define DHTPIN 4 // What digital pin we're connected to
#define DHTTYPE DHT11 // DHT 22, AM2302, AM2321
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
// MW: Declare variable out here so they can be accessed in other sub-function, such as checkDelayTimer. I think if you declare them inside the sub-function it is only accessible there. So these would be called global variables.
float h = 0;
float t = 0;
int delayCountdown = 0; // Use this for countdown timing
void sendSensor()
{
h = dht.readHumidity();
t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
Serial.print(t);
Serial.print(h);
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, t);
Blynk.virtualWrite(V6, h);
if ( (t > 30) && (delayCountdown == 0) )
{
delayCountdown = 60;
digitalWrite(5, LOW);
Blynk.virtualWrite(V2, LOW);
}
if (delayCountdown == 1) // slutet av den aktiva fasen
{
digitalWrite(5, HIGH);
Blynk.virtualWrite(V2, HIGH);
delayCountdown = 0; // tillbaka till startläge
}
if (delayCountdown > 0)
{
delayCountdown--;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin(); // Start DHT22 communication
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
pinMode (5, OUTPUT);
}
BLYNK_WRITE(V2) {
int buttonState = param.asInt();
digitalWrite(13, buttonState); // Just do manual on and off here
}
void loop()
{
Blynk.run();
timer.run();
}
Comments