esp32-Blynk-Timeout- RELAY control

Hi, folks. I have been at this program for couple weeks, pulling of the net as much as i could, but I think its time to reach for help with writing this program. I am using ESP32.

What I am trying to achieve is…Using Blynk app I’d like to turn on the Relay and once it’s ON , I want the Timeout /countdown to kick off and when its out, than turn OFF the Relay.

I have managed to get all working but, When I turn on the Relay the countdown/Timeout is not always the same. To me it looks like it is random.

The whole project is to start immersion for pre set countdown(for example 15 min) and than go off until I use Blynk app to turn it on again.

For testing purpose I have countdown set for 5s.

Any help, or advice is much appreciated.

attaching the copy of my program

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

#define AUTH “…”
#define WIFI_SSID “…”
#define WIFI_PASS “…”
#define BLYNK_PRINT Serial
//#define POTM_PIN A12
#define RELAY_PIN_1 12
#define VPIN_BUTTON_1 V12

BlynkTimer timer;

int relay1State = LOW;
unsigned long check_wifi = 5000;
unsigned long countdown =5000;
unsigned long wd_timer_id=0;

BLYNK_CONNECTED(){
Blynk.syncVirtual(VPIN_BUTTON_1);
Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
}

void check(){
digitalWrite(RELAY_PIN_1, LOW);
Blynk.virtualWrite(VPIN_BUTTON_1,LOW);
timer.restartTimer(wd_timer_id);
}
void setup(){
Serial.begin(115200);
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS);
pinMode(RELAY_PIN_1, OUTPUT);
digitalWrite(RELAY_PIN_1, relay1State);
}
void loop(){
if ((WiFi.status() != WL_CONNECTED) && (millis() > check_wifi)) {
Serial.println(“Reconnecting to WiFi…”);
WiFi.disconnect();
WiFi.begin(WIFI_SSID,WIFI_PASS);
check_wifi = millis() + 1000;
}

if(RELAY_PIN_1,HIGH){
wd_timer_id= timer.setTimeout(countdown,check);
}
Blynk.run();
timer.run();
}

Welcome,

This line is wrong :

 if(RELAY_PIN_1,HIGH)

It should be :

if ( relay1State == HIGH )

And about this :

millis() > check_wifi
...
check_wifi = millis() + 1000;

It's preferable to do it like this:

millis() - check_wifi >= 1000UL
...
check_wifi = millis();

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.