# How do I turn on a magnetic lock with an Arduino?

I have a 12v magnetic lock, which is just an electromagnet. I want to turn it on with my Arduino.

I've been able to turn on/off a 5v motor with the Arduino. So I'm guessing the wiring is similar. The problem is I need 12v. I looked for a 5v to 12v DC convertor at Fry's and DigiKey, and couldn't find any. I can only find ones that go from 12v to 5v.

I found a this youtube video doing exactly what I want, but it's short on details. He only has a single electronic on his breadboard that he calls a "DC convertor". No transistor, no diode. How does that work?

Also, is the current from the Arduino enough to power a magnetic lock, or should I have an external power source?

I'm very new to electronics. Any help is appreciated.

• A relay might be a good place to start. – uint128_t Jan 19 '16 at 1:01
• So your entire question is about how to power the electromagnet, not how to control it? – immibis Jan 19 '16 at 8:19

You need a relay circuit, here is a simple relay circuit example.

(source)

You should find a relay with 5VDC coil, and replace the +12VDC power supply with 5VDC, use the same power supply that powers your arduino. And then use 12VDC power supply instead of 240VAC. Put you magnetic lock where the 240VAC bulb is.

• To get the 12VDC power supply, do I just get a spare 12V power supply that plugs into a wall (say, that used to go to a printer), and strip the wires? Do I put the ground wire where the diagram says "Neutral"? – abtree Jan 19 '16 at 1:11
• Yes, you connect the wire marked «240VAC» at the diagram to «+» on the spare 12VDC power supply, and «Neutral» to «-» on spare power supply. Just remember to replace the «240VAC bulb» with magnetic lock, else there will be a short circuit. – BufferOverflow Jan 19 '16 at 1:20
• What's the purpose of the resistor and transistor next to the on/off? Why not connect the on/off directly to the coil? – abtree Jan 19 '16 at 11:39
• The transistor is the only part of this circuit that's needed, because it controls a 12V device with non-trivial current (which could be the magnetic lock) from a 3-5V digital signal that the microcontroller can provide. – Ben Voigt Jan 24 '16 at 0:47

one way is to use a couple of transistors

simulate this circuit – Schematic created using CircuitLab

You could use a relay or a transistor. I'm assuming the current draw is pretty low, so almost any transistor or relay would work.

simulate this circuit – Schematic created using CircuitLab

• To use a relay you should first see te resistance of the inductor to not damage the arduino output pin.I recommend to use only a transistor or a mosfet as a control device. – Stefan Merfu Jan 24 '16 at 12:43