Hello Blynk Community I have used the Slider widget to adjust the setpoint at which the relay pin will turn on and i am trying to use the slider to adjust the setpoint of the maximum and minimum temperature.
Thank You in advance
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "DHT.h"
#define DHTPIN D1
#define relay D2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
char auth[] = "***";
char ssid[] = "***";
char pass[] = "***";
BlynkTimer timer;
float t;
float h;
float setpoint = 0;
bool relaystatuschanged = false;
const float maxTemp = 34.10;
const float minTemp = 33.8;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, Dht);
dht.begin();
pinMode(relay, OUTPUT);
}
BLYNK_WRITE(V2)
{
setpoint = param.asFloat();
relaystatuschanged = true;
}
void Dht() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if((setpoint < t) && (relaystatuschanged == true))
{
digitalWrite(relay, LOW); // assuming relay is active HIGH
relaystatuschanged = false;
}
if((setpoint > t) && (relaystatuschanged == true))
{
digitalWrite(relay, HIGH); // assuming relay is active HIGH
relaystatuschanged = false;
}
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C "));
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run();
timer.run();
}
void loop()