Help with button command on relay

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.

you should begin using virtual pins, and do not use digital pins anymore from the app, it is quite lame stuff. you can write much better / robust code with virtual pins.

All code does something and what you have is bad code, remove it.

@wanek I think for now the OP should kick off with physical pins until they know a bit more coding and how ESP’s work. Then they can advance to the more complex and more powerful virtual pins.

Arduino said:
" Downloading ‘https://raw.githubusercontent.com/blynkkk/blynk-library/master/library.properties
… done.
Latest version: 0.5.0"

At this moment I’m so confused:

Nothing work!!!

after ESP power on, at 5 or 6 seconds, ALL relay is ON

I revert to initial settings and same, all relays is ON… maibe it is too late for work: 4am…

For the most common relays, active LOW, and safe pins that is the default for ESP’s.

It will also be the default when Blynk issues the next default for any widgets tied to digital pins.

You need to use digitalWrite() properly and virtualSync() if you don’t want pins to be LOW after the ESP boots.

ok, after a short private conversation with the op, it is clear he has some problems with the lib sructure also. he will open a topic on the romanian forum, as he has some difficulties with english.

at least, this is what i’ve suggested :slight_smile:

1 Like

@Costas, @wanek, appreciate your response and attempts to make me understand how Blynk works and digital outputs, but what I do not understand is: why if two digitally buttons have worked well, then it does not work anymore.

And if it is as you say, use additional code lines, then in Blynk presentation should NOT write “Direct pin manipulation with no code writing”. :slight_smile:

I was excited about the ease of using this application, being ignorant of programming languages, and as a mediocre user of arduino, but it starts to pass me :slight_smile:

I understand Blynk’s work and I will try to study, and I hope to clarify certain things.

the issue can be multiple:

  • bad library structre (this is for sure based on the pm)
  • defective jumper wire between mcu / relay boards
  • defective relay board
  • etc

as i suggested, please open a new topic on the romanian section, if you wish, or we can continue here. just do not cross post.

@mircea there is a bug in 0.5.0 relating to digital pins whereby the library was not iterating through a pinMode() loop that should set all pins LOW for widgets tied to digital pins. The bug is fixed in the master copy of the library and will be available in the next library update.

It’s not Blynk’s problem that most relays were designed to be active LOW and therefore will be ON when the ESP boots up.

I never say this… I understand this think well. I is my job to try many inputs, depending on hardware,no problem.

Thanks to @wanek, project go to the right direction. :+1:

I added right code line, in right place and everything works fine. Also help me to have updated applications (Blynk and Arduino).

From now on the sun shines on my street :sunny:

1 Like