So, I want to make a simple lock box that unlocks using a servo and RC522 RFID tag reader/writer. I am also wanting to use what I learn from this to make a better one in the future. But I want to write my own code for it.
Here is the code I have used to get the arduino to do what I want it to do using RC522 RFID tag reader/writer, and a servo.(See Below).
The thing is I got this code online and don't really know what it is doing. I realize that this code has comments but I need things explained in more detail than anyone can really provide.
The parts I really need help understanding are from Serial.print("UID tag: "); all the way to Serial. println("Authorized Access"); Can ANYONE PLEASE explain this section of code in detail, as to why it has to be the way that it is?
A Million Thanks to anyone Who can actually help me out!!
The Code is as Follows
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
int servoPos=0;
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
Servo myservo;
void setup()
{
myservo.attach(2);
myservo.write(servoPos);
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();
}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "39 4C 33 98") //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
Serial.println();
servoPos=175;
myservo.write(servoPos);
delay(20000);
servoPos=0;
myservo.write(servoPos);
}
else {
Serial.println(" Access denied");
delay(3000);
}
}