Devices & Components
Arduino Uno Rev3
Breadboard - 400 contacts
10 jumper wires 150mm male
Set of 70 assorted color 5mm LEDs
RFID-RC522 Sensor
Resisstor 330 ohoms
Software & Tools
Arduino IDE
Project description
Code
RC522code
cpp
This is the code for the project.
1#include <SPI.h> 2#include <MFRC522.h> 3 4#define SS_PIN 10 5#define RST_PIN 9 6#define greenLED 8 7#define redLED 7 8 9String UIDlist[4] = {"A3D4F231", "A31F094B", "12AB34CD", "DEADBEEF"}; 10bool LEDstate = false; 11 12MFRC522 mfrc522(SS_PIN, RST_PIN); 13 14void setup() { 15 pinMode(greenLED, OUTPUT); 16 pinMode(redLED, OUTPUT); 17 Serial.begin(9600); 18 SPI.begin(); 19 mfrc522.PCD_Init(); 20 Serial.println("Scan your RFID card..."); 21} 22 23void loop() { 24 if (!mfrc522.PICC_IsNewCardPresent()) return; 25 if (!mfrc522.PICC_ReadCardSerial()) return; 26 27 String uidString = ""; 28 29 for (byte i = 0; i < mfrc522.uid.size; i++) { 30 if (mfrc522.uid.uidByte[i] < 0x10) { 31 uidString += "0"; 32 } 33 uidString += String(mfrc522.uid.uidByte[i], HEX); 34 } 35 36 uidString.toUpperCase(); 37 Serial.println(uidString); 38 39 for (int i = 0; i < 4; i++) { 40 if (UIDlist[i] == uidString){ 41 LEDstate = true; 42 break; 43 } 44 45 else{ 46 LEDstate = false; 47 } 48 } 49 50 if(LEDstate){ 51 digitalWrite(greenLED, HIGH); 52 delay(1000); 53 digitalWrite(greenLED, LOW); 54 } 55 56 else{ 57 digitalWrite(redLED, HIGH); 58 delay(1000); 59 digitalWrite(redLED, LOW); 60 } 61}
Comments
Only logged in users can leave comments