I am using an ESP8266-01S that only works with 3.3 V power. I want to control a 5 V relay.

I gave each component its own power source and got an NPN transistor and wired it like in the diagram, but for some reason, it's not working when I power the transistor from the GPIO2 pin.

When I plug the middle pin of the transistor to the 3.3 V the relay works fine. I don't want to use a logic convertor and I want the solution to be small and simple.

wiring diagram

  • 1
    Electronics circuits between two boards need to have common GND to operate properly.
    – hcheung
    Apr 24 at 9:13
  • Keep the GPIO2 pin high. Then measure the voltage of this pin with a multimeter. See if it is 3.3V or lower.
    – tepalia
    May 6 at 19:21

1 Answer 1


Connect the grounds of the two boards (maybe you already have).

Also, the maximum GPIO pin current of the RSP8266 is 12 mA. Connecting a transistor without a base resistor will send a large current through the BE of the transistor, which can damage the GPIO (and some transistors).

You have 3.3 V, minus the BE diode drop, say 0.6 V, leaves 2.7 V. Staying well within the GPIO's max. current, you can go for 9 mA base current. R = V/I = 2.7/0.009 = 300 Ω for the base resistor.

  • 1- I tried to connect the ground together but the ESP just turns off for some reason 2- I put a 1k resistor between gpio and the transistor but nothing happened I don't know if I should connect a lower resistance or not Apr 24 at 11:50
  • 2
    @Samyashraf, if your picture shown exactly the Relay module you had, it already has a resistor and a transistor (and a diode) on board, so you can directly connect to the board from GPIO2 directly to the relay board without extra transistor. You do need the common GND.
    – hcheung
    Apr 24 at 12:28
  • @hcheung ok, that works thanks, but I am also trying to make a custom PCB so what I need to make this connection work as I think I need a 5v relay without the module NPN transistor, and a 300-ohm resistance is that right, or is there is more to it? Apr 25 at 6:57
  • You also need a flyback diode to prevent in-rush current. See how to use a relay for more explanation.
    – hcheung
    Apr 25 at 11:09
  • @hcheung I just got the parts and tried what like the schematics but the relay makes like a buzz sound and don't work I even tried a potinchiometer and star loring the ohm until it works but still noting Apr 27 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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