Arduino - Electromagnetic Lock
Arduino - 电磁锁
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.
电磁锁(EM锁)广泛用于锁门。它通常与开关、指纹读取器、RFID/NFC 读取器、键盘或 PC/mobille 上的应用程序一起使用,以控制对门、建筑大门的访问…电磁锁也称为磁力锁或磁锁。
An alternative to the Electromagnetic Lock is Solenoid Lock. You can learn more in Arduino - Solenoid Lock tutorial
电磁锁的替代品是电磁锁。您可以在 Arduino - 电磁锁教程中了解更多信息
About Electromagnetic Lock 关于电磁锁
Pinout 引脚排列
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 Arduino pin. We have to connect it to Arduino pin via a relay
电磁锁通常使用12V、24V或48V电源。因此,我们无法将电磁锁直接连接到Arduino引脚。我们必须通过继电器将其连接到Arduino引脚
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.
通过将Arduino连接到继电器,我们可以对Arduino进行编程来控制电磁锁。在Arduino中了解有关继电器的更多信息 - 中继教程。
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 接线图
This image is created using Fritzing. Click to enlarge image
此图像是使用 Fritzing 创建的。点击放大图片
Arduino Code Arduino代码
The below code lock/unlock the door every 5 seconds
以下代码每 5 秒锁定/解锁一次门
/** 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 = A5; // 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 A5 as an output.pinMode(RELAY_PIN, OUTPUT);
}// the loop function runs over and over again forever
void loop() {digitalWrite(RELAY_PIN, HIGH); // lock the doordelay(5000);digitalWrite(RELAY_PIN, LOW); // unlock the doordelay(5000);
}
Quick Steps 快速步骤
- Copy the above code and open with Arduino IDE
复制上面的代码并使用Arduino IDE打开 - Click Upload button on Arduino IDE to upload code to Arduino
单击Arduino IDE上的“上传”按钮,将代码上传到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.
我们正在考虑制作视频教程。如果您认为视频教程是必不可少的,请订阅我们的 YouTube 频道,为我们制作视频提供动力。
Arduino - Button Controls Electromagnetic Lock Arduino - 按钮控制电磁锁
See Arduino - Button Controls Electromagnetic Lock tutorial
请参阅Arduino - 按钮控制电磁锁教程