How to use RYRR10S RFID module from Reyax with Arduino
Open the magnetic lock using authorised proximity card!
Components and supplies
1
REYAX RYRR10S RFID module
1
1028x64 SPI OLED display
1
Arduino Nano R3
1
Magnetic Lock 12V
1
KY-019 5V Relay
Apps and platforms
1
Arduino IDE 2.0 (beta)
Project description
Code
Reading tags using RYRR10S RFID module and displaying TAG ID in Serial Monitor
arduino
1#include <SoftwareSerial.h> 2SoftwareSerial NFCserial(2, 3); //RX, TX 3 4uint8_t received_buf_pos=0; 5uint8_t response_byte; 6uint8_t data_len; 7boolean received_complete=false; 8String tag_id = ""; 9char Byte_In_Hex[3]; 10 11 12uint8_t echo_command[1] = {0x55}; 13 14uint8_t initialise_cmd_iso14443_1[6] = {0x09, 0x04, 0x68, 0x01, 0x07, 0x10}; 15uint8_t initialise_cmd_iso14443_2[6] = {0x09, 0x04, 0x68, 0x01, 0x07, 0x00}; 16uint8_t initialise_cmd_iso14443_3[6] = {0x02, 0x04, 0x02, 0x00, 0x02, 0x80}; 17uint8_t initialise_cmd_iso14443_4[6] = {0x09, 0x04, 0x3A, 0x00, 0x58, 0x04}; 18uint8_t initialise_cmd_iso14443_5[6] = {0x09, 0x04, 0x68, 0x01, 0x01, 0xD3}; 19 20uint8_t detect_cmd_iso14443_1[4] = {0x04, 0x02, 0x26, 0x07}; 21uint8_t detect_cmd_iso14443_2[5] = {0x04, 0x03, 0x93, 0x20, 0x08}; 22 23 24void setup() { 25 Serial.begin(9600); 26 NFCserial.begin(57600); 27 Serial.println("Echo command: "); 28 NFCserial.write(echo_command, 1); 29 delay(1000); show_serial_data(); 30 delay(1000); 31 Serial.println("Initialise commands: "); 32 NFCserial.write(initialise_cmd_iso14443_1, 6); 33 delay(1000); show_serial_data(); 34 NFCserial.write(initialise_cmd_iso14443_2, 6); 35 delay(1000); show_serial_data(); 36 NFCserial.write(initialise_cmd_iso14443_3, 6); 37 delay(1000); show_serial_data(); 38 NFCserial.write(initialise_cmd_iso14443_4, 6); 39 delay(1000); show_serial_data(); 40 NFCserial.write(initialise_cmd_iso14443_5, 6); 41 delay(1000); show_serial_data(); 42} 43 44void show_serial_data(){ 45 while(NFCserial.available()!=0) 46 Serial.print(NFCserial.read(), HEX); 47 Serial.println(""); 48} 49 50void Read_Tag(){ 51 uint8_t received_char; 52 while(NFCserial.available()!=0){ 53 received_char = char (NFCserial.read()); 54 55 if(received_buf_pos==0)response_byte = received_char; 56 else if (received_buf_pos==1)data_len = received_char; 57 else if (received_buf_pos>=2 and received_buf_pos<6) { 58 sprintf(Byte_In_Hex,"%x", received_char); 59 tag_id += Byte_In_Hex; //adding to a string 60 } 61 received_buf_pos++; 62 if(received_buf_pos >= data_len){ 63 received_complete = true; 64 } 65 } 66} 67 68void loop() { 69 received_buf_pos = 0; 70 received_complete = false; 71 tag_id=""; 72 response_byte=0; 73 74 Serial.println("Searching new card..."); 75 NFCserial.write(detect_cmd_iso14443_1, 4); 76 delay(800); 77 Serial.println("Response:"); show_serial_data(); 78 79 NFCserial.write(detect_cmd_iso14443_2, 5); 80 delay(300); 81 82 if(NFCserial.available()) { 83 Read_Tag(); 84 } 85 86 if(response_byte == 0x80){ 87 Serial.print("Tag detected. Tag id: "); 88 Serial.println(tag_id); 89 Serial.println(""); 90 delay(2000); 91 } 92 else{ 93 Serial.println("No tag detected."); 94 Serial.println(""); 95 delay(2000); 96 } 97}
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
1#include <SPI.h> 2#include <Wire.h> 3#include <Adafruit_GFX.h> 4#include <Adafruit_SSD1306.h> 5 6 7// Oled display size 8#define SCREEN_WIDTH 128 // OLED display width, in pixels 9#define SCREEN_HEIGHT 64 // OLED display height, in pixels 10 11#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) 12Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 13 14struct tag{ 15 String Card; 16 int Access; 17}; 18tag Tags[4] = {{"1da74473",0}, 19 {"127d2a19",1}, 20 {"8119f02e",0}, 21 {"53b9f72e",1}}; 22 23int Tag_Status; 24 25// 'RFID', 128x48px 26const unsigned char epd_bitmap_RFID [] PROGMEM = { 27 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 28 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 29 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 30 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 31 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 32 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 33 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 34 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 35 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 36 0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 37 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 38 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 39 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 40 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xfe, 0x7f, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 41 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfe, 0x7f, 0xc0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 42 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfe, 0x3f, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 43 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xe2, 0x3f, 0x9f, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 44 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xe3, 0x1f, 0x9f, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xff, 45 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0x33, 0x1f, 0x9f, 0xff, 0xff, 0xf2, 0x1f, 0xff, 0xff, 46 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xfe, 0x31, 0x1f, 0x9f, 0xff, 0xff, 0xf3, 0x8f, 0xff, 0xff, 47 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0x11, 0x9f, 0x9f, 0xff, 0xff, 0xf3, 0xc7, 0xff, 0xff, 48 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf9, 0x11, 0x9f, 0x9f, 0xff, 0xff, 0xf3, 0xe3, 0xff, 0xff, 49 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf1, 0x19, 0x9f, 0x9f, 0xff, 0xff, 0xf3, 0xf1, 0xff, 0xff, 50 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf1, 0x19, 0x9f, 0x9f, 0xff, 0x87, 0xf3, 0xf8, 0xff, 0xff, 51 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf1, 0x19, 0x9f, 0x9f, 0xff, 0x01, 0xf3, 0xfe, 0xff, 0xff, 52 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf1, 0x19, 0x9f, 0x9f, 0xff, 0x38, 0x73, 0xff, 0xff, 0xff, 53 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xf9, 0x11, 0x9f, 0x9f, 0xff, 0x3e, 0x03, 0xff, 0xff, 0xff, 54 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0x11, 0x9f, 0x9f, 0xff, 0x3f, 0x83, 0xff, 0xff, 0xff, 55 0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xfe, 0x31, 0x1f, 0x9f, 0xff, 0x9f, 0xe7, 0xff, 0xff, 0xff, 56 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0x73, 0x1f, 0x9f, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 57 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xe3, 0x1f, 0x9f, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 58 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xe2, 0x3f, 0x9f, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 59 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfe, 0x3f, 0x8f, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 60 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfe, 0x7f, 0xc0, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 61 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xfe, 0x7f, 0xe0, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 62 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xfe, 0x7c, 0x9c, 0x07, 0xff, 0xff, 0xff, 63 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xfc, 0xfc, 0x1c, 0xc0, 0x00, 0x3f, 0xff, 64 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0xff, 0x00, 0x08, 0x00, 0x3f, 0xff, 65 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xe1, 0x1f, 0xff, 0xff, 0xff, 66 0xff, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 67 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 68 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 69 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 70 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 71 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 72 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x7e, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 73 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 74 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 75}; 76// 'notok', 41x41px 77const unsigned char epd_bitmap_notok [] PROGMEM = { 78 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0x00, 0x7f, 0xff, 0x80, 0xff, 0xf8, 0x00, 0x0f, 79 0xff, 0x80, 0xff, 0xe0, 0x00, 0x03, 0xff, 0x80, 0xff, 0x80, 0x7f, 0x00, 0xff, 0x80, 0xff, 0x03, 80 0xff, 0xe0, 0x7f, 0x80, 0xfe, 0x0f, 0xff, 0xf8, 0x3f, 0x80, 0xfc, 0x1f, 0xff, 0xfc, 0x1f, 0x80, 81 0xf8, 0x7f, 0xff, 0xff, 0x0f, 0x80, 0xf0, 0xff, 0xff, 0xff, 0x87, 0x80, 0xe1, 0xcf, 0xff, 0xfb, 82 0x87, 0x80, 0xe1, 0xc7, 0xff, 0xe1, 0xc3, 0x80, 0xc3, 0xc3, 0xff, 0xc3, 0xe3, 0x80, 0xc3, 0xe0, 83 0xff, 0x83, 0xe1, 0x80, 0xc7, 0xf0, 0x7f, 0x07, 0xf1, 0x80, 0x87, 0xf8, 0x3e, 0x0f, 0xf0, 0x80, 84 0x8f, 0xfc, 0x1c, 0x1f, 0xf8, 0x80, 0x8f, 0xfe, 0x08, 0x3f, 0xf8, 0x80, 0x8f, 0xff, 0x00, 0x7f, 85 0xf8, 0x80, 0x8f, 0xff, 0x80, 0xff, 0xf8, 0x80, 0x8f, 0xff, 0x81, 0xff, 0xf8, 0x80, 0x8f, 0xff, 86 0x80, 0xff, 0xf8, 0x80, 0x8f, 0xff, 0x00, 0x7f, 0xf8, 0x80, 0x8f, 0xfe, 0x00, 0x3f, 0xf8, 0x80, 87 0x8f, 0xfc, 0x1c, 0x1f, 0xf8, 0x80, 0x87, 0xf8, 0x3e, 0x0f, 0xf0, 0x80, 0xc7, 0xf0, 0x7f, 0x0f, 88 0xf1, 0x80, 0xc7, 0xe0, 0xff, 0x83, 0xe1, 0x80, 0xc3, 0xc1, 0xff, 0xc3, 0xe3, 0x80, 0xe1, 0xc3, 89 0xff, 0xe1, 0xc3, 0x80, 0xe1, 0xc7, 0xff, 0xf1, 0xc7, 0x80, 0xf0, 0xff, 0xff, 0xff, 0x87, 0x80, 90 0xf8, 0x7f, 0xff, 0xff, 0x0f, 0x80, 0xfc, 0x3f, 0xff, 0xfe, 0x1f, 0x80, 0xfc, 0x0f, 0xff, 0xf8, 91 0x3f, 0x80, 0xff, 0x07, 0xff, 0xe0, 0x7f, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0xc0, 92 0x00, 0x01, 0xff, 0x80, 0xff, 0xf0, 0x00, 0x07, 0xff, 0x80, 0xff, 0xfc, 0x00, 0x3f, 0xff, 0x80, 93 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 94}; 95// 'ok', 41x41px 96const unsigned char epd_bitmap_ok [] PROGMEM = { 97 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xfc, 0x00, 0x1f, 0xff, 0x80, 0xff, 0xf0, 0x00, 0x07, 98 0xff, 0x80, 0xff, 0xc0, 0x1c, 0x01, 0xff, 0x80, 0xff, 0x03, 0xff, 0xc0, 0xff, 0x80, 0xfe, 0x0f, 99 0xff, 0xf0, 0x7f, 0x80, 0xfc, 0x3f, 0xff, 0xfc, 0x3f, 0x80, 0xf8, 0x7f, 0xff, 0xfe, 0x1f, 0x80, 100 0xf8, 0xff, 0xff, 0xff, 0x0f, 0x80, 0xf1, 0xff, 0xff, 0xff, 0x87, 0x80, 0xe1, 0xff, 0xff, 0xff, 101 0xc7, 0x80, 0xe3, 0xff, 0xff, 0xf9, 0xe3, 0x80, 0xc7, 0xff, 0xff, 0xf0, 0xe3, 0x80, 0xc7, 0xff, 102 0xff, 0xe1, 0xf1, 0x80, 0xc7, 0xff, 0xff, 0xc3, 0xf1, 0x80, 0x8f, 0xff, 0xff, 0x87, 0xf1, 0x80, 103 0x8f, 0xff, 0xff, 0x0f, 0xf1, 0x80, 0x8f, 0xff, 0xfe, 0x1f, 0xf9, 0x80, 0x8f, 0xff, 0xfc, 0x3f, 104 0xf8, 0x80, 0x8f, 0xff, 0xf8, 0x7f, 0xf8, 0x80, 0x8f, 0xff, 0xf0, 0xff, 0xf8, 0x80, 0x8f, 0x9f, 105 0xe1, 0xff, 0xf9, 0x80, 0x8f, 0x87, 0xc3, 0xff, 0xf1, 0x80, 0x8f, 0xc3, 0x87, 0xff, 0xf1, 0x80, 106 0x8f, 0xe0, 0x0f, 0xff, 0xf1, 0x80, 0xc7, 0xf0, 0x1f, 0xff, 0xf1, 0x80, 0xc7, 0xf8, 0x3f, 0xff, 107 0xe3, 0x80, 0xe3, 0xfc, 0x7f, 0xff, 0xe3, 0x80, 0xe3, 0xff, 0xff, 0xff, 0xc7, 0x80, 0xf1, 0xff, 108 0xff, 0xff, 0x87, 0x80, 0xf0, 0xff, 0xff, 0xff, 0x8f, 0x80, 0xf8, 0x7f, 0xff, 0xff, 0x1f, 0x80, 109 0xfc, 0x3f, 0xff, 0xfe, 0x1f, 0x80, 0xfe, 0x1f, 0xff, 0xf8, 0x3f, 0x80, 0xff, 0x07, 0xff, 0xe0, 110 0xff, 0x80, 0xff, 0x80, 0x7f, 0x81, 0xff, 0x80, 0xff, 0xe0, 0x00, 0x07, 0xff, 0x80, 0xff, 0xf8, 111 0x00, 0x1f, 0xff, 0x80, 0xff, 0xff, 0x81, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 112 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 113}; 114 115uint8_t received_buf_pos=0; 116uint8_t response_byte; 117uint8_t data_len; 118boolean received_complete=false; 119String tag_id = ""; 120char Byte_In_Hex[3]; 121 122 123uint8_t echo_command[1] = {0x55}; 124 125uint8_t initialise_cmd_iso14443_1[6] = {0x09, 0x04, 0x68, 0x01, 0x07, 0x10}; 126uint8_t initialise_cmd_iso14443_2[6] = {0x09, 0x04, 0x68, 0x01, 0x07, 0x00}; 127uint8_t initialise_cmd_iso14443_3[6] = {0x02, 0x04, 0x02, 0x00, 0x02, 0x80}; 128uint8_t initialise_cmd_iso14443_4[6] = {0x09, 0x04, 0x3A, 0x00, 0x58, 0x04}; 129uint8_t initialise_cmd_iso14443_5[6] = {0x09, 0x04, 0x68, 0x01, 0x01, 0xD3}; 130 131uint8_t detect_cmd_iso14443_1[4] = {0x04, 0x02, 0x26, 0x07}; 132uint8_t detect_cmd_iso14443_2[5] = {0x04, 0x03, 0x93, 0x20, 0x08}; 133 134 135void setup() { 136 Serial.begin(57600); 137 pinMode(13,OUTPUT); 138 139 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 140 ///Serial.println(F("SSD1306 allocation failed")); 141 for(;;); // Don't proceed, loop forever 142 } 143 //display.display(); 144 //delay(2000); // Pause for 2 seconds 145 display.clearDisplay(); 146 display.setTextSize(1); 147 display.fillRect(0, 0, 128, 15, SSD1306_INVERSE); 148 display.setTextColor(SSD1306_BLACK); 149 display.setCursor(4,4); 150 display.println("Initialising ... "); 151 display.display(); 152 delay(2000); 153 154 155 Serial.write(echo_command, 1); 156 delay(1000); show_serial_data(); 157 Serial.write(initialise_cmd_iso14443_1, 6); 158 delay(500); show_serial_data(); 159 Serial.write(initialise_cmd_iso14443_2, 6); 160 delay(500); show_serial_data(); 161 Serial.write(initialise_cmd_iso14443_3, 6); 162 delay(500); show_serial_data(); 163 Serial.write(initialise_cmd_iso14443_4, 6); 164 delay(500); show_serial_data(); 165 Serial.write(initialise_cmd_iso14443_5, 6); 166 delay(500); show_serial_data(); 167} 168 169void show_serial_data(){ 170 while(Serial.available()!=0) Serial.read(); 171} 172 173void Read_Tag(){ 174 uint8_t received_char; 175 while(Serial.available()!=0){ 176 received_char = char (Serial.read()); 177 178 if(received_buf_pos==0)response_byte = received_char; 179 else if (received_buf_pos==1)data_len = received_char; 180 else if (received_buf_pos>=2 and received_buf_pos<6) { 181 sprintf(Byte_In_Hex,"%x", received_char); 182 tag_id += Byte_In_Hex; //adding to a string 183 } 184 received_buf_pos++; 185 if(received_buf_pos >= data_len){ 186 received_complete = true; 187 } 188 } 189} 190 191void Searching_Tag_Screen(){ 192 display.fillRect(0, 0, 128, 15, SSD1306_WHITE); 193 display.setTextSize(1); 194 display.setCursor(4,4); 195 display.println("Scan Card..."); 196 display.fillRect(0, 15, 128, 49, SSD1306_BLACK); 197 display.drawBitmap(0,16,epd_bitmap_RFID,128,48,1); 198 display.display(); 199} 200 201void Display_Tag(String Tag){ 202 203 display.fillRect(0, 0, 128, 15, SSD1306_WHITE); 204 display.setCursor(1,8); 205 display.println("TAG: "); 206 display.setTextSize(2); 207 display.setCursor(30,1); 208 //Tag.toUpperCase(); 209 display.println(Tag); 210 display.display(); 211} 212 213 214void loop() { 215 received_buf_pos = 0; 216 received_complete = false; 217 tag_id=""; 218 response_byte=0; 219 Searching_Tag_Screen(); 220 221 Serial.write(detect_cmd_iso14443_1, 4); 222 delay(800); 223 show_serial_data(); 224 225 Serial.write(detect_cmd_iso14443_2, 5); 226 delay(300); 227 228 if(Serial.available()) { 229 Read_Tag(); 230 } 231 232 if(response_byte == 0x80){ 233 Display_Tag(tag_id); 234 display.fillRect(0, 15, 128, 49, SSD1306_WHITE); 235 display.fillRect(2, 20, 41, 41, SSD1306_BLACK); 236 display.setTextSize(2); 237 Tag_Status=2; 238 for (int i=0;i<sizeof(Tags)/sizeof(tag); i++){ 239 if(Tags[i].Card==tag_id) Tag_Status=Tags[i].Access; 240 } 241 if(Tag_Status==1){ 242 digitalWrite(13,HIGH); 243 display.drawBitmap(2,20,epd_bitmap_ok,41,41,1); 244 display.setCursor(43,33); 245 display.println("GRANTED"); 246 display.display(); 247 } 248 if (Tag_Status==0){ 249 display.drawBitmap(2,20,epd_bitmap_notok,41,41,1); 250 display.setCursor(43,33); 251 display.println(" DENIED"); 252 display.display(); 253 } 254 if (Tag_Status==2){ 255 display.fillRect(0, 15, 128, 49, SSD1306_WHITE); 256 display.setCursor(30,33); 257 display.println("UNKNOWN"); 258 display.display(); 259 } 260 delay(4000); 261 digitalWrite(13,LOW); 262 } 263}
Comments
Only logged in users can leave comments