First of all, I would like to apologize if this question is frequent on the forum, but I searched around here and couldn’t find a solution to my problem. In addition, I am new to blynk and arduino codes.
Second, I am trying to connect two relays and have them switch off automatically after 40 minutes. When I use the code below, without time codes, it works.
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "XXXXXX";
char ssid[] = "XXXXXX";
char pass[] = "XXXXXXX";
#define EspSerial Serial3
#define ESP8266_BAUD 115200
#define PUMP 23
#define VALVE 24
ESP8266 wifi(&EspSerial);
BLYNK_WRITE(V0) {
if (param.asInt()==1) {
//PUMP AND VALVE TURN ON
TEST_ON();
}else{
//PUMP AND VALVE TURN OFF
TEST_OFF();
}
}
void setup()
{
Serial.begin(115200);
Serial3.begin(115200);
pinMode(13,OUTPUT);
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
pinMode (PUMP, OUTPUT);
pinMode (VALVE, OUTPUT);
}
BLYNK_CONNECTED()
{
Blynk.syncAll();
Blynk.syncVirtual(V0);
}
void loop()
{
Blynk.run();
if ( Serial3.available() ) { Serial.write( Serial3.read() ); }
if ( Serial.available() ) { Serial3.write( Serial.read() ); }
}
void TEST_ON() {
digitalWrite(VALVE, HIGH);
digitalWrite(PUMP, HIGH);
}
void TEST_OFF() {
digitalWrite(VALVE, LOW);
digitalWrite(PUMP, LOW);
}
When I add the “timer” codes, the relays turn on themselves. I turn off, they turn on again and do not turn off at the indicated time.
The “Timer” and “Eventor” widgets are not suitable for this project because there is no exact time to activate these relays. Can someone help me?
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "xxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxx";
#define EspSerial Serial3
#define ESP8266_BAUD 115200
#define PUMP 23
#define VALVE 24
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
BLYNK_WRITE(V0) {
if (param.asInt()==1) {
//PUMP AND VALVE TURN ON
TEST_ON();
timer.setTimeout(5000, TEST_OFF);
}else{
//PUMP AND VALVE TURN OFF
TEST_OFF();
}
}
void setup()
{
Serial.begin(115200);
Serial3.begin(115200);
pinMode(13,OUTPUT);
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
pinMode (PUMP, OUTPUT);
pinMode (VALVE, OUTPUT);
timer.setTimeout(5000, TEST_OFF);
}
BLYNK_CONNECTED()
{
Blynk.syncAll();
Blynk.syncVirtual(V0);
}
void loop()
{
Blynk.run();
if ( Serial3.available() ) { Serial.write( Serial3.read() ); }
if ( Serial.available() ) { Serial3.write( Serial.read() ); }
timer.run();
}
void TEST_ON() {
digitalWrite(VALVE, HIGH);
digitalWrite(PUMP, HIGH);
}
void TEST_OFF() {
digitalWrite(VALVE, LOW);
digitalWrite(PUMP, LOW);
}