MisterBotBreak
Published

How to Use RFID with Serial Monitor

This project will show you how to use RFID with serial monitor.

BeginnerProtip1 hour2,242
How to Use RFID with Serial Monitor

Things used in this project

Hardware components

RFID reader (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

RFID.ino

Arduino
To use RFID with serial monitor
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN); 

// for a led 
int lock = 6;

int serrure = 3; 


char st[20];

void setup() 
{
  pinMode(lock, OUTPUT);
 
  pinMode (serrure, OUTPUT);
 
 
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init(); 

  Serial.println("Access test via RFID tag");
  Serial.println();
}

void loop() 
{
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  Serial.print("Tag :");
  String tag= "";
  byte caractere;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     tag.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  tag.toUpperCase();
  

  if (tag.substring(1) == "06 62 20 02") // le numero de tag est visible lorsqu on presente la carte ou le badge via le moniteur serie
  
 
  {
    digitalWrite(lock, HIGH);
    Serial.println("TAG checked - Access allow !");
    Serial.println();
    delay(3000);
   // if you want to set a led 
    digitalWrite(lock, LOW);
   
    digitalWrite(serrure, LOW); 
   
    }
 
.
 else if (tag.substring(1) == "D4 A9 42 DB") 
  {
    digitalWrite(lock, HIGH);
    Serial.println("TAG checked - Access allow !");
    Serial.println();
    delay(3000);
    digitalWrite(lock, LOW);
    
    digitalWrite(serrure, LOW);
    
    }
  
  else
  
  {
    
    Serial.println("Unknown tag - Access refused !!!");
    Serial.println();
  
    for (int i= 1; i<5 ; i++)
    {
     
      digitalWrite(lock, HIGH);
      delay(200);
      digitalWrite(lock, LOW);
      delay(200);
    }
  }
  delay(1000);
}

Credits

MisterBotBreak

MisterBotBreak

37 projects • 66 followers
I love electronic and I make explanatory project on how to control sensors.

Comments