Arduino - Electromagnetic Lock

The electromagnetic lock (EM lock) is widely used to lock the door. It is usually used with switch, fingerprint reader, RFID/NFC reader, keypad, or application on PC/mobille to control access to door, buiding gate ... The electromagnetic lock is also known as magnetic lock, or maglock.

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×Electromagnetic Lock
1×Relay
1×12V Power Adapter
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.
Or you can order electronic components from utsource.net

About Electromagnetic Lock

Pinout

Electromagnetic Lock includes two components:

  • One electromagnet with two pins
  • One armature plate
  • Electromagnetic Lock Pinout

How It Works

  • When the electromagnet is powered, a current passing through the electromagnet creates a magnetic flux that causes the armature plate to attract to the electromagnet ⇒ a locking action
  • When the electromagnet is NOT powered, there is no a magnetic flux, armature plate does NOT attract to the electromagnet ⇒ a unlocking action

※ NOTE THAT:

The electromagnetic lock usually uses 12V, 24V or 48V power suppply. Therefore, we CANNOT connect the electromagnetic lock directly to Arduino pin. We have to connect it to Arduino pin via a relay

If we connect the electromagnetic lock to a relay (normally open mode):

  • When relay is open, door is unlocked
  • When relay is closed, door is locked

By connecting Arduino to the relay, we can program for Arduino to control the electromagnetic lock. Learn more about relay in Arduino - Relay tutorial .

For installation, the armature plate is attached to the door/window (moving part), and the electromagnet is attached to the door frame (fixed part). The two components are in contact when the door is closed

Wiring Diagram

Arduino Electromagnetic Lock Wiring Diagram

Image is developed using Fritzing. Click to enlarge image

Arduino Code

The below code lock/unlock the door every 5 seconds

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-electromagnetic-lock */ // constants won't change const int RELAY_PIN = 3; // the Arduino pin, which connects to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 9 as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); // lock the door delay(5000); digitalWrite(RELAY_PIN, LOW); // unlock the door delay(5000); }

Quick Steps

  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino
  • Put the armature plate close to electromagnet.
  • See the attraction between armature plate and electromagnet.

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

Arduino - Button Controls Electromagnetic Lock

See Arduino - Button Controls Electromagnetic Lock tutorial

Electromagnetic Lock on Commercial Products

  • Fingerprint RFID Password Access Control Systems Force Electric EM Magnetic Lock

※ OUR MESSAGES