Rad Silviu
Published

A box with RFID and I2C LCD

A box that opens with an RFID tag and servomotor.

IntermediateFull instructions provided1 hour10,393
A box with RFID and I2C LCD

Things used in this project

Story

Read more

Schematics

A box with RFID an I2C LCD

If you are confused, let me know.

Code

A box with RFID an I2C LCD

C/C++
you can modify the code to show whatever you want.
#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;
}

Credits

Rad Silviu
12 projects • 8 followers

Comments