enter image description hereI've been trying to power my 5v relay through a MOSFET but I can't seem to get it to work. I'm using a IRLI540N with the gate to GPIO 24 that goes high when I click the pushbutton (that much does work, I checked with some leds before) drain is to 5v and source is to one of the coils of the relay.

I tried the rest of the circuit manually switching the relay on with 5v power and it does work (the solenoid pulls, which is all I want to be able to do via code), I just really don't know how to switch it logically with this or any other sort of transistor.

Is there any way to switch it on with logic with the mosfet or through any other type of switching that doesn't involve a relay board module? (It would solve my problem, but I wasn't able to get one of those).

  • \$\begingroup\$ IRLI540N is NMOS. Drain should go to coil, source to GND. Coil should go between 5V and drain. Try assembling it this way and see if the problem is solved. \$\endgroup\$ May 8, 2018 at 5:46
  • \$\begingroup\$ So should I connect the drain, coil and 5v to the same rail? \$\endgroup\$
    – Victor
    May 8, 2018 at 5:53
  • \$\begingroup\$ you have to put a schematic otherwise the question wont be clear to people here. \$\endgroup\$
    – Mitu Raj
    May 8, 2018 at 5:55
  • \$\begingroup\$ @Victor No, that's not what I said. Best representation I could give without drawing a schematic: (5V) - (|coil|) - (D|S) - (GND). I won't draft it up as an answer because it's hard to say if this is the real problem without looking at a schematic of what you got assembled. \$\endgroup\$ May 8, 2018 at 5:59

1 Answer 1


This is what you should be looking for to switch NMOS and relay. Source is grounded.


simulate this circuit – Schematic created using CircuitLab

  • \$\begingroup\$ I think I get it, so I'd have to put 5v as if I were to have the relay ALWAYS on, but then have the MOSFET in the middle of that circuit (between the second coil and ground) drain to coil and source to ground? (with a resistor in parallel) \$\endgroup\$
    – Victor
    May 8, 2018 at 6:06
  • \$\begingroup\$ yea that resistor to the gate is called pull-down resistor. \$\endgroup\$
    – Mitu Raj
    May 8, 2018 at 6:14
  • 1
    \$\begingroup\$ This schematic is missing the flyback diode though. \$\endgroup\$ May 8, 2018 at 11:13

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.