Hy please help me !
I need add in this code 3 reelays in sequence with a deelay in loop mode !
when 16 high — relay3 off relay1 on — delay — relay1 off relay2 on — delay — relay2 off reelay3 on — delay — loop when 16 low
Thanx
Hy please help me !
I need add in this code 3 reelays in sequence with a deelay in loop mode !
when 16 high — relay3 off relay1 on — delay — relay1 off relay2 on — delay — relay2 off reelay3 on — delay — loop when 16 low
Thanx
What have you tried so far?
Show us your code.
@gemforce Welcome to Blynk
Please try not to post random help requests into other topics. I moved your question into a topic of it’s own… Thank you.
Be aware, we are not going to simply write your code for you, and programming timer loops to control things like relays is not a Blynk specific task… As @Jamin has asked, please show us what you have so far, and if able and applicable, we will guide you.
When posting any code here, please follow the formatting guides:
Also try searching this forum for the words “relay” and “pulses” there might be something relevant.
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space // COSTAS
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Time.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";
char Date[16];
char Time[16];
const int zonePin1 = 12; //1.zóna pin
const int zonePin2 = 13; //2.zóna pin
const int zonePin3 = 14; //3.zóna pin
long startseconds; // start time in seconds
long stopseconds; // stop time in seconds
long nowseconds; // time now in seconds
int btnpin;
SimpleTimer timer;
WidgetRTC rtc;
//BLYNK_ATTACH_WIDGET(rtc, V0);
void setup() {
Serial.begin(115200); // COSTAS
Serial.println("\nStarted"); // COSTAS
pinMode(zonePin1, OUTPUT);
pinMode(zonePin2, OUTPUT);
pinMode(zonePin3, OUTPUT);
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false) { // COSTAS
// Wait until connected // COSTAS
} // COSTAS
Blynk.notify("Connected successfully");
Serial.println("Done");
rtc.begin();
timer.setInterval(60000L, activetoday); // check every minute if schedule should run today
timer.setInterval(30000L, reconnectBlynk); // check every 30s if still connected to server
}
void activetoday() { // check if schedule should run today
if (year() != 1970) {
Blynk.syncVirtual(V1); // sync timeinput widget
sprintf(Date, "%02d/%02d/%04d", day(), month(), year()); // COSTAS
sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second()); // COSTAS
}
}
BLYNK_WRITE(V1) {
TimeInputParam t(param);
Serial.print("Checked schedule at: ");
Serial.println(Time);
int dayadjustment = -1;
if (weekday() == 1) {
dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}
if (t.isWeekdaySelected((weekday() + dayadjustment))) { //Time library starts week on Sunday, Blynk on Monday
Serial.println("Schedule ACTIVE today");
nowseconds = ((hour() * 3600) + (minute() * 60) + second());
startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
if (nowseconds >= startseconds) {
if (nowseconds <= startseconds + 90) { // 90s on 60s timer ensures 1 trigger command is sent
// code here to switch the relay ON
digitalWrite(zonePin3, LOW);
digitalWrite(zonePin1, HIGH);
delay(60000);
digitalWrite(zonePin1, LOW);
digitalWrite(zonePin2, HIGH);
delay(60000);
digitalWrite(zonePin2, LOW);
digitalWrite(zonePin3, HIGH);
delay(60000);
}
}
else {
Serial.println("Relay not on");
// nothing more to do here, waiting for relay to be turned on later today
}
stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
if (nowseconds >= stopseconds) {
// 90s on 60s timer ensures 1 trigger command is sent
if (nowseconds <= stopseconds + 90) {
// code here to switch the relay OFF
digitalWrite(zonePin1, LOW);
digitalWrite(zonePin2, LOW);
digitalWrite(zonePin3, LOW);
}
}
else {
if (nowseconds >= startseconds) { // only show if motor has already started today
Serial.println("Relay is still ON");
// nothing more to do here, waiting for motor to be turned off later today
}
}
}
else {
Serial.println("Schedule INACTIVE today");
// nothing to do today, check again in 1 minutes time
}
Serial.println();
}
void reconnectBlynk() {
if (!Blynk.connected()) {
if (Blynk.connect()) {
BLYNK_LOG("Reconnected");
}
else {
BLYNK_LOG("Not reconnected");
}
}
}
BLYNK_WRITE(V2) {
btnpin = param.asInt();
digitalWrite(16, btnpin);
}
void loop()
{
if (Blynk.connected()) {
Blynk.run();
}
timer.run();
}
Hey @gemforce,
Replace this section in BLYNK_WRITE(V1)
digitalWrite(zonePin3, LOW);
digitalWrite(zonePin1, HIGH);
delay(60000);
digitalWrite(zonePin1, LOW);
digitalWrite(zonePin2, HIGH);
delay(60000);
digitalWrite(zonePin2, LOW);
digitalWrite(zonePin3, HIGH);
delay(60000);
with this non-blocking version
digitalWrite(zonePin3, LOW);
digitalWrite(zonePin1, HIGH);
timer.setTimeout(60000L, [](){
digitalWrite(zonePin1, LOW);
digitalWrite(zonePin2, HIGH);
timer.setTimeout(60000L, [](){
digitalWrite(zonePin2, LOW);
digitalWrite(zonePin3, HIGH);
});
});