Created
June 18, 2018 13:21
-
-
Save elktros/1200fef2fc74ba9d6d011fe6f3445dd5 to your computer and use it in GitHub Desktop.
Code for Arduino and RFID based Encrypted Login System.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*THIS PROJECT REQUIRES STEPS, FIRST STEP IS, MAKE IT THE CIRCUIT THAT I SHARED AND UPLOAD THE CODE TO YOUR ARDUINO, AFTER THAT READ YOUR CARD WITH USING RFID SENSOR, | |
FINALLY YOU WILL SEE THE CARD'S UID, AND AT THE FINAL STEP YOU SUPPOSE | |
TO CHANGE THE CODE THAT I WROTE BEFORE. | |
https://www.electronicshub.org/ | |
created by The Industries Of Engineering | |
Instagram:theindustriesofengineering | |
G-mail:theindustriesofengineering@gmail.com | |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
Rfid technology is used in different areas, | |
so we're using RFID technology in our almost every cards. | |
So, in this project we're going to make a project which can teach us how RFID technology works. | |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
*/ | |
#include <SPI.h> | |
#include <MFRC522.h> | |
#include <EEPROM.h> | |
#include <Servo.h> | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h>//I used i'2c module, so if you are gonna use 20x4 i2'c lcd display, don't change the code | |
#define RST_PIN 9 | |
#define SS_PIN 10 | |
#define ledPin 3 | |
MFRC522 mfrc522(SS_PIN, RST_PIN); | |
/*change them if you're gonna use 16*2 lcd without i'2c | |
but if you want to use 20x4 i'2c module ; | |
sda=A4 | |
scl=A5 | |
-------------------------------------------------------- | |
if you're gonna use 16x2 lcd display without i'2c, change the library(do it LiquidCrystal.h), and change the code as you wish. | |
*/ | |
LiquidCrystal_I2C lcd(0x3f , 20 , 4); | |
String lastRfid = ""; | |
Servo myservo; | |
MFRC522::MIFARE_Key key; | |
void setup() | |
{ | |
Serial.begin(9600); | |
SPI.begin(); | |
mfrc522.PCD_Init(); | |
pinMode(ledPin, OUTPUT); | |
Serial.println("ENCRYPTED LOGIN SYSTEM"); | |
Serial.println("**********************************"); | |
Serial.println(); | |
myservo.attach(6); //servo motor | |
pinMode(3,OUTPUT); //led | |
pinMode(2,OUTPUT); //buzzer | |
lcd.begin(); | |
lcd.setCursor(1,0); | |
lcd.print(" "); | |
lcd.setCursor(0,1); | |
lcd.print(" INSERT YOUR CARD"); | |
} | |
void loop() | |
{ | |
//don't contiune untill new card | |
if ( ! mfrc522.PICC_IsNewCardPresent()) | |
{ | |
return; | |
} | |
if ( ! mfrc522.PICC_ReadCardSerial()) | |
{ | |
return; | |
} | |
//read the UID from card and save it to a string | |
String rfid = ""; | |
for (byte i = 0; i < mfrc522.uid.size; i++) | |
{ | |
rfid += mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "; | |
rfid += String(mfrc522.uid.uidByte[i], HEX); | |
} | |
//string'in boyutunu ayarla ve tamamýný büyük harfe çevir | |
rfid.trim(); | |
rfid.toUpperCase(); | |
if (rfid == lastRfid) | |
return; | |
lastRfid = rfid; | |
Serial.print("UID: ");//at the first step, you are going to see card's UID | |
Serial.println(rfid); | |
Serial.println(); | |
if (rfid == "** ** ** **")//my UID was here, write your card's uid after rading it | |
{ | |
digitalWrite(ledPin, HIGH); | |
myservo.write(90); | |
lcd.clear(); | |
lcd.setCursor(1,0); | |
lcd.print(" < ACCESS ACCEPTED >"); | |
delay(1700); | |
myservo.write(0); | |
lcd.clear(); | |
lcd.print("<INSERT YOUR CARD>"); | |
} | |
else | |
{ | |
lcd.clear(); | |
lcd.setCursor(1,0); | |
lcd.print(" < ACCESS DENIED >"); | |
digitalWrite(ledPin, LOW); | |
myservo.write(0); | |
digitalWrite(2,HIGH); | |
delay(1500); | |
digitalWrite(2,LOW); | |
lcd.clear(); | |
lcd.print("<INSERT YOUR CARD>"); | |
} | |
Serial.println(); | |
delay(200); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment