mdraber
Created August 31, 2022 © GPL3+

How to use RYRR10S RFID module from Reyax with Arduino

Open the magnetic lock using authorised proximity card!

IntermediateFull instructions provided136
How to use RYRR10S RFID module from Reyax with Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
1028x64 SPI OLED display
×1
REYAX RYRR10S RFID module
×1
KY-019 5V Relay
×1
Magnetic Lock 12V
×1

Story

Read more

Schematics

Connectivity

Connectivity diagram shows RFID module connected to digital pins D2 and D3 (with the use of Software Serial Library) .
In the second sketch attached where I open magnetic lock I was not using Serial Monitor anymore so I connected RFID module directly to the serial ports of Arduino RX and TX (remember to cross the connection , so RX of RFID goes to TX of Arduino and vice versa)

Code

Reading tags using RYRR10S RFID module and displaying TAG ID in Serial Monitor

Arduino
#include <SoftwareSerial.h>
SoftwareSerial NFCserial(2, 3); //RX, TX

uint8_t received_buf_pos=0;
uint8_t response_byte;
uint8_t data_len;
boolean received_complete=false;
String tag_id = "";
char Byte_In_Hex[3];


uint8_t echo_command[1] = {0x55};

uint8_t initialise_cmd_iso14443_1[6] =  {0x09, 0x04, 0x68, 0x01, 0x07, 0x10};
uint8_t initialise_cmd_iso14443_2[6] =  {0x09, 0x04, 0x68, 0x01, 0x07, 0x00};
uint8_t initialise_cmd_iso14443_3[6] =  {0x02, 0x04, 0x02, 0x00, 0x02, 0x80};
uint8_t initialise_cmd_iso14443_4[6] =  {0x09, 0x04, 0x3A, 0x00, 0x58, 0x04};
uint8_t initialise_cmd_iso14443_5[6] =  {0x09, 0x04, 0x68, 0x01, 0x01, 0xD3};

uint8_t detect_cmd_iso14443_1[4] =  {0x04, 0x02, 0x26, 0x07};
uint8_t detect_cmd_iso14443_2[5] =  {0x04, 0x03, 0x93, 0x20, 0x08};


void setup() {  
  Serial.begin(9600);
  NFCserial.begin(57600);
  Serial.println("Echo command: "); 
  NFCserial.write(echo_command, 1);  
  delay(1000); show_serial_data();
  delay(1000);
  Serial.println("Initialise commands: ");  
  NFCserial.write(initialise_cmd_iso14443_1, 6);
  delay(1000); show_serial_data(); 
  NFCserial.write(initialise_cmd_iso14443_2, 6);
  delay(1000); show_serial_data();
  NFCserial.write(initialise_cmd_iso14443_3, 6);
  delay(1000); show_serial_data();
  NFCserial.write(initialise_cmd_iso14443_4, 6);
  delay(1000); show_serial_data();
  NFCserial.write(initialise_cmd_iso14443_5, 6); 
  delay(1000); show_serial_data();
}

void show_serial_data(){
  while(NFCserial.available()!=0)
  Serial.print(NFCserial.read(), HEX);
  Serial.println("");
}

void Read_Tag(){
  uint8_t received_char;
  while(NFCserial.available()!=0){
    received_char = char (NFCserial.read());
    
    if(received_buf_pos==0)response_byte = received_char; 
    else if (received_buf_pos==1)data_len = received_char; 
    else if (received_buf_pos>=2 and received_buf_pos<6) {
      sprintf(Byte_In_Hex,"%x", received_char);
      tag_id += Byte_In_Hex; //adding to a string
      }
    received_buf_pos++;
    if(received_buf_pos >= data_len){
      received_complete = true;
      }
    }
}

void loop() {  
  received_buf_pos = 0;
  received_complete = false;
  tag_id="";
  response_byte=0;
  
  Serial.println("Searching new card...");
  NFCserial.write(detect_cmd_iso14443_1, 4);
  delay(800);
  Serial.println("Response:"); show_serial_data();
  
  NFCserial.write(detect_cmd_iso14443_2, 5);
  delay(300);

  if(NFCserial.available()) {
    Read_Tag();
  }

  if(response_byte == 0x80){
    Serial.print("Tag detected. Tag id: ");
    Serial.println(tag_id);    
    Serial.println("");
    delay(2000); 
  }    
  else{
    Serial.println("No tag detected.");
    Serial.println("");
    delay(2000);
  }
}

Reading tag ID and if authorised opening magnetick lock

Arduino
The sketch reads the tag. Compares it against a list of know tags.
The TAG id is displayed on the OLED display. Also the access data for the read tag ID is displayed. If the tag access is granted a signal is sent to open magnetic lock
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


// Oled display size
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

struct tag{
   String Card;
   int Access;
};
tag Tags[4] = {{"1da74473",0},     
               {"127d2a19",1},
               {"8119f02e",0},
               {"53b9f72e",1}};

int Tag_Status;

// 'RFID', 128x48px
const unsigned char epd_bitmap_RFID [] PROGMEM = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xfe, 0x7f, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfe, 0x7f, 0xc0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfe, 0x3f, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xe2, 0x3f, 0x9f, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xe3, 0x1f, 0x9f, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0x33, 0x1f, 0x9f, 0xff, 0xff, 0xf2, 0x1f, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xfe, 0x31, 0x1f, 0x9f, 0xff, 0xff, 0xf3, 0x8f, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0x11, 0x9f, 0x9f, 0xff, 0xff, 0xf3, 0xc7, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf9, 0x11, 0x9f, 0x9f, 0xff, 0xff, 0xf3, 0xe3, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf1, 0x19, 0x9f, 0x9f, 0xff, 0xff, 0xf3, 0xf1, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf1, 0x19, 0x9f, 0x9f, 0xff, 0x87, 0xf3, 0xf8, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf1, 0x19, 0x9f, 0x9f, 0xff, 0x01, 0xf3, 0xfe, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf1, 0x19, 0x9f, 0x9f, 0xff, 0x38, 0x73, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf9, 0x11, 0x9f, 0x9f, 0xff, 0x3e, 0x03, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0x11, 0x9f, 0x9f, 0xff, 0x3f, 0x83, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xfe, 0x31, 0x1f, 0x9f, 0xff, 0x9f, 0xe7, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0x73, 0x1f, 0x9f, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xe3, 0x1f, 0x9f, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xe2, 0x3f, 0x9f, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfe, 0x3f, 0x8f, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfe, 0x7f, 0xc0, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xfe, 0x7f, 0xe0, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xfe, 0x7c, 0x9c, 0x07, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xfc, 0xfc, 0x1c, 0xc0, 0x00, 0x3f, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0xff, 0x00, 0x08, 0x00, 0x3f, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xe1, 0x1f, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x7e, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
// 'notok', 41x41px
const unsigned char epd_bitmap_notok [] PROGMEM = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0x00, 0x7f, 0xff, 0x80, 0xff, 0xf8, 0x00, 0x0f, 
  0xff, 0x80, 0xff, 0xe0, 0x00, 0x03, 0xff, 0x80, 0xff, 0x80, 0x7f, 0x00, 0xff, 0x80, 0xff, 0x03, 
  0xff, 0xe0, 0x7f, 0x80, 0xfe, 0x0f, 0xff, 0xf8, 0x3f, 0x80, 0xfc, 0x1f, 0xff, 0xfc, 0x1f, 0x80, 
  0xf8, 0x7f, 0xff, 0xff, 0x0f, 0x80, 0xf0, 0xff, 0xff, 0xff, 0x87, 0x80, 0xe1, 0xcf, 0xff, 0xfb, 
  0x87, 0x80, 0xe1, 0xc7, 0xff, 0xe1, 0xc3, 0x80, 0xc3, 0xc3, 0xff, 0xc3, 0xe3, 0x80, 0xc3, 0xe0, 
  0xff, 0x83, 0xe1, 0x80, 0xc7, 0xf0, 0x7f, 0x07, 0xf1, 0x80, 0x87, 0xf8, 0x3e, 0x0f, 0xf0, 0x80, 
  0x8f, 0xfc, 0x1c, 0x1f, 0xf8, 0x80, 0x8f, 0xfe, 0x08, 0x3f, 0xf8, 0x80, 0x8f, 0xff, 0x00, 0x7f, 
  0xf8, 0x80, 0x8f, 0xff, 0x80, 0xff, 0xf8, 0x80, 0x8f, 0xff, 0x81, 0xff, 0xf8, 0x80, 0x8f, 0xff, 
  0x80, 0xff, 0xf8, 0x80, 0x8f, 0xff, 0x00, 0x7f, 0xf8, 0x80, 0x8f, 0xfe, 0x00, 0x3f, 0xf8, 0x80, 
  0x8f, 0xfc, 0x1c, 0x1f, 0xf8, 0x80, 0x87, 0xf8, 0x3e, 0x0f, 0xf0, 0x80, 0xc7, 0xf0, 0x7f, 0x0f, 
  0xf1, 0x80, 0xc7, 0xe0, 0xff, 0x83, 0xe1, 0x80, 0xc3, 0xc1, 0xff, 0xc3, 0xe3, 0x80, 0xe1, 0xc3, 
  0xff, 0xe1, 0xc3, 0x80, 0xe1, 0xc7, 0xff, 0xf1, 0xc7, 0x80, 0xf0, 0xff, 0xff, 0xff, 0x87, 0x80, 
  0xf8, 0x7f, 0xff, 0xff, 0x0f, 0x80, 0xfc, 0x3f, 0xff, 0xfe, 0x1f, 0x80, 0xfc, 0x0f, 0xff, 0xf8, 
  0x3f, 0x80, 0xff, 0x07, 0xff, 0xe0, 0x7f, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0xc0, 
  0x00, 0x01, 0xff, 0x80, 0xff, 0xf0, 0x00, 0x07, 0xff, 0x80, 0xff, 0xfc, 0x00, 0x3f, 0xff, 0x80, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x80
};
// 'ok', 41x41px
const unsigned char epd_bitmap_ok [] PROGMEM = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xfc, 0x00, 0x1f, 0xff, 0x80, 0xff, 0xf0, 0x00, 0x07, 
  0xff, 0x80, 0xff, 0xc0, 0x1c, 0x01, 0xff, 0x80, 0xff, 0x03, 0xff, 0xc0, 0xff, 0x80, 0xfe, 0x0f, 
  0xff, 0xf0, 0x7f, 0x80, 0xfc, 0x3f, 0xff, 0xfc, 0x3f, 0x80, 0xf8, 0x7f, 0xff, 0xfe, 0x1f, 0x80, 
  0xf8, 0xff, 0xff, 0xff, 0x0f, 0x80, 0xf1, 0xff, 0xff, 0xff, 0x87, 0x80, 0xe1, 0xff, 0xff, 0xff, 
  0xc7, 0x80, 0xe3, 0xff, 0xff, 0xf9, 0xe3, 0x80, 0xc7, 0xff, 0xff, 0xf0, 0xe3, 0x80, 0xc7, 0xff, 
  0xff, 0xe1, 0xf1, 0x80, 0xc7, 0xff, 0xff, 0xc3, 0xf1, 0x80, 0x8f, 0xff, 0xff, 0x87, 0xf1, 0x80, 
  0x8f, 0xff, 0xff, 0x0f, 0xf1, 0x80, 0x8f, 0xff, 0xfe, 0x1f, 0xf9, 0x80, 0x8f, 0xff, 0xfc, 0x3f, 
  0xf8, 0x80, 0x8f, 0xff, 0xf8, 0x7f, 0xf8, 0x80, 0x8f, 0xff, 0xf0, 0xff, 0xf8, 0x80, 0x8f, 0x9f, 
  0xe1, 0xff, 0xf9, 0x80, 0x8f, 0x87, 0xc3, 0xff, 0xf1, 0x80, 0x8f, 0xc3, 0x87, 0xff, 0xf1, 0x80, 
  0x8f, 0xe0, 0x0f, 0xff, 0xf1, 0x80, 0xc7, 0xf0, 0x1f, 0xff, 0xf1, 0x80, 0xc7, 0xf8, 0x3f, 0xff, 
  0xe3, 0x80, 0xe3, 0xfc, 0x7f, 0xff, 0xe3, 0x80, 0xe3, 0xff, 0xff, 0xff, 0xc7, 0x80, 0xf1, 0xff, 
  0xff, 0xff, 0x87, 0x80, 0xf0, 0xff, 0xff, 0xff, 0x8f, 0x80, 0xf8, 0x7f, 0xff, 0xff, 0x1f, 0x80, 
  0xfc, 0x3f, 0xff, 0xfe, 0x1f, 0x80, 0xfe, 0x1f, 0xff, 0xf8, 0x3f, 0x80, 0xff, 0x07, 0xff, 0xe0, 
  0xff, 0x80, 0xff, 0x80, 0x7f, 0x81, 0xff, 0x80, 0xff, 0xe0, 0x00, 0x07, 0xff, 0x80, 0xff, 0xf8, 
  0x00, 0x1f, 0xff, 0x80, 0xff, 0xff, 0x81, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x80
};

uint8_t received_buf_pos=0;
uint8_t response_byte;
uint8_t data_len;
boolean received_complete=false;
String tag_id = "";
char Byte_In_Hex[3];


uint8_t echo_command[1] = {0x55};

uint8_t initialise_cmd_iso14443_1[6] =  {0x09, 0x04, 0x68, 0x01, 0x07, 0x10};
uint8_t initialise_cmd_iso14443_2[6] =  {0x09, 0x04, 0x68, 0x01, 0x07, 0x00};
uint8_t initialise_cmd_iso14443_3[6] =  {0x02, 0x04, 0x02, 0x00, 0x02, 0x80};
uint8_t initialise_cmd_iso14443_4[6] =  {0x09, 0x04, 0x3A, 0x00, 0x58, 0x04};
uint8_t initialise_cmd_iso14443_5[6] =  {0x09, 0x04, 0x68, 0x01, 0x01, 0xD3};

uint8_t detect_cmd_iso14443_1[4] =  {0x04, 0x02, 0x26, 0x07};
uint8_t detect_cmd_iso14443_2[5] =  {0x04, 0x03, 0x93, 0x20, 0x08};


void setup() {  
  Serial.begin(57600);
  pinMode(13,OUTPUT);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    ///Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  //display.display();
  //delay(2000); // Pause for 2 seconds
  display.clearDisplay();
  display.setTextSize(1);           
  display.fillRect(0, 0, 128, 15, SSD1306_INVERSE);
  display.setTextColor(SSD1306_BLACK);  
  display.setCursor(4,4); 
  display.println("Initialising ... ");
  display.display();
  delay(2000);

  
  Serial.write(echo_command, 1);  
  delay(1000); show_serial_data();  
  Serial.write(initialise_cmd_iso14443_1, 6);
  delay(500); show_serial_data(); 
  Serial.write(initialise_cmd_iso14443_2, 6);
  delay(500); show_serial_data();
  Serial.write(initialise_cmd_iso14443_3, 6);
  delay(500); show_serial_data();
  Serial.write(initialise_cmd_iso14443_4, 6);
  delay(500); show_serial_data();
  Serial.write(initialise_cmd_iso14443_5, 6); 
  delay(500); show_serial_data();
}

void show_serial_data(){
  while(Serial.available()!=0) Serial.read();
}

void Read_Tag(){
  uint8_t received_char;
  while(Serial.available()!=0){
    received_char = char (Serial.read());
    
    if(received_buf_pos==0)response_byte = received_char; 
    else if (received_buf_pos==1)data_len = received_char; 
    else if (received_buf_pos>=2 and received_buf_pos<6) {
      sprintf(Byte_In_Hex,"%x", received_char);
      tag_id += Byte_In_Hex; //adding to a string
      }
    received_buf_pos++;
    if(received_buf_pos >= data_len){
      received_complete = true;
      }
    }
}

void Searching_Tag_Screen(){
  display.fillRect(0, 0, 128, 15, SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(4,4); 
  display.println("Scan Card...");
  display.fillRect(0, 15, 128, 49, SSD1306_BLACK);
  display.drawBitmap(0,16,epd_bitmap_RFID,128,48,1);
  display.display();
}

void Display_Tag(String Tag){

  display.fillRect(0, 0, 128, 15, SSD1306_WHITE);
  display.setCursor(1,8);
  display.println("TAG: ");
  display.setTextSize(2);
  display.setCursor(30,1); 
  //Tag.toUpperCase();
  display.println(Tag);
  display.display();
}


void loop() {  
  received_buf_pos = 0;
  received_complete = false;
  tag_id="";
  response_byte=0;
  Searching_Tag_Screen();
  
 Serial.write(detect_cmd_iso14443_1, 4);
  delay(800);
  show_serial_data();
  
  Serial.write(detect_cmd_iso14443_2, 5);
  delay(300);

  if(Serial.available()) {
    Read_Tag();
  }

  if(response_byte == 0x80){
    Display_Tag(tag_id);
    display.fillRect(0, 15, 128, 49, SSD1306_WHITE);
    display.fillRect(2, 20, 41, 41, SSD1306_BLACK);
    display.setTextSize(2);
    Tag_Status=2;
    for (int i=0;i<sizeof(Tags)/sizeof(tag); i++){
      if(Tags[i].Card==tag_id) Tag_Status=Tags[i].Access;
    }
    if(Tag_Status==1){
      digitalWrite(13,HIGH);
      display.drawBitmap(2,20,epd_bitmap_ok,41,41,1);
      display.setCursor(43,33); 
      display.println("GRANTED");                                                                                                                                                                                                                                                            
      display.display();
    }
    if (Tag_Status==0){
      display.drawBitmap(2,20,epd_bitmap_notok,41,41,1);
      display.setCursor(43,33); 
      display.println(" DENIED");
      display.display();
    }
    if (Tag_Status==2){
        display.fillRect(0, 15, 128, 49, SSD1306_WHITE);
        display.setCursor(30,33); 
        display.println("UNKNOWN");
      display.display();
    }          
   delay(4000);
   digitalWrite(13,LOW); 
 }    
}

Credits

mdraber
50 projects • 74 followers
Contact

Comments

Please log in or sign up to comment.