X
Home > Blog > STEM for Arduino > HOW to Make a Card-scanning Door-lock Control Device with Kidspico

HOW to Make a Card-scanning Door-lock Control Device with Kidspico

By r December 10th, 2024 432 views
It is an ideal for smart safe house that the Card-scanning Door-lock Control Device features both security and convenience.
In this experiment, we adopt RFID module and a servo to form a door-lock control device, and the RFID module works in real time. When the correct IC card is identified, the door opens; Otherwise, the door won’t open.

Flow

4101

Assembly

line1

Required Parts

41_00

line1

Step 1

41_01

line1

Step 2

41_02

line1

Step 3

41_03

line1

Step 4

41_04

line1

Step 5

41_05

line1

Step 6

41_06

line1

Step 7

41_07

line1

Step 8

41_08

line1

Step 9

41_09

line1

Step 10

41_10

Calibration is required after the servo is mounted. Connect the servo to io19 on the board and connect the board to computer via USB cable.

44_15

Open Servo_Calibration.py in Files and click 1407.

'''
 * Filename    : Servo_Calibration
 * Thonny      : Thonny 4.1.4
 * Auther      : http//www.keyestudio.com
'''
from machine import Pin, PWM
import time

servo = PWM(Pin(19))
servo.freq(50)  #T = 1/f = 20ms

def angle(x):
    return int((((x + 45) * 1.8 / 270) + 0.6 )/ 20 *65535)

while True:   
    servo.duty_u16(angle(0))

After calibration, disconnect the board to the computer and continue the assembly.

line1

Step 11

41_11

line1

Step 12

Note that the two gears mesh in order to drive smoothly.

41_12

line1

Step 13

41_13

line1

Step 14

41_14

line1

Completed

41_15

line1

Wiring Diagram

4102

Test Code

Open 4.1Card-scanning access control machine.py in Files and click 1407.

'''
 * Filename    : Smart Safe Home: Card-scanning access control machine
 * Thonny      : Thonny 4.1.4
 * Auther      : http//www.keyestudio.com
'''
from machine import Pin, PWM
from mfrc522_i2c import mfrc522
import time

servo = PWM(Pin(19))
servo.freq(50)  #T = 1/f = 20ms

# IIC configuration
addr = 0x28
scl = 5
sda = 4    
rc522 = mfrc522(scl, sda, addr)
rc522.PCD_Init()  # Initialization
rc522.ShowReaderDetails()  # Display details of the PCD-MFRC522 card reader

UID =[244, 160, 150, 219] # UID code of the IC card, modify it to yours.

def angle(x):
    return int((((x + 45) * 1.8 / 270) + 0.6 )/ 20 *65535)

servo.duty_u16(angle(0))  # Initalize servo

while True:
    if rc522.PICC_IsNewCardPresent():  # Scan for a new card
        if rc522.PICC_ReadCardSerial() == True:  # New card is found
            if rc522.uid.uidByte[0 : rc522.uid.size] == UID:
                servo.duty_u16(angle(120))  # open the door
                time.sleep(3)
                servo.duty_u16(angle(0))    # close the door
            else:
                servo.duty_u16(angle(0))    # close the door

Explanations

5top

Conceive:

First, set the rotation angles for opening and closing the door. Herein, we set angle to 120° to open the door, and 0° to close the door.

Then, when the RFID module receives a correct IC card code, it drives the servo to open the door for 3s. Otherwise, servo stays still.

line2

Code structure:

  1. Initialization.

    On the basis of Chapter 3.8 and 3.10, we add an initialization code servo.duty_u16(angle(0)) for servo to ensure the door is closed before running code.

    Define UID code. The code of each card is unique, so please replace the UID in code with yours.

  2. Loop.

    Determine whether the UID is correct. If yes, servo opens the door. If not, close the door.

5bottom

Test Result

4top

After uploading code, scan the correct IC card, and the door will open for 3s and then close.

4106

4bottom

FAQ
10top
Q: No response after uploading code?
A: Please check whether the IC card value is yours.
Q: After the sensor detects the card, the servo rotates yet the door does not open?
A: Power off immediately! Reassemble the building blocks according to the tutorial, noting that the servo needs to be calibrated before installation. Re-power on after the assembly is completed.
10bottom
HOW to Make a Motion Alarm with KidsIOT
Previous
HOW to Make a Motion Alarm with KidsIOT
Read More
How to Program Relay Module on Kidsuno
Next
How to Program Relay Module on Kidsuno
Read More
Message Us