I have this relay module that is attached to an ESP8266 (Wemos D1 Mini). Currently, I operate the relay by shorting the IN and GND pins to ground (relay module uses low state to energize) with a transistor hooked to my D1 pin. Relay 5V comes from an external power supply

The circuit diagram can be found here.

The module works fine and all but I am wondering: is it okay to operate it like this ?

circuit diagram

  • the schematic is messy, but it looks ok ..... put a 1k ohm resistor between pin D1 and the base of the transistor for current limiting on pin D1 ..... put a bypass diode on the relay coil to prevent voltage kickback when the relay is de-energized .... the kickback may destroy the transistor – jsotola Jan 7 '19 at 0:20

It is not okay. The base-emitter of an NPN transistor acts as a diode. That means pin D1 is shorted to GND via a "diode". You need a resistor to the base of the transistor.

The relay module has already a transistor to drive the relay and also a flyback diode. The control signal that is needed depends on the relay module. The explanation "5VDC to 12VDC (some boards may work with 3.3)" on the page of the relay does not sound reliable.
The relay module on that page is not the module that you have. You have a different module that is activated with a low signal.
Nevertheless, I think that a transistor can be used when the IN and GND of the relay module are connected to the collector of the transistor.

Could you please not try to make the schematic as small as possible. A schematic should explain how everything is connected.

Could try to connect the collector only the IN pin? As in the schematic below.


In your circuit diagram, the mains "neutral" is connected to an earth ground symbol. I hope you are not going to connect a mains wire to ground.

When the IN and GND are connected, then the resistor to the transistor needs to be lower. The ESP8266 can output 12 mA. Let's use 10 mA for safety: (3.3V - 0.5V)/10mA = 280 Ω. I suggest using a resistor of 330 Ω or more.

  • The relay in the schematic is barebone as I couldn't manage to find the actual module to add to it. I just found the relay that is used on the module as a reference. The relay needs 5v and my microcontroller can only deliver 3v. That's why I'm using my own transistor. As with the schematic, it's my first one ever, first project ever. Thanks for the advice. As with the mains neutral, indeed I'm not connecting it to ground, I messed up the symbol and didn't care after. Again, it was just for reference. – TermoZour Jan 7 '19 at 6:39
  • @TermoZour which transistor do you really use? I have added a calculation (below the horizontal line) to my answer. I think 330Ω or 470Ω are good and safe values for the resistor. – Jot Jan 7 '19 at 9:00
  • I use a BC548B with a 510 ohm resistor on it's input signal – TermoZour Jan 15 '19 at 9:09
  • The sdrd-05vdc-sl-c relay is 5v 70mA. The bc548b is maximum 100mA. I'm not happy with that, but it might work. Does the relay work with a 510 ohm resistor to the base? When the transistor is on, you could measure the voltage of the collector. If it is about 0.1v then the transistor is fully turned on and it is okay. – Jot Jan 15 '19 at 9:16

You mean that you pull your Arduino relay control pin LOW, causing it to ground the pin? Yes, that sounds correct. (And you would set it HIGH to not energize the relay.) You might need a low value resistor between the relay's logic pin and the Arduino output if the relay is sinking too much current through the Arduino logic pin. A 100 ohm resistor would prevent sinking too much current through the Arduino logic pin. Try it and see if the relay still energizes.


When I posted my answer the image wasn't loading, so I had to guess as to what you were describing. My guess was wrong, and thus my answer was wrong too.

Since you're driving the gate of a transistor you will need a current limiting resistor or you will overload the logic pin on your microcontroller. (As Jot says in their answer.)

There are 3.3v versions of these logic-driven relay modules readily available, and some even include optical isolation, so why not use one of those?

Take this one for example: https://www.adafruit.com/product/3191 (I don’t think that one has optical isolation.)

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