Problem with relay and ESP-01

Hello,

I’m using a ESP8266 (ESP-01) to control a relay module:
https://robotdyn.com/relay-module-1-relay-5v-30a.html
I sucessufuly connected the ESP-01 to cayenne.

The connections I made were:
ESP-01: VCC and CH_PD to 3.3V
GND to 0V
GPIO2 to In of relay
Relay:
VCC to 5V
GND to 0V
IN to GPIO2 of ESP-01.

I can activate the relay once, by pressing the dashboard widget, but when I click it again it does not turn off relay and a loading animation appears on the widget.
Any solutions?

Thank you

Are you using an FTDI. Add #define CAYENNE_DEBUG in the code and check the serial monitor. Maybe the esp is restarting on not getting enough power.

Hello,

I used this to program ESP-01, an USB adapter for programming ESP-01:
https://www.ebay.co.uk/itm/ESP-01-ESP8266-Switchable-USB-Adaptor-Programmer-CH340G-UK-Seller-/322466871464

When I connect this adapter with ESP-01 to usb of computer, everything works good. When I remove ESP-01 from it, and make this connections externaly (with exterior power supply), the loading animation on widget hapens:
ESP-01: VCC and CH_PD to 3.3V
GND to 0V
GPIO2 to In of relay
Relay:
VCC to 5V
GND to 0V
IN to GPIO2 of ESP-01.

can you try powering the relay from separate power source with common ground.

So, I changed the system:

The relay module is now powered from 5V DC of raspberry PI (5V and GND pins).
The ESP-01 is powered by breadboard, that is powered by this:

The IN pin of relay is connected directly to ESP-01 GPIO2. I managed to turn on relay and then turn off, but when I clicked widget to turn off the loading animation stayed…
When I share a common ground between ESP-01 and relay, the blue light of ESP-01 turns on (indicating bad power supply)

can you try running the esp alone first on the separate power supply and see if the button works.

ESP-01, when powered by breadboard power module, enables perfectly the ON/OFF clicking on dashboard widget. The problem of widget stuck in loading animation doesn’t happen.

When I connect IN pin of relay to GPIO0 of ESP-01, the ESP-01 disconnects sometimes or the loading animation happens.

Does your relay module has an opto coupler?

Yes, the relay module has opto coupler.

it is power issue, maybe try to use 1000 uF capacitor close to 3.3V line.

This breadpower power supply I’m using:


Already has capacitator integrated in it. The power supply is good and stable.
I think the problem here, is the relay module working on 5V and ESP-01 with 3.3V, any solution to this?

the relay module supports 3.3v logic control. it is something to do with power supply.

Yes it does. But explain me why the widget on dashboard keeps stuck on loading animation?

Because the esp reset and never sends the updated state response required to show the change and thus the button gets stuck.

Interesting. Will analyse the problem further and respond here if I solve it. Thank you

it is something to do with the power supply. Try powering it a different power supply.

Finally I solved the problem. It was not the power module problem.
Regarding the use of ESP-01 (ESP8266) to control actuators, in this case a relay, or a sensor, you have to pay attention to this explanations:
image
https://www.forward.com.au/pfod/ESP8266/GPIOpins/ESP8266_01_pin_magic.html

I connected GPIO02 directly to IN of relay module. Every time i powered the ESP-01 reseted or booted incorrectly (blue led ON), and I wasn’t able to use it and connect it to cayenne. When I first powered the ESP-01 and then connected the signal GPIO of ESP-01 to IN of relay the ESP-01 worked correctly by controling the relay module trough cayenne dashboard.
The problem is this:


The relay module or sensor was puting GPIO2 high and GPIO0 low, puting the ESP-01 on programming mode and not Flash (normal running).
I’m not 100% certain about this, but the solution worked.

Thank you

the relay pin is an input pin so connecting it does not make the esp pin HIGH or LOW in general.
Anyways good to hear it is working now.