Components and supplies
RFID Module (Generic)
USB-A to B Cable
Solderless Breadboard Full Size
ULN2003 Stepper Motor Driver Module
5 mm LED: Green
Gravity I2C OLED-2864 Display
Resistor 220 ohm
Male/Female Jumper Wires
5 mm LED: Red
Arduino UNO
RFID Tags-Card and Coin
28BYJ-28 Stepper Motor 5v
Jumper wires (generic)
Apps and platforms
Arduino IDE
Project description
Code
Door Lock system
c_cpp
Final sketch, after the test code
1//Including Libraries 2#include <SPI.h> //SPI Library 3#include <Wire.h> //Include the Wire Library 4#include <MFRC522.h> //Library of the RFID Module 5#include <Stepper.h> //Library for the Stepper Motor 6#include <Adafruit_GFX.h> //Library for the OLED Display 7#include <Adafruit_SSD1306.h> //Library for the OLED Display 8Adafruit_SSD1306 display = Adafruit_SSD1306(); //Creates an object "display", the OLED Display 9//Pins used by the RFID Module 10#define SS_PIN 10 11#define RST_PIN 9 12//LED pins 13int ledr = 6; 14int ledg = 7; 15char st[20]; 16MFRC522 mfrc522(SS_PIN, RST_PIN); //Creates an object "mfrc522", the RFID Module 17Stepper myStepper(500, 2, 4, 3, 5); //Creates an object "myStepper", the Stepper motor 18void setup() { 19 myStepper.setSpeed(60); //Sets Stepper motor speed 20 SPI.begin(); //Starts the SPI Library 21 mfrc522.PCD_Init(); //Starts the RFID Module 22 Wire.begin(); //Starts the Wire library 23 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Starts the display 24 display.setTextColor(WHITE); //Sets the text color 25 display.setTextSize(1); //Sets the text size 26 display.clearDisplay(); //Clears the display 27 //Defining LEDs as output 28 pinMode(ledr, OUTPUT); 29 pinMode(ledg, OUTPUT); 30} 31void loop() { 32 display.clearDisplay(); 33 display.setCursor(5, 1); //Sets the cursor position 34 display.print("Approach the TAG"); //Prints the message 35 digitalWrite(ledr, HIGH); //Red LED is on 36 if ( ! mfrc522.PICC_IsNewCardPresent()) { //RFID module searches for new TAGs 37 return; 38 } 39 if ( ! mfrc522.PICC_ReadCardSerial()) { //Reads the TAG 40 return; 41 } 42 //Decoding the TAG code 43 String content = ""; 44 byte letra; 45 for (byte i = 0; i < mfrc522.uid.size; i++) 46 { 47 content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 48 content.concat(String(mfrc522.uid.uidByte[i], HEX)); 49 } 50 content.toUpperCase(); //Converts the text to upper case 51 //The locker system 52 if (content.substring(1) == "13 FE 51 3D") { //Change here by the code of your TAG 53 display.clearDisplay(); 54 display.setCursor(10, 1); 55 display.print("Authorized access"); //Shows a message on display 56 display.display(); 57 digitalWrite(ledr, LOW); 58 digitalWrite(ledg, HIGH); //Green LED turns on 59 myStepper.step(-512); //Stepper motor moves 60 delay(5000); 61 display.clearDisplay(); 62 display.setCursor(10, 1); 63 display.print("Approach the TAG"); 64 display.display(); 65 digitalWrite(ledr, HIGH); //Red LED turns on again 66 digitalWrite(ledg, LOW); 67 myStepper.step(512); //Stepper motor moves 68 } 69 //Acess denied 70 else if (content.substring(1) != "13 FE 51 3D") {//Change here too 71 display.clearDisplay(); 72 display.setCursor(10, 1); 73 display.print("Access denied"); 74 display.display(); 75 delay(500); 76 display.clearDisplay(); 77 display.setCursor(10, 1); 78 display.print("Approach the TAG"); 79 display.display(); 80 } 81}
Test code (use this to get the TAG's code)
c_cpp
Sketch to get your TAG's code
1#define SS_PIN 10 2#define RST_PIN 9 3 4MFRC522 rfid(SS_PIN, RST_PIN); 5 6void setup() { 7 Serial.begin(9600); 8 SPI.begin(); 9 rfid.PCD_Init(); 10} 11 12void loop() { 13 if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) 14 return; 15 String content = ""; 16 byte letra; 17 for (byte i = 0; i < rfid.uid.size; i++) 18 { 19 content.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ")); 20 content.concat(String(rfid.uid.uidByte[i], HEX)); 21 } 22 content.toUpperCase(); //Converts the text to upper case 23 24 25 Serial.print("TAG CODE: "); 26 Serial.println(content); 27 28 rfid.PICC_HaltA(); 29 rfid.PCD_StopCrypto1(); 30}
Door Lock system
c_cpp
Final sketch, after the test code
1//Including Libraries 2#include <SPI.h> //SPI Library 3#include <Wire.h> 4 //Include the Wire Library 5#include <MFRC522.h> //Library of the RFID Module 6#include 7 <Stepper.h> //Library for the Stepper Motor 8#include <Adafruit_GFX.h> //Library 9 for the OLED Display 10#include <Adafruit_SSD1306.h> //Library for the OLED Display 11Adafruit_SSD1306 12 display = Adafruit_SSD1306(); //Creates an object "display", the OLED Display 13//Pins 14 used by the RFID Module 15#define SS_PIN 10 16#define RST_PIN 9 17//LED pins 18int 19 ledr = 6; 20int ledg = 7; 21char st[20]; 22MFRC522 mfrc522(SS_PIN, RST_PIN); 23 //Creates an object "mfrc522", the RFID Module 24Stepper myStepper(500, 2, 4, 25 3, 5); //Creates an object "myStepper", the Stepper motor 26void setup() { 27 28 myStepper.setSpeed(60); //Sets Stepper motor speed 29 SPI.begin(); //Starts 30 the SPI Library 31 mfrc522.PCD_Init(); //Starts the RFID Module 32 Wire.begin(); 33 //Starts the Wire library 34 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Starts 35 the display 36 display.setTextColor(WHITE); //Sets the text color 37 display.setTextSize(1); 38 //Sets the text size 39 display.clearDisplay(); //Clears the display 40 //Defining 41 LEDs as output 42 pinMode(ledr, OUTPUT); 43 pinMode(ledg, OUTPUT); 44} 45void 46 loop() { 47 display.clearDisplay(); 48 display.setCursor(5, 1); //Sets the cursor 49 position 50 display.print("Approach the TAG"); //Prints the message 51 digitalWrite(ledr, 52 HIGH); //Red LED is on 53 if ( ! mfrc522.PICC_IsNewCardPresent()) { //RFID module 54 searches for new TAGs 55 return; 56 } 57 if ( ! mfrc522.PICC_ReadCardSerial()) 58 { //Reads the TAG 59 return; 60 } 61 //Decoding the TAG code 62 String 63 content = ""; 64 byte letra; 65 for (byte i = 0; i < mfrc522.uid.size; i++) 66 67 { 68 content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 69 70 content.concat(String(mfrc522.uid.uidByte[i], HEX)); 71 } 72 content.toUpperCase(); 73 //Converts the text to upper case 74 //The locker system 75 if (content.substring(1) 76 == "13 FE 51 3D") { //Change here by the code of your TAG 77 display.clearDisplay(); 78 79 display.setCursor(10, 1); 80 display.print("Authorized access"); //Shows 81 a message on display 82 display.display(); 83 digitalWrite(ledr, LOW); 84 85 digitalWrite(ledg, HIGH); //Green LED turns on 86 myStepper.step(-512); 87 //Stepper motor moves 88 delay(5000); 89 display.clearDisplay(); 90 display.setCursor(10, 91 1); 92 display.print("Approach the TAG"); 93 display.display(); 94 digitalWrite(ledr, 95 HIGH); //Red LED turns on again 96 digitalWrite(ledg, LOW); 97 myStepper.step(512); 98 //Stepper motor moves 99 } 100 //Acess denied 101 else if (content.substring(1) 102 != "13 FE 51 3D") {//Change here too 103 display.clearDisplay(); 104 display.setCursor(10, 105 1); 106 display.print("Access denied"); 107 display.display(); 108 delay(500); 109 110 display.clearDisplay(); 111 display.setCursor(10, 1); 112 display.print("Approach 113 the TAG"); 114 display.display(); 115 } 116}
Downloadable files
Schematics
Nothing Here, Check all the steps. Here is only the led connection to arduino
Schematics
Schematics
Nothing Here, Check all the steps. Here is only the led connection to arduino
Schematics
Comments
Only logged in users can leave comments
dylanstauffer839
a month ago
this was perfect thank you