I want to build a safe that can only be opened via an HTTP POST request. In order to do this the safe will contain a Raspberry Pi Zero W hosting a simple ExpressJS server that listens to these requests and uses rpi-gpio.js[1] to unlock an electronic lock[2].

This lock uses a 12V DC @ 2A power supply as the standby power, but it also needs a 12V signal to unlock electronically. I initially wanted to unlock it directly using one of the 3.3V GPIOs on the Raspi, but the lock would not unlock when setting the pin to 1. I tried several GPIOs, checked that they are functioning correctly, and they are indeed outputting the documented signal. I also tried using the 5V pin on the GPIO (that cannot be controlled) to see if 5V would be enough, but no luck on that as well.

The lock does unlock correctly if I feed the 12V @ 2A signal from the power supply (the same power supply I'm using to power the lock on standby) into the positive unlock input on the lock's logic board.

Since I can unlock it using the 12V @ 2A signal from the power supply, I want to use one of the GPIOs on the Raspi as a switch to open/close the circuit. Here's an idea of what I want to accomplish: https://i.stack.imgur.com/sdf4c.png (mirror: https://i.postimg.cc/MH2wLh8m/untitled.png)

I was thinking about using a ready made IRF520 MOSFET board with a reverse emf protection diode across the output to protect it from the voltage generated by the lock coil on power off.

My questions are:

  1. Is an IRF520 suited for this job?
  2. Which diode should I get?

Any insights are appreciated. Thanks for reading.

[1] https://www.npmjs.com/package/rpi-gpio

[2] https://www.amazon.com/Electric-Electronic-TPEKKA-Fireproof-Doorbell/dp/B074Z55WWG/ref=sr_1_110?dchild=1

  • \$\begingroup\$ The lock you list does not have separate 12v standby and a 12v trigger pin. It is a single 12v solenoid. \$\endgroup\$
    – Passerby
    Dec 16, 2020 at 23:01
  • \$\begingroup\$ What is the spec/schematic for the ready made IRF520 MOSFET board? \$\endgroup\$
    – mhaselup
    Dec 16, 2020 at 23:03
  • 1
    \$\begingroup\$ How will you be able to open the safe if the Rpi fails? \$\endgroup\$
    – mhaselup
    Dec 16, 2020 at 23:04
  • \$\begingroup\$ I couldn't find the exact same lock I have online, but mine does indeed have a 12V trigger pin. \$\endgroup\$ Dec 16, 2020 at 23:06
  • \$\begingroup\$ mhaselup, I haven't been able to find the schematics for that board, this is as much as I've been able to find: hobbycomponents.com/motor-drivers/…. \$\endgroup\$ Dec 16, 2020 at 23:13

1 Answer 1


The IRF520 will be OK for a 5V Arduino (see below for Rpi) based application, the max current 9.2A and voltage 100V are generously above your needs. The module you have indicated looks fine and is designed to drive DC motors so it may have an onboard flyback diode (I couldn't see it in the photo or spec). If you do need to add a diode nothing particularly special is required-an IN4007 will do the trick.

The Rpi has 3.3V GPIO so you need a MOSFET with a lower threshold. The IRL540 (2V threshold) should be OK here.


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.