Skip to content

#20 Secured Entrance Project With PicoBricks

07 Nov 2023
#20 Secured Entrance Project With PicoBricks

Security systems include technologies that can control access at building and room entrances. Card entry systems, in which only authorized personnel can enter the operating rooms of hospitals, are one of the first examples that come to mind. In addition, many entrance areas are equipped with card and password entry technologies. These electronic systems not only prevent the entrance of unauthorized persons, but also ensure that entry and exit information is recorded. Password entry, card entry, fingerprint scanning, face scanning, retina scanning and voice recognition technologies are the authentication methods used in electronic entry systems.

Systems such as RFID and NFC are the basic forms of contactless payment technologies today. Although the contactless payment technology used with credit cards is technically different, the working logic is the same. The maximum distance between the reader and the card is one of the features that distinguishes the technologies from each other. When leaving the shopping stores, especially clothing stores, NFC tags on the products will beep if they are detected by the readers at the entrance. A kind of RFID technology is used in those systems.

In this project, we will prepare a card entry system on a model house. The electronic components we will use are MFRC522 RFID reader and 13.56 Mhz cards.

Details and Algorithm

Place the MFRC522 reader near the door of the model so that it is visible from the outside. Place the RGB LED and the buzzer on the wall where the door is visible from the outside. Picoboard can remain in the model. The entrance door of the model should be connected to the door of the servo, while the servo is set to 0 degrees, the door should be closed. You should determine the serial number of the RFID / NFC tag that will open the door, create the homeowner variable and assign the serial number to this variable.

Set the door to the closed position when the program starts. Make the buzzer beep when a card is shown to the RFID reader. If the serial number of the card being read matches the serial number in the homeowner variable, turn the RGB LED on green. Then let the door open. Make sure the door is closed 3 seconds after the door is opened. If the serial number of the card being read does not match the homeowner variable, turn the RGB LED on red and play a different tone from the buzzer.

Components

1X PicoBricks
1X Servo Motor
1X RC522-RFID Card
Jumper Cables
Easy Connection Cables

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

Construction Stages of the Project

We will make the project on the house model you used in the Smart Home project number 18.

Click for Smart Home project

Drill holes for the RGB LED, Buzzer and RC522 RFID reader on the house model.

Attach double-sided foam tape on the back of the RGB LED and Buzzer and attach it on the box. Place the RC522 inside the model as in the image.

Attach the servo motor to the inside of the model with double-sided tape as a hinge in the upper left corner of the door. Attach the servo head to the door with hot glue or liquid glue.

Finally, place the Pico board and the 2-key battery box inside the model house and complete the cable connections. After making the final checks of your project, it is ready to work.

MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button.

Microblocks Run Tab

MicroPython Codes of the PicoBricks


from machine import Pin, PWM
from picobricks import MFRC522, WS2812
from time import sleep

reader = MFRC522(spi_id=0,sck=18,miso=16,mosi=19,cs=17,rst=0)

servo = PWM(Pin(21))

buzzer = PWM(Pin(20, Pin.OUT))
buzzer.freq(1000)

ws2812 = WS2812(6,brightness=1)

servo.duty_u16(1250) #servo set 0 angle 8200 for 180.
servo.freq(50)

def activated():
        print("Card ID: "+ str(card)+" PASS: Activated")
        ws2812.pixels_fill((0, 255, 0))
        ws2812.pixels_show()
        
        buzzer.freq(2000)
        
        buzzer.duty_u16(2000)
        sleep(0.05)
        buzzer.duty_u16(0)
        sleep(0.05)
        
        buzzer.duty_u16(2000)
        sleep(0.05)
        buzzer.duty_u16(0)
        sleep(0.05)
        
        servo.duty_u16(4500)
        servo.freq(50)

        sleep(3)
        servo.duty_u16(2150)
        servo.freq(50)
        ws2812.pixels_fill((255, 0, 0))
        ws2812.pixels_show()
        
def unknown_card():
    print("Card ID: "+ str(card)+" UNKNOWN CARD! ")
    buzzer.freq(1000)
    buzzer.duty_u16(2000)
    sleep(0.1)
    buzzer.duty_u16(0)
    sleep(0.1)
    
id_list=[562956160,2309304334,2903577093] # add your card number in list
    
while True:
    reader.init()
    (stat, tag_type) = reader.request(reader.REQIDL)
    ws2812.pixels_fill((255, 0, 0))
    ws2812.pixels_show()  
    if stat == reader.OK:
        (stat, uid) = reader.SelectTagSN()
        if stat == reader.OK:
            card = int.from_bytes(bytes(uid),"little",False)
                            
            if card in id_list:
                activated()                    
            else:
                unknown_card()

Arduino C Codes of the PicoBricks

The code to be run to learn the Card ID:

 

#include <SPI.h>
#include <MFRC522.h>
//define libraries

int RST_PIN = 26;
int SS_PIN = 17;
//define pins

MFRC522 rfid(SS_PIN, RST_PIN);

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
}

void loop() {

  if (!rfid.PICC_IsNewCardPresent())
    return;
  if (!rfid.PICC_ReadCardSerial())
    return;
    rfid.uid.uidByte[0] ;
    rfid.uid.uidByte[1] ;
    rfid.uid.uidByte[2] ;
    rfid.uid.uidByte[3] ; 
    printid();
  rfid.PICC_HaltA();
//Reading your ID.
}
void printid() 
{
  Serial.print("Your ID: ");
  for (int x = 0; x < 4; x++) {
    Serial.print(rfid.uid.uidByte[x]);
    Serial.print(" ");
  }
  Serial.println("");
}

Project code:


#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <Adafruit_NeoPixel.h>
//Define libraries.


#define RST_PIN    26
#define SS_PIN     17
#define servoPin   22
#define PIN        6 
#define NUMPIXELS  1
#define buzzer     20
//define pins of servo,buzzer,neopixel and rfid.

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Servo motor;
MFRC522 rfid(SS_PIN, RST_PIN);

byte ID[4] = {"Write your own ID."};

void setup() { 
  pixels.begin();
  motor.attach(servoPin);
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  pinMode(buzzer, OUTPUT);
  
}
 
void loop()
{
  pixels.clear();
  
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if ( ! rfid.PICC_ReadCardSerial())
    return;

  if 
  (
    rfid.uid.uidByte[0] == ID[0] &&
    rfid.uid.uidByte[1] == ID[1] &&
    rfid.uid.uidByte[2] == ID[2] &&
    rfid.uid.uidByte[3] == ID[3] ) 
  {
        Serial.println("Door Opened.");
        printid();
        tone(buzzer,523);
        delay(200);
        noTone(buzzer);
        delay(100);
        tone(buzzer,523);
        delay(200);
        noTone(buzzer);
        pixels.setPixelColor(0, pixels.Color(0, 250, 0));
        delay(200);
        pixels.show();
        pixels.setPixelColor(0, pixels.Color(0, 0, 0));
        delay(200);
        pixels.show();
        motor.write(180);
        delay(2000);
        motor.write(0);
        delay(1000);
     //RGB LED turns green and the door opens thanks to the servo motor if the correct card is read to the sensor.
    }
    else
    {
      Serial.println("Unknown Card.");
      printid();
      tone(buzzer,494);
      delay(200);
      noTone(buzzer);
      delay(100);
      tone(buzzer,494);
      delay(200);
      noTone(buzzer);
      pixels.setPixelColor(0, pixels.Color(250, 0, 0));
      delay(100);
      pixels.show();
      pixels.setPixelColor(0, pixels.Color(0, 0, 0));
      delay(100);
      pixels.show();
      //RGB LED turns red and the door does not open if the wrong card is read to the sensor
    }
  rfid.PICC_HaltA();
}
void printid()
{
  Serial.print("ID Number: ");
  for(int x = 0; x < 4; x++){
    Serial.print(rfid.uid.uidByte[x]);
    Serial.print(" ");
  }
  Serial.println("");
}

GitHub Project Page
Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Back In Stock Notification

Compare

Product SKURatingDescription Collection Availability Product Type Other Details
this is just a warning
Login
Shopping Cart
0 items
Same Day Shipping No Extra Costs
Easy Returns Guarantee Return with Ease
Secure Checkout Secure Payment