Help with button command on relay

Hello! :frowning: I have a small / big problem:

To operate an 6-12V electromagnetic latch, which standard is operated from the intercom button, I use a relay on the four-relay module in parallel with the intercom button.
The relay is commanded by a ESP8266-12F Witty Cloud. With a command from iphone (button widget, set to ā€œpushā€, 1 to 0).

On the same board, through the other three relays, they give similar commands the lights.

In the event of a power failure, when the electricity returns, the latch remains connected until the first command on the phone (if pressed on the intercom, it does not react). In the case of lights I have no problem, and generally the system behaves ok.

What to check, and what can be solving?

image

it would be interesting to know what gpio pins are you using for each channel?

the way you expalin is a bit confusingā€¦
you mean that one of the relays on the 4ch board stays on after mcu reset?

also, this is not blynk related issues and errors, so i changed the category for your topic.

For lights, use GP16, GP14, GP2 and for latch GP5.
I have to check the digital outputs on the board, possibly change the two outputs (ex. GP5 with GP16)

Iā€™m not sure what is the cause, but the the problem is that the bobbin coil (latch) remains continuously fed. unlocking can only be done on the phone. Today I noticed this after the tension dropped after a short period of time.

gpio 5 should be ok for the latch. the question is, you have an active high or active low relay board?

maybe the board has reversed logic, and this is why the relay is activated at startup. try to reverse the logic in the blynk button: for off set 1 and for on set 0.

if reverse 1 to 0, relay is on at startup, is not what I want :slight_smile:

ah, ok. than you just have to sync that pin at startup.

search in the docs, there is something like this:

blynkconnected{
syncvirtual(vp);
}

sorry, iā€™m on phone right now.

k. thanks for now

but, even better, to avoid keeping the latch ā€œonā€ in case of restart and there is no wifi / internet / server connection, is to turn off the relay right in the setup with digitalwrite, BEFORE attempting to connect to blynk server!

actually, you should always set all the outputs in the desired default state before initing blynk connection.

I tried to change pins assignments at buttons, but the issues remained at the same button, with the changed digital pin.
e.q.:
#first, the button (green - doesnā€™t matter color) assigned to door latch, has digital pin GP5 = relay start when power on module ESP, and relay stays ON.
#second, change pin of the same button(green) to GP15, problem migrate to GP15, and corresponding relay stays ON.
I removed button, create another one, set GP14, same problem.

I think is a Blynk software issue.

  • please post your formatted code
  • i do not think it is a blynk issue
  • in app are you using virtual pins or digital pins for button widgets?
#define BLYNK_PRINT Serial
#include "ESP8266WiFi.h"
#include "BlynkSimpleEsp8266.h" 

// You should get Auth Token in the Blynk App. 
// Go to the Project Settings (nut icon). 
char auth[] = "xxxxxxxx"; 

// Your WiFi credentials. 
// Set password to "" for open networks.
 char ssid[] = "xxxxxx"; 
char pass[] = "xxxxxxxxxx"; 

void setup()
 { 
// Debug console 
Serial.begin(9600); 

pinMode(1, OUTPUT);  //here I tried to say how to go at startup, initial without this line

Blynk.begin(auth, ssid, pass); 

} 

void loop() 
{ 
  digitalWrite(1, HIGH); //here I tried to say go on high mode at startup, initial without this line
Blynk.run(); 
}

I use digital pins
now, after switch pin assignments, I have:
Button 1 = GP5, button 2 = GP16, button 3 = GP14, button 4 = GP2

GP5 and GP16 acting OK, but, at power on board, GP2 start relay (go ON and OFF itself, acting ā€œpushā€) and after a few seconds GP14 start relay and remain ON and stay ON until use phone to set OFF.

Doesnā€™t matter how digital pin is assigned, button 3 and 4 has issue.

You have pinMode and digitalWrite set for GPIO 1 i.e. TX pin not any of the pins you are using with the relays.

digitalWrite needs to be in setup() not loop().

1 Like

Problem appear before write pinMode and digitalWrite lineā€¦ initial code was without this two lineā€¦

Now I search what is correct pins assignment for GP5/2/14 and 16ā€¦ then rewrite code.

Are they active LOW relays, most are but from some of your details they might me active HIGH.

Have they ever worked with Blynk?

Also if you only have the 4 channel relay board in your project you should be using regular GPIO pins 4, 5,13 and 14 not special pins 2 and 16.

I use this ā€œapplicationā€ about three monts.

Work fine from first time, for one light (just one button/one relay). Then upgraded with other three relay, adding three new buttons (one for door latch, and two more lights). Work well, with no problem until crash solenoid at door latch :frowning: . I initially believed is a latch problem (10 years old :slight_smile: ) and I bought a new one.

In one of the previous days, I noticed that the solenoid coil of latch is powered up, and I did the analogy with the power failure. I tested by power on and off and the suspicion was confirmed.

pin2 is builtin LED - I think is not so special,
pin16 is also not special (if I donā€™t miss something :slight_smile: )

please see:
ā€œI tried to change pins assignments at buttons, but the issues remained at the same button, with the changed digital pin.
e.q.:
#first, the button (green - doesnā€™t matter color) assigned to door latch, has digital pin GP5 = relay start when power on module ESP, and relay stays ON.
#second, change pin of the same button(green) to GP15, problem migrate to GP15, and corresponding relay stays ON.
I removed button, create another one, set GP14, same problem.ā€
you think is pins problem?

I will try this code:

#define BLYNK_PRINT Serial
#include "ESP8266WiFi.h"
#include "BlynkSimpleEsp8266.h" 

// You should get Auth Token in the Blynk App. 
// Go to the Project Settings (nut icon). 
char auth[] = "xxxxx"; 

// Your WiFi credentials. 
// Set password to "" for open networks.
 char ssid[] = "xxx"; 
char pass[] = "xxxxx"; 

void setup()
 { 
// Debug console 
Serial.begin(9600); 

pinMode(17, OUTPUT); //gp2
pinMode(20, OUTPUT); //gp5
pinMode(5, OUTPUT); //gp14
pinMode(4, OUTPUT); //gp16
 digitalWrite(17, HIGH); //gp2
 digitalWrite(20, HIGH); //gp5
 digitalWrite(5, HIGH); //gp14
 digitalWrite(4, HIGH); //gp16
 
Blynk.begin(auth, ssid, pass); 

} 

void loop() 
{ 
 
Blynk.run(); 
}

Pin 2 is part of the boot sequence and will be HIGH when the ESP boots.

Are you using version 5.0 0 library or the master branch?

See Advanced Warning - next library update will send ESP pins low on bootup

ā€œpin2 - not so specialā€ - my mistake, sorry Costas. In my case is very special. When I power on the board, builtin LED flash, that mean the relay receives the command.

By the way, the code with pinMode and digitalWrite line insert, do nothingā€¦ :frowning:

edit: I donā€™t see your post, Costas.