I recently bought a Wemos D1 board and tried to connect a relay and test its connection.

I got an example server from here and executed. I connected D5 to a Relay's data and 5v and GND from Wemos board.

But this does not change the state of relay, it always remains high. I connected a LED for D5, it works perfectly with client's response.

Then I powered relay using an external 5v and ground connection, but the same result.

I have checked for possible solution, but coulnt find an answer.

The relay I am using is this one

  • 1
    Normally it is because people work under the misconception that D5 in the code is D5 on the board, but using the LED means you are using the right port in the code and hardware, so have you looked at it the board can supply enough current to trigger the relay (it only outputs <20mA). – Code Gorilla May 22 '18 at 11:48
  • 1
    Sounds like the pin cannot provide enough current to drive the relais. Try to use a transistor or MOSFET for it – chrisl May 22 '18 at 11:53
  • @chrisl can you provide me an example? I am not good with electronic stuffs. Thanks for the comment. – Sachith Muhandiram May 22 '18 at 12:07
  • 1
    You may need a BJT transistor to amplify the current. Look at electronics.stackexchange.com/questions/220492/…. Do you use a bare-bones relay or a relay board? Which one exactly? – Maximilian Gerhardt May 22 '18 at 12:15
  • 1
    you have a relay module? add a link to it – Juraj May 22 '18 at 13:00

The board which you are using is operating on 3v3. Even if you try to run the relay using the D5 or any other pin on the board, you may not be able to run it successfully at all times. In this case, you can go for either MOSFETs or Pull-up resistors so that you can hold the voltage to 5V for triggering the relay. I would personally suggest to go for a PNP type.

As requested by Sachith, here is the circuit suggested for the problem stated. Just note that the voltage source should be +5 V (which is +1 V in the schematic). Also, the MOSFET is not the specific one, it is just for the schematic purpose.


simulate this circuit – Schematic created using CircuitLab

| improve this answer | |
  • I would expect that a 5 V TTL senses 3.3 V as HIGH. I think he has some other problem. – Juraj May 24 '18 at 13:56
  • @Juraj: your expectations are too high for fleabay modules; i have several single-relay boards that work perfect at 5v, but spotty or not at all on 3.3v... – dandavis May 24 '18 at 18:43
  • @dandavis, with 5 V power supply and 3.3 V signal? – Juraj May 24 '18 at 19:35
  • @Juraj: yes, with 5v in from usb, 3.3v i/o on ESP, many are sporadic at best – dandavis May 24 '18 at 19:54
  • but patching the module's on-board TTL circuit with external MOSFET? is it a good answer? if I would want to care about electronics details, the I would take a plain relay – Juraj May 25 '18 at 4:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.