MODULE 5
Microcontroller programming and control access III

For this project,we interfaced raspberry pico,RFID,LED and OLED for a simple access and display.But also a RGB can be used instead of two LED's

The OLED was to show the access granted or denied while the green for granted and red for denied.


INTERFACING RASPBERRY PICO RELAY

A relay is acts as a switch when intergrated with other components.Relay module that i used(12v 5v)uses an electric current to open or close the contacts of a switch. This is usually done using the help of a coil that attracts the contacts of a switch and pulls them together when activated, and a spring pushes them apart when the coil is not energized.

relay module from machine import Pin
from time import sleep
relay_pin = 10
# set relay PIN object
relay = Pin(relay_pin, Pin.OUT)
# Relay configured for NO (Normally Open)
def relay_on():
relay.value(1)
def relay_off():
relay.value(0)
# test the relay
relay_on()
sleep(5)
relay_off()

video width="320" height="240" controls> Your browser does not support the video tag.

For control access project where i could use Raspberry pico and ESPwroom32 to store data.Relay and solenoid lock for door access started with raspberry pico.

An adddition component was used which is the power supply unit to power boyh relay and solenoid since it uses high voltage power to operate and also a passive buzzer was used alarm when the wrong card was used.

rpi pico,buzzer and rfid

Intergrated RFID,buzzer,RGB ,relay and solenoid for a complete door access control.In this case for simpler connection i used RGB instead of a two LED's.

raspberrypico door access control
from machine import Pin
from mfrc522 import MFRC522
import utime
reader = MFRC522(spi_id=0,sck=6,miso=4,mosi=7,cs=5,rst=22)
red = Pin(0, Pin.OUT)
green = Pin(1, Pin.OUT)
blue = Pin(2, Pin.OUT)
print("Bring RFID TAG Closer...")
print("")
while True:
reader.init()
(stat, tag_type) = reader.request(reader.REQIDL)
if stat == reader.OK:
(stat, uid) = reader.SelectTagSN()
if stat == reader.OK:
card = int.from_bytes(bytes(uid),"little",False)
if card == 111583217:
print("Card ID: "+ str(card)+" PASS: Green Light Activated")
red.value(0)
green.value(1)
blue.value(0
) elif card == 495638547:
print("Card ID: "+ str(card)+" PASS: Blue Light Activated")
red.value(0)
green.value(0)
blue.value(1)
else:
print("Card ID: "+ str(card)+" UNKNOWN CARD! Red Light Activated")
red.value(1)
green.value(0)
blue.value(0)

Using ESPwroom32 for access control door lock.

For this case will be using Arduino IDE to write a code.Certain libraries are needed to be installed to be compactible(MFRC522).

* This ESP32 code is created by esp32io.com
* * This ESP32 code is released in the public domain
* * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-rfid-nfc-door-lock-system
*/ #include
#include
#define SS_PIN 5 // ESP32 pin GPIO5
#define RST_PIN 0 // ESP32 pin GPIO27
#define RELAY_PIN 27 // ESP32 pin GPIO32 connects to relay
MFRC522 rfid(SS_PIN, RST_PIN);
#define PIN_RED 13 // GPIO23
#define PIN_GREEN 14 // GPIO22
#define PIN_BLUE 12 // GPIO21
#define BUZZER_PIN 26
//ss 5 sda 21 rst 0 mosi 23 miso 19
byte adminUID[4] = {0x60, 0x79, 0xC5, 0x14};
byte visitorUID[4] = {0x59, 0x47, 0xA3, 0x18};
void setup() {
Serial.begin(115200);
SPI.begin(); // init SPI bus
rfid.PCD_Init(); // init MFRC522
pinMode(RELAY_PIN, OUTPUT); // initialize pin as an output.
SPI.begin(); // Init SPI bus
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
Serial.println("Tap an RFID/NFC tag on the RFID-RC522 reader");
}
void loop() {
rfid.PCD_Init()
if (rfid.PICC_IsNewCardPresent()) { // new tag is available
if (rfid.PICC_ReadCardSerial()) { // NUID has been readed
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
if (rfid.uid.uidByte[0] == adminUID[0] &&
rfid.uid.uidByte[1] == adminUID[1] &&
rfid.uid.uidByte[2] == adminUID[2] &&
rfid.uid.uidByte[3] == adminUID[3] ) {
Serial.println("Access is granted to admin");
//setColor(255,0,0);//green
digitalWrite(RELAY_PIN, HIGH);
digitalWrite(PIN_GREEN, HIGH);
digitalWrite(PIN_RED, LOW);
digitalWrite(PIN_BLUE, LOW);
delay(1000);
digitalWrite(PIN_GREEN, LOW);
digitalWrite(RELAY_PIN, LOW);
}
else if (rfid.uid.uidByte[0] == visitorUID[0] &&
rfid.uid.uidByte[1] == visitorUID[1] &&
rfid.uid.uidByte[2] == visitorUID[2] &&
rfid.uid.uidByte[3] == visitorUID[3] ) {
Serial.println("Access is granted to visitor");
digitalWrite(RELAY_PIN, HIGH);
digitalWrite(PIN_GREEN, HIGH);
digitalWrite(PIN_RED, LOW);
digitalWrite(PIN_BLUE, LOW);
delay(1000);
digitalWrite(PIN_GREEN, LOW);
digitalWrite(RELAY_PIN, LOW);
}
else
{
Serial.print("Access denied, UID:");
digitalWrite(BUZZER_PIN,HIGH);
digitalWrite(PIN_GREEN, LOW);
digitalWrite(PIN_RED, HIGH);
digitalWrite(PIN_BLUE, LOW);
delay(1000);
digitalWrite(PIN_RED, LOW);
digitalWrite(BUZZER_PIN,LOW);
for (int i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(rfid.uid.uidByte[i], HEX);
}
Serial.println();
}
rfid.PICC_HaltA(); // halt PICC
rfid.PCD_StopCrypto1(); // stop encryption on PCD
}
}
}