ESP32 - 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.
|1||×||ESP-WROOM-32 Dev Module|
|1||×||Micro USB Cable|
|1||×||12V Power Adapter|
About Electromagnetic Lock
Electromagnetic Lock includes two components:
- One electromagnet with two pins
- One armature plate
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 ESP32 pin. We have to connect it to ESP32 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 ESP32 to the relay, we can program for ESP32 to control the electromagnetic lock. Learn more about relay in ESP32 - 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
Image is developed using Fritzing. Click to enlarge image
The below code lock/unlock the door every 5 seconds
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE
- Copy the above code and paste it to Arduino IDE
- Click Upload button on Arduino IDE to compile and upload code to ESP32 board
- Put the armature plate close to electromagnet.
- See the attraction between armature plate and electromagnet.
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.
Electromagnetic Lock on Commercial Products
※ NOTE THAT:
Note that this tutorial is incomplete. We will post on our Facebook Page when the tutorial is complete. Like it to get updated.