Using an ESP8266 relay with normal pins

Hello,

I have an ESP8266/ESP01 relay, the one with the wifi microprocessor

I would like to use it with an Arduino board though, so the relay command must come from an external source, not from the ESP8266/ESP01 that is usually coupled to this kind of relays.
I cannot understand which is the pin that I should supply with 5 or 3.3V in order to make it toggle.
Can you please help me? Thank you very much in advance!

this is the pinout of esp01

the vcc pin of esp01 isn't directly connected like that. there is a linear voltage regulator present on those types of relays so you can supply 5-12v.

Hello amitf,

Thanks for your reply but sorry, I did not understand.

The general test I am trying to do is to toggle the relay by just putting 5V taken from the wemos D1 mini board.
So:

  • I powered the relay with the red and black solid lines you see
  • Since there are many versions of the ESP01 pinout on the internet, with a multimeter, I checked all the pins in the yellow connector by bridging them with GND and VCC to check continuity. 3 of them are either connected to GND either to VCC
  • Therefore, with all the other pins, I tried to make a bridge with the 5V or 3.3V, to find which pin was going to make the relay toggle (assumed GPIO0 or GPIO2 but I tested all of them to be sure)

None of the pins, if supplied with 5 or 3.3V, makes the relay toggle. Why?

the pinout of esp01 is pretty Standard. pin 1 is GND and pin 8 is 3.3v.


i have marked GND with black and 3.3v with red.
check the voltage with your DMM if you are getting 3.3 at pin 8 or not.

Hello Amitf,

Yes. Actually, since I have a temporary problem on my 5V pin, I tried with the 3v3 pin and then at pin 8 I get 2.7 V. I assume that if my 5V pin was working, I would get the desired voltage.

Moreover, I did the following tests:

  1. tried all the combinations to see where I get voltage and where I don't, and I found all the grounds (black dots) and the positive poles (red dots). I have 3.3 V (exactly the same as input) only between pin 1 and the positive pole coming in input (right on the left of pin1). On all the other pins instead I could measure 2.7V as said above (I assume internal resistances).
    Strange thing (for me) is that if I put the multimeter in circuit continuity mode, when I put one probe on pin 1, it beeps either if I put the other probe on the positive input either on the ground input.

  2. I did the same tests on another relay of the same type and got the same results. The relay with yellow connector is v4.0.0 while the one with the black connector is v5.0.0. Also all the resistances and module components in general seem the same both in type and disposition.

Marco

Yes, the linear voltage regulators has some level of dropout voltage.

Because it is completing the circuit. The multimeter will aslo show some resistance between gnd and VCC

Pin 4,5,6 need to be high for the working of esp01 that's why you are getting 2.7 v on those pins.

  • For the working of relay you need to provide 5v.

  • Does your relay work with esp01 module?

Hello Amitf,

I don't know if the relay works with the ESP01, I don't have the USB/TTL adapter for the moment and hence no way to program the ESP01.

Anyway, as I wrote above, when 5V was working I tried to supply 5V in every of the pins one-by-one (except no. 1), but the relay was not switching.
This evening I can fix the issue on the 5V pin and try to do the same thing also on the other relay.

if you power the relay board with 5v, connecting pin 3 (gpio 0) with pin 1 (GND) should switch the relay.
There is a schematic of the board here in this thread on github

You can use more than 5v. If you have some 7-10v source. It would work fine.

As Rishi suggested you should try with GND not the 5v.

Thank you very much to both, it works now.

But this then means that I can't control the relay externally with the wemos D1 mini? Because if it was with the 3.3/5V I can set the pin to high or low in the script, but then if I have to control it with the ground, I can't set the ground to high or low

sorry ?
Eh no you connect GND on the Wemos to GND on the ESP-01 socket (pin 1)
and somehow the relay board needs power and so does the wemos so you power the wemos from there.
Just like the ESP-01 would be powered from there,
Connect the wemos 3.3v pin to the ESP-01 socket Vcc pin (pin8).
and you connect a GPIO pin on the Wemos to the switch pin on the ESP-01 socket.

edit: How you convert the 5v input to 3.3v is optional, the Wemos does have a really efficient regulator, but if you want to use it, you should make sure that the 3.3v on the relay board does not get to Vcc pins.
The 3.3v which powers the opto-coupler that controls the relay is the same as on the ESP-01 socket, and that should be connected to the 3.3v on the wemos,, but not both regulators should be providing 3.3v to the same circuit.
The relay gets it's 5v power from the power input.
So there is the catch, you can't use the Wemos 3.3v regulator and the relay board regulator at the same time.
Some of those relay boards have jumpers that can be removed, but the one you have doesn't appear to have one.

Then programatically you set the connected GPIO pin to OUTPUT, and when you set the pin LOW

digitalWrite(GPIO, LOW);

the relay closes.

If you want to make sure the relay doesn't first open you should set the pinMode after first setting the GPIO pin HIGH.

I feel a bit silly explaining this.

  • HIGH means 3.3v
  • And LOW means GND (0v)

If you write
digitalWrite(d3,LOW); the relay will turn ON and digitalWrite(d3,High) to turn relay OFF.

Thank you very much Amtif, very simple and clear, it worked.

In fact, I had already tried to do this yesterday evening because it's pretty logical indeed, but the problem is that I had connected the pin to GPIO2 (Wemos board side), which on the board itself says "2", so I thought it was D2.
Now instead I notice that from what you showed, GPIO0 = D3, for example. In the Wemos D1 R2 I used so far instead it was pretty equivalent GPIO0 = D0, GPIO1 = D1 etc.
Moreover I had also checked with the multimeter that the voltage was going up and down on the desired pin, but it was late evening after having worked 9h so I might have missed something else...

As last question, if you could tell me where to retrieve the information GPIO0 = D3 for the next time, I would be very glad

Thank you again

the pinout of the board is one source, a very simple

Serial.print("Pin D3 = GPIO ");
Serial.println(D3, DEC);

should reveal it as well.

It is one of the strange things of how ESP8266 have been put together.

@amitf In your schematic you sink the current that is provided by the 3.3v regulator on the relay board, through the Wemos which has it's own regulator. This is not preferred.

The relay is connected through 5v(vbus) pin on wemos.
The voltage regulators on wemos and relay is powering there circuit separately.

I don't understand what you are trying to say.
Did you mean that the Wemos should also get power from the 3.3v pin of the relay?

OIP

The gpio pin name does not correspond to naming on the board. (Neither in wemos mini nor in wemos R2)
It will be easier for you if you address the pin like D0,D1,D2.... In your code .

That is one option, or the opto-coupler (PC817) on the relay board should get it's 3.3v from the Wemos.

As it is in your schematic, the regulator on the relay board provides power to the PC817, which then the Wemos is sinking.
The opto-coupler drives the circuit that controls the relay, but this all happens at 5v.

I admit it's details, the voltage drop of the PC817 should make it all really safe anyway.

or you could use a NPN transistor

indeed, in addition 470ohm resistor in series with opto-coupler will only let approx. 7mA of current to flow.

But not from the same 3.3v power source that powers the Wemos.

Personally i would cut the 5v input to the relay board regulator (the output probably has both the center pin and the heatsink connected to the PCB) or pull the whole regulator off, (The best) and connect the Wemos 3.3v to pin 8 on the ESP-01 socket.

It is partly the result of the design of the relay board icw the requirement of the ESP-01 gpio pin of choice that can not be pulled LOW at boot, which results in the circuit having to be active LOW for it to work with the ESP-01.