Hardware components | ||||||
| × | 1 | ||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
| × | 1 |
I used for this project an RC522 RFID module.
The LCD display has an I2C module attached.
You can modify the code so it can display anything you want in what language you want. In the photo, I wrote in Romanian but how I said, you can modify the code.
What's inside. You can make it more organised.
If you have any questions, please let me know.
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
Servo myServo;
int *aux;
int card1[4];
int flag = 0;
int led = 13;
int cnt =0;
void setup() {
pinMode(led, OUTPUT);
lcd.init();
lcd.backlight();
SPI.begin();
mfrc522.PCD_Init();
lcd.print(" Apropie cardul");
lcd.setCursor(0,1);
lcd.print(" Pentru acces ");
myServo.attach(3);
myServo.write(0);
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
for (byte i = 0; i < mfrc522.uid.size; i++) {
aux[i]= mfrc522.uid.uidByte[i];
}
if(flag == 0)
{
lcd.clear();
lcd.print(" Card UID: ");
lcd.setCursor(0,1);
for (byte i = 0; i < mfrc522.uid.size; i++) {
card1[i] = aux[i];
lcd.print( card1[i], DEC);
lcd.print( " ");
flag =1;
}
delay(3000);
lcd.clear();
lcd.print(" Apropie cardul");
lcd.setCursor(0,1);
lcd.print(" Pentru acces ");
}
else{
for (byte i = 0; i < mfrc522.uid.size; i++) {
if(aux[i] == card1[i])
cnt++;
}
if(cnt == mfrc522.uid.size-1)
{
lcd.clear();
lcd.print(" ACCES ");
lcd.setCursor(0,1);
lcd.print(" PERMIS ");
delay(200);
myServo.write(180);
delay(5000);
myServo.write(0);
}
else
{
lcd.clear();
lcd.print(" ACCES ");
lcd.setCursor(0,1);
lcd.print(" INTERZIS ");
delay(2000);
}
}
lcd.clear();
lcd.print(" Apropie cardul");
lcd.setCursor(0,1);
lcd.print(" Pentru acces ");
cnt=0;
}
Comments