Components and supplies
RFID reader (generic)
Breadboard (generic)
Servos (Tower Pro MG996R)
RGB Diffused Common Cathode
Buzzer
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
Arduino RFID locker
arduino
Works on any Arduino Uno systems with the required controls
1// Created by Surya Skywalker. This code will be used in the locker. when 2 the correct card is swiped, light goes gren and door opens and when swiped a second 3 time, door closes and light goes 4// to blue. when wrong card is swiped, ligh 5 goes red and buzzer beeps. 6 7#include <SPI.h> 8#include <MFRC522.h> 9#include 10 <Servo.h> 11 12#define SS_PIN 10 13#define RST_PIN 9 14#define Buzzer 8 // Pin 15 3 connected to + pin of the Buzzer 16 17Servo myservo; // create servo object 18 to control a servo 19// twelve servo objects can be created on most boards 20MFRC522 21 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. 22 23int pos = 0; // 24 variable to store the servo position 25int num = 0; 26int redPin = 2; 27int greenPin 28 = 4; 29int bluePin = 7; 30int counter = 0; 31const int buzzerPin = 8; 32 33void 34 setup() { 35 // put your setup code here, to run once: 36 Serial.begin(9600); 37 // Initiate a serial communication 38 SPI.begin(); // Initiate SPI bus 39 40 mfrc522.PCD_Init(); // Initiate MFRC522 41 Serial.println("Approximate your 42 card to the reader..."); 43 Serial.println(); 44 myservo.attach(3); // attaches 45 the servo on pin 9 to the servo object 46 myservo.write(0); //Set the servo at 47 position 0 48 pinMode(redPin, OUTPUT); 49 pinMode(greenPin, OUTPUT); 50 pinMode(bluePin, 51 OUTPUT); 52 setColor(0, 0, 225); // blue 53 pinMode(Buzzer, OUTPUT); // Set 54 buzzer pin to an Output pin 55 digitalWrite(Buzzer, LOW); // Buzzer Off at startup 56 57} 58 59void 60 loop() { 61 // put your main code here, to run repeatedly: 62 // Look for new 63 cards 64 if ( ! mfrc522.PICC_IsNewCardPresent()) 65 { 66 return; 67 } 68 69 // Select one of the cards 70 if ( ! mfrc522.PICC_ReadCardSerial()) 71 { 72 73 return; 74 } 75 //Show UID on serial monitor 76 Serial.print("UID tag 77 :"); 78 String content= ""; 79 byte letter; 80 for (byte i = 0; i < mfrc522.uid.size; 81 i++) 82 { 83 Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 84 85 Serial.print(mfrc522.uid.uidByte[i], HEX); 86 content.concat(String(mfrc522.uid.uidByte[i] 87 < 0x10 ? " 0" : " ")); 88 content.concat(String(mfrc522.uid.uidByte[i], 89 HEX)); 90 } 91 Serial.println(); 92 Serial.print("Message : "); 93 content.toUpperCase(); 94 95 if (content.substring(1) == "4A 31 07 85") //change here the UID of the card/cards 96 that you want to give access 97 { 98 if (num % 2 == 0) 99 { 100 setColor(0, 101 225, 0); // Green 102 myservo.write(180); 103 Serial.println("Authorized 104 access"); 105 Serial.println(); 106 } 107 else { 108 Serial.println("Locking..."); 109 110 myservo.write(0); 111 delay(750); 112 Serial.println("Message : 113 Locked"); 114 Serial.println(); 115 setColor(0, 0, 225); // Blue 116 117 } 118 num = num + 1; 119 delay(3000); 120 } 121 122 else { 123 setColor(225, 124 0, 0); // Red 125 Serial.println("Access denied"); 126 Serial.println(); 127 128 beep(1000,10000); 129 setColor(0, 0, 225); // Blue 130 } 131} 132 133void 134 setColor(int red, int green, int blue) 135{ 136 #ifdef COMMON_ANODE 137 red 138 = 255 - red; 139 green = 255 - green; 140 blue = 255 - blue; 141 #endif 142 143 analogWrite(redPin, red); 144 analogWrite(greenPin, green); 145 analogWrite(bluePin, 146 blue); 147} 148 149void beep(int note, int duration) 150{ 151 //Play tone on 152 buzzerPin 153 tone(buzzerPin, note); 154 delay(duration); 155 //Stop tone on 156 buzzerPin 157 noTone(buzzerPin); 158 159 delay(50); 160 161 //Increment counter 162 163 counter++; 164} 165
Downloadable files
Arduino RFID locker
Arduino RFID locker
Arduino RFID locker
Arduino RFID locker
Comments
Only logged in users can leave comments
SuryaTuraga
0 Followers
•0 Projects
Table of contents
Intro
3
0