Hello, group, i want to blink for 1 or 2 sec ; once the led or digital pin when is changing the temperature.
But all the time is blinking mi led .
Can someone tell me how to stop blinks.
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#define BLYNK_PRINT Serial
#define DHTPIN 1
#define DHTTYPE DHT22
char auth[] = "gtgtrghrthrt";
char ssid[] = "Tggfdg";
char pass[] = "697gtrgrt";
// change as per your button attached.
const int relayPin = 14;
const int rel = 12;
int motorInitiated = 0;
int motorInitiated4 = 0;
int motorInitiated5 = 0;
int motorInitiated6 = 0;
int motorInitiated7 = 0;
int setTemp;
int t1;
SimpleTimer timer;
DHT dht(DHTPIN, DHTTYPE);
WidgetBridge bridge1(V1);
WidgetBridge bridge2(V2);
BLYNK_CONNECTED() {
Blynk.syncAll();
// Place the AuthToken of the second hardware here
bridge1.setAuthToken("ffferfer);
bridge2.setAuthToken("7rgergerg");
}
BLYNK_WRITE(V11) {
int pinData = param.asInt();
if (pinData == 1) {
motorInitiated = 0;
} else {
motorInitiated++;
motorInitiated6 = 0;
}
}
BLYNK_WRITE(V12) {
int pinData = param.asInt();
if (pinData == 1) {
motorInitiated4++;
digitalWrite(rel, HIGH);
} else {
motorInitiated4 = 0;
delay(6000);
digitalWrite(relayPin, LOW );
digitalWrite(rel, LOW);
}
}
BLYNK_WRITE(V3)
{
setTemp = param.asInt();
}
void sendSensor() {
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(V41, h);
Blynk.virtualWrite(V31, t);
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
if (t >= setTemp) {
motorInitiated6 = 0;
if (motorInitiated4 == 0) {
motorInitiated5 = 0;
}
delay(1500);
timer.restartTimer(t1);
timer.disable(t1);
}
else {
if (motorInitiated == 0) {
motorInitiated6++;
}
if (motorInitiated4 == 1) {
motorInitiated5++;
}
timer.enable(t1);
}
}
void sendSensor3() {
if (motorInitiated5 == 1) {
digitalWrite(relayPin, HIGH);
delay(1000);
digitalWrite(relayPin, LOW );
delay(500);
timer.restartTimer(t1);
timer.disable(t1);
}
}
void sendSensor4() {
if (motorInitiated6 == 0 && motorInitiated7 == 0)
{
bridge1.virtualWrite(V72, 0);
} else {
bridge1.virtualWrite(V72, 1);
}
}
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
pinMode(rel, OUTPUT);
digitalWrite(rel, HIGH);
dht.begin();
timer.setInterval(5000L, sendSensor);
t1 = timer.setInterval(2100L, sendSensor3);
timer.setInterval(3000L, sendSensor4);
}
void loop() {
Blynk.run();
timer.run();
}
I can see lot of delay in your sketch. This is a blocking function. It prevents other part of the sketch from running. Replace delay with timer.setInterval.
This will cause disconnections to the server. And other problems like you are facing now.
still is repeating ; i use the digital signal to connect in optocuplor to turn on or off the ac portable; because no have a thermostat .
the power button is digital if i pres 1 time then release is turning on again if i pres and release is turning off.
Thank you [Toro_Blanco] and [Madhukesh] the code is working perfectly when is v12 is on; just tell me if the timing on set interval sensor is ok or any small mistake on code appear just let me know please and THANK YOU.
Not so much a mistake, but just not the best way to do with BLYNK. I would get rid of the delay() in your code. This is a blocking function, and can cause connection issues with BLYNK.
You could use what is referred to as the lamda function. For example: