Problem: ESP1 triggers relay on power-on/reset

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ChrisO
New user
Posts: 8
Joined: 29 Dec 2021, 20:24

Problem: ESP1 triggers relay on power-on/reset

#1 Post by ChrisO » 29 Dec 2021, 21:09

Hi

The problem was already discussed here for an older version, v1.0.
I have the relay module labeled: ESP-01/01S Relay v4.0 TB:IOTMCU.
And the same problem: on power-on there is a short level toggle on the GPIo0 which triggers the relay.
So, after power outage my garage doors would be open :-)
Is there anyone out there having a solution to this problem?
A workaround I already have: Raspi Zero + Relay module :-)
A ESP-01 would be a bit easier/smaller, though.

Any help would be really appreciated.
Regards,
Chris

TD-er
Core team member
Posts: 8607
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem: ESP1 triggers relay on power-on/reset

#2 Post by TD-er » 29 Dec 2021, 21:50

GPIO-0 is pulled high during boot.
So if that's the situation you don't want to have, you might want to invert your logic.
Meaning the "high" level should then be the situation where nothing happens.

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Problem: ESP1 triggers relay on power-on/reset

#3 Post by chromo23 » 29 Dec 2021, 22:18

Are you sure GPIO0 is high at boot?
I use this as a reference and it always worked for me so far: https://randomnerdtutorials.com/esp8266 ... nce-gpios/
And there it states that GPIO0 is not high at boot.

edit: found a solution: https://github.com/IOT-MCU/ESP-01S-Relay-v4.0/issues/1

TD-er
Core team member
Posts: 8607
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem: ESP1 triggers relay on power-on/reset

#4 Post by TD-er » 29 Dec 2021, 22:38

Yep, it MUST be pulled high at boot or else you will enter flash mode.

See: https://espeasy.readthedocs.io/en/lates ... on-esp8266
To enter flash mode, you have to pull GPIO-0 down to GND.

ChrisO
New user
Posts: 8
Joined: 29 Dec 2021, 20:24

Re: Problem: ESP1 triggers relay on power-on/reset

#5 Post by ChrisO » 30 Dec 2021, 21:30

Let me clarify:
On power-on/reset the GPIO0 on the ESP8266-01 goes up and then down. It is not simply pulled up.
It's not what I believe, it is what I observed.

This up-down (+5v-GND) triggers the relay. Even if I could change the logic it wouldn't help because it toggles.
I was looking for a remedy to this, hoping there is maybe a firmware version which would eliminate it or something similar.

> Yep, it MUST be pulled high at boot or else you will enter flash mode.

I'm sorry to contradict you, it's other way round, it must be pulled down to enter flash mode.
In normal operation, when the ESP8622-01 sits on the relay-board, this GPIO0 pin is connected to the relay and the relay will not change the voltage on this pin, it just waits for 5V to close the coil or release it when 5v is gone.

Have just found this, about "What is the GPIO level status?" here:

https://www.espressif.com/en/products/s ... /resources under FAQ.

Looks like GPIO0 is high after boot with the factory firmware (AT-commands).

Every ESP8266 I flashed with proprietary/own firmware (using Arduino IDE) behaves like I described above.
Is it the bootloader? A kind of start-up initialization before our program gets started?
Go figure why.
Got few 470uF capacitors, will give eventually this workaround a try. I don't think it's the right way, though.

TD-er
Core team member
Posts: 8607
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem: ESP1 triggers relay on power-on/reset

#6 Post by TD-er » 30 Dec 2021, 22:37

All ESP boards have a pull-up resistor present on GPIO-0.
The ESP12S modules have it even in the module itself which makes them even easier to use.

Now about the GPIO state.
How do you control this pin?
Is it via the switch plugin?
Then you may see a difference between power up (power cycle) and reset/reboot/crash.
This difference is cause by the last value of all tasks being restored from RTC memory.

ChrisO
New user
Posts: 8
Joined: 29 Dec 2021, 20:24

Re: Problem: ESP1 triggers relay on power-on/reset

#7 Post by ChrisO » 31 Dec 2021, 01:13

> All ESP boards have a pull-up resistor present on GPIO-0.

This confirms what I said: "Looks like GPIO0 is high after boot with the factory firmware (AT-commands)."

> Now about the GPIO state.
> How do you control this pin?
I don't.

> Is it via the switch plugin?
> Then you may see a difference between power up (power cycle) and reset/reboot/crash.
> This difference is cause by the last value of all tasks being
> restored from RTC memory.

I feel misunderstood.
I write a scetch in Arduino's IDE, download it to the ESP8266-01 and
restart it (with GPIO0 not grounded, etc) GPIO0 goes very quickly up
and down and remain down. All this before my
program/scetch/you_name_it executes its first statement.

Just tried: installed a trivial scetch, nothing with GPIO, put the ESP8266-01 in the relay-board, powered it on and click-click: up and down. Something does a kind of "initialization".

User avatar
Ath
Normal user
Posts: 3386
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Problem: ESP1 triggers relay on power-on/reset

#8 Post by Ath » 31 Dec 2021, 10:15

I get the impression that the real problem here is in the 'design' of the board. Or in fact the lack of a proper design, as any sensible ESP designer would have avoided the use of GPIO-0 for an output. The side-effect of that lack of design is what you are now experiencing, and I think the only sensible solution is to re-wire the board to use any of the other GPIO pins, or use another board that has a different GPIO layout.
This is never going to be decently resolved using this board, only the proposed workarounds, delaying/dampening the 'spike' output, will kind of work, until something changes, and the delay/dampening isn't enough anymore...
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Problem: ESP1 triggers relay on power-on/reset

#9 Post by chromo23 » 03 Jan 2022, 17:14

Got few 470uF capacitors, will give eventually this workaround a try. I don't think it's the right way, though.
actually this is not what i meant. should have been clearer, sorry.
There is also the much more simpler solution of changing the pin to gpio3 in this thread. maybe this helps...

TD-er
Core team member
Posts: 8607
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem: ESP1 triggers relay on power-on/reset

#10 Post by TD-er » 03 Jan 2022, 17:32

See: https://espeasy.readthedocs.io/en/lates ... on-esp8266
GPIO-3 is the ESP RX.
This one is high at boot.

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Problem: ESP1 triggers relay on power-on/reset

#11 Post by chromo23 » 03 Jan 2022, 18:00

i know, it is not what i would recommend intuitively but that is what people in the github thread did to circumvent the issue described here..

ChrisO
New user
Posts: 8
Joined: 29 Dec 2021, 20:24

Re: Problem: ESP1 triggers relay on power-on/reset

#12 Post by ChrisO » 04 Jan 2022, 00:33

Ath wrote: 31 Dec 2021, 10:15 I get the impression that the real problem here is in the 'design' of the board. Or in fact the lack of a proper design, as any sensible ESP designer would have avoided the use of GPIO-0 for an output. The side-effect of that lack of design is what you are now experiencing, and I think the only sensible solution is to re-wire the board to use any of the other GPIO pins, or use another board that has a different GPIO layout.
This is never going to be decently resolved using this board, only the proposed workarounds, delaying/dampening the 'spike' output, will kind of work, until something changes, and the delay/dampening isn't enough anymore...
Well, I learned a bit more in the mean time. The "original" firmware (bootloader?) let the GPIO0 as it was designed to be: HIGH, 5V. Not perfect, but I could live with it.
But somebody decided to put it LOW in the "program" we download into the ESP8266 from the Arduino's IDE. Whatever the idea behind was is is not well thought-out, IMHO. And this toggle makes the whole thing useless for serious use.
A pity.

ChrisO
New user
Posts: 8
Joined: 29 Dec 2021, 20:24

Re: Problem: ESP1 triggers relay on power-on/reset

#13 Post by ChrisO » 04 Jan 2022, 00:35

TD-er wrote: 03 Jan 2022, 17:32 See: https://espeasy.readthedocs.io/en/lates ... on-esp8266
GPIO-3 is the ESP RX.
This one is high at boot.
So is the GPIO0, only just for a very short time ;-) See my reply to Ath.

ChrisO
New user
Posts: 8
Joined: 29 Dec 2021, 20:24

Re: Problem: ESP1 triggers relay on power-on/reset

#14 Post by ChrisO » 04 Jan 2022, 00:40

chromo23 wrote: 03 Jan 2022, 18:00 i know, it is not what i would recommend intuitively but that is what people in the github thread did to circumvent the issue described here..
I was already there. I would prefer to catch the guy who pulls it down after/while booting a sketch ;-)

ChrisO
New user
Posts: 8
Joined: 29 Dec 2021, 20:24

Re: Problem: ESP1 triggers relay on power-on/reset

#15 Post by ChrisO » 04 Jan 2022, 21:30

Just for reference.
I was partially wrong. I've just realized that the relay on my relay-board where the ESP8266-01 is sitting is LOW triggered. My bad. That means when the ESP8266-01 boots, before GPIO0 goes, as designed, to 5V it is for a very short time LOW. That closes the relay and then GPIO0 goes HIGH and my relay opens.
I was thinking it was the other way round.
That means it has nothing to do with Arduinos sketches etc. I received today two brand new ESP8266-01, with just AT firmware and observed what I described above.
Well, I'm not the first one who noticed this toggle and there was no reaction from ESP8266-01 manufacturer, I guess we are on our own.
Thanks
ChrisO

TD-er
Core team member
Posts: 8607
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem: ESP1 triggers relay on power-on/reset

#16 Post by TD-er » 04 Jan 2022, 22:33

You could consider the pin logic inversed.
Then "high" is the default state, also during boot and you have to actively pull it down in software.

ChrisO
New user
Posts: 8
Joined: 29 Dec 2021, 20:24

Re: Problem: ESP1 triggers relay on power-on/reset

#17 Post by ChrisO » 04 Jan 2022, 23:03

It would not help. There are both levels on the pin before I get control over it. This LOW-HIGH I cannot control, one of them would trigger the relay. Now it is the LOW if I invert the logic
it would be the the HIGH. It is just sh...y design of handling GPIOs.
BTW, tried this 470uF on the optocoupler workaround and it looks like it works.

darkodel
New user
Posts: 1
Joined: 21 May 2022, 19:30

Re: Problem: ESP1 triggers relay on power-on/reset

#18 Post by darkodel » 21 May 2022, 19:56

One way to do it is to control relay by transmitting serial characters from the ESP-01 rather than controlling an OUTPUT pin. HW-655 is a ready relay board for ESP-01 where relay is controlled by Serial.write. The board includes ESP-01 module but it can also be controlled directly via exposed serial pins.

Send to serial {0xA0, 0x01, 0x01, 0xA2} to open relay and {0xA0, 0x01, 0x00, 0xA1} to close it.

It might seem complicated to write to serial some strange strings instead of just controlling an OUTPUT pin but it really makes sense. It gives you better control and relay will not open or close accidentally during power on/off, just because a pin went HIGH or LOW when you didn't want it.

This is where I found a basic code A simple Arduino program for controlling an LC Tech serial relay board https://gist.github.com/ItKindaWorks/52 ... ad12743bc5
If the link doesn't work just go to GitHub Gist and search for ItKindaWorks/serialRelayTest.ino

To find where to buy HW-655 board, just google it.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests