Hi guys, I’m trying to develop a simple app with an ESP8266 that will send me humidity and temperature information with a DHT11.
That, I got it. But older I want to add a slider to enter a temperature range where a radiator is turned on or off (that is, a thermostat) to simulate the radiator and I put a led on the D2 output (GPIO 04), I am trying to get my slider to send information to my code and with an “if” the radiator is turned off or on according to the set temperature.
Then I put the code I have …
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
int SENSOR = 2;
int TEMPERATURA;
int RADIADOR = 4;
int HUMEDAD;
int TERMOSTATO;
BLYNK_WRITE(V7){
TERMOSTATO = param.asInt();
}
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXX";
char ssid[] = "XXXXXXXX";
char pass[] = "XXXXXXXX";
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
void setup()
{
pinMode(4, OUTPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(1000L, sendSensor);
}
void loop()
{
if (TEMPERATURA < TERMOSTATO) {
digitalWrite(RADIADOR, HIGH);
}
else digitalWrite(RADIADOR, LOW);
Blynk.run();
timer.run();
}
I can’t get it to work properly, when I move the slider it lights up once and then it never works again
@Zyklon-B please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Pete.
Ready! sorry I didn’t know how to do it
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
int SENSOR = 2;
int TEMPERATURA;
int RADIADOR = 4;
int TERMOSTATO;
BLYNK_WRITE(V7){
TERMOSTATO = param.asInt();
}
char auth[] = "_EQlv1IQtCqUBNIZptTSKdZxLy0Qwb-4";
char ssid[] = "Sanjose";
char pass[] = "Pirillueiro37";
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
TEMPERATURA = t;
}
void setup(){
pinMode(4, OUTPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(1000L, sendSensor);
}
void loop()
{
if (TEMPERATURA < TERMOSTATO) {
digitalWrite(RADIADOR, HIGH);
}
else digitalWrite(RADIADOR, LOW);
Blynk.run();
timer.run();
}
One last thing, now to finish, how can I put a manual on / off button and that it commands (or has priority) over the slider … ??
What’s the difference between the two sets of code you posted?
You should start by reading this…
Your temperature comparison logic should be in the sendSensor
function, which makes your TEMPERATURA
variable redundant
The DHT11 doesn’t like being read every second, so increase the timer interval.
Pete.
distans
January 30, 2021, 10:57pm
6
Nothing to do with your slider problem, but with DHT sensors you’ll probably be better of with a timer set to >5 seconds.