keyestudio
Share your creative ideas with us here
By ran | 18 September 2024 | 0 Comments

HOW to Make an Intelligent Entrance Guard System with ESP32

Description

In this project, we use the RFID522 card swiping module and the servo to set up an intelligent access control system. The principle is very simple.We use RFID522 swipe card module, an IC card or key card to unlock.

Required Components

img

img

img

img

ESP32 Board*1

ESP32 Expansion Board*1

Key*1

IC Card*1

img

img

img

img

Keyestudio RFID Module*1

Servo*1

4P Dupont Wire*1

Micro USB Cable*1

Connection Diagram

Add Library

Open “Thonny”, click “This computer” → “D:” → “2. ESP32_code_MicroPython” → “lesson 59. Intelligent access control”. Select “mfrc522_config.py”, “mfrc522_i2c.py” and “soft_iic.py”, right-click and select “Upload to /”, waiting for the “mfrc522_config.py”, “mfrc522_i2c.py” and “soft_iic.py” to be uploaded to the ESP32.

Test Code

Note: Different RFID-RC522 modules, ID cards and keys may different uid1 values and uid2 values.

The uID1 and UID2 values of the white card and key chain read by your RRFID RC522 module can be replaced by the corresponding values in the program code. If not, click “Run current script” to run the code may cause your own white card and key chain to fail to control the servo.

For example: You can replace the UID1 and UID2 values In the program code  with your own white card and key chain values.

from machine import Pin, PWM
import time
from mfrc522_i2c import mfrc522

pwm = PWM(Pin(15))
pwm.freq(50)

'''
Duty cycle corresponding to the Angle
Duty cycle corresponding to the Angle
0°----2.5%----25
45°----5%----51.2
90°----7.5%----77
135°----10%----102.4
180°----12.5%----128
'''
angle_0 = 25
angle_90 = 77
angle_180 = 128

#i2c config
addr = 0x28
scl = 22
sda = 21
    
rc522 = mfrc522(scl, sda, addr)
rc522.PCD_Init()
rc522.ShowReaderDetails()            # Show details of PCD - MFRC522 Card Reader details

uid1 = [237, 247, 148, 90]
uid2 = [76, 9, 107, 110]

pwm.duty(angle_180)
time.sleep(1)

while True:
    if rc522.PICC_IsNewCardPresent():
        print("Is new card present!")
        if rc522.PICC_ReadCardSerial() == True:
            print("Card UID:", end=' ')
            print(rc522.uid.uidByte[0 : rc522.uid.size])
            if rc522.uid.uidByte[0 : rc522.uid.size] == uid1 or rc522.uid.uidByte[0 : rc522.uid.size] == uid2:
                pwm.duty(angle_0)
            else :
                pwm.duty(angle_180)
            time.sleep(500)from machine import Pin, PWM
import time
from mfrc522_i2c import mfrc522

pwm = PWM(Pin(15))
pwm.freq(50)

'''
Duty cycle corresponding to the Angle
Duty cycle corresponding to the Angle
0°----2.5%----25
45°----5%----51.2
90°----7.5%----77
135°----10%----102.4
180°----12.5%----128
'''
angle_0 = 25
angle_90 = 77
angle_180 = 128

#i2c config
addr = 0x28
scl = 22
sda = 21
    
rc522 = mfrc522(scl, sda, addr)
rc522.PCD_Init()
rc522.ShowReaderDetails()            # Show details of PCD - MFRC522 Card Reader details

uid1 = [237, 247, 148, 90]
uid2 = [76, 9, 107, 110]

pwm.duty(angle_180)
time.sleep(1)

while True:
    if rc522.PICC_IsNewCardPresent():
        print("Is new card present!")
        if rc522.PICC_ReadCardSerial() == True:
            print("Card UID:", end=' ')
            print(rc522.uid.uidByte[0 : rc522.uid.size])
            if rc522.uid.uidByte[0 : rc522.uid.size] == uid1 or rc522.uid.uidByte[0 : rc522.uid.size] == uid2:
                pwm.duty(angle_0)
            else :
                pwm.duty(angle_180)
            time.sleep(500)

Code Explanation

In the previous experiment, our card swipe module has tested the information of IC card and key. Then we use this corresponding information to control the door.

Test Result

Connect the wires according to the experimental wiring diagram and power on. Click “Run current script”, the code starts executing. When we use the IC card or blue key to swipe the card, the shell displays the card and the key information , at the same time, the servo rotates to the corresponding angle to simulate opening the door.

Press “Ctrl+C”or click “Stop/Restart backend”to exit the program.

 

Leave a Reply

Your email address will not be published.Required fields are marked. *
Name
E-mail
Content
Verification code