im really new in Arduino world and i need some help for my project. I found a code to read my Card Numbers. The 1. Card is=DB 7F EA D5 and the 2. Card is=D6 D0 84 8D. I want to use these 2 Cards to print in Serial monitor The Door is Open and The door is closed. Can someone help me to modify my code? I would be really happy to learn how this world is working.
My Code to read Card Number
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5 // SPI Reset Pin
#define SS_PIN 53 // SPI Slave Select Pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // Instanz des MFRC522 erzeugen
void setup() {
// Diese Funktion wird einmalig beim Start ausgeführt
Serial.begin(9600); // Serielle Kommunikation mit dem PC initialisieren
SPI.begin(); // Initialisiere SPI Kommunikation
mfrc522.PCD_Init(); // Initialisiere MFRC522 Lesemodul
}
void loop() {
// Diese Funktion wird in Endlosschleife ausgeführt
// Nur wenn eine Karte gefunden wird und gelesen werden konnte, wird der Inhalt von IF ausgeführt
// PICC = proximity integrated circuit card = kontaktlose Chipkarte
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ) {
Serial.print("Gelesene UID:");
for (byte i = 0; i < mfrc522.uid.size; i++) {
// Abstand zwischen HEX-Zahlen und führende Null bei Byte < 16
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
// Versetzt die gelesene Karte in einen Ruhemodus, um nach anderen Karten suchen zu können.
mfrc522.PICC_HaltA();
delay(1000);
}
}
the code is just for the see what my id number. But i want to modify this code and see in serial monitor for 1. Card The door is open and for the 2. Card access denied
it print the card numbers. I need to save the card numbers on a variable and check if they are opening card. other cards needs to print out access denied
This will probably do what you want. Feel free to move the validUUID array to a more suitable location (e.gh. global). The code uses memcmp(3) - Linux manual page
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
Serial.print("Gelesene UID:");
for (byte i = 0; i < mfrc522.uid.size; i++) {
// Abstand zwischen HEX-Zahlen und führende Null bei Byte < 16
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
uint8_t validUUID[] = { 0xDB, 0x7F, 0xEA, 0xD5 };
if (memcmp(validUUID, mfrc522.uid.uidByte, mfrc522.uid.size) == 0) {
Serial.println(F("valid"));
}
Thank you guys it working really well. But i want to also change something in my code. Im Using the code from @b707 and its definitely what i want. But after i use it i just get access denied repeatedly. I think i have to change the void loop function. But im not sure how. how should i change it? After that it is going to work as i wanted. I would be really happy if you guys teach me how its done. Thank you
im working on a project for my school and im really new in Arduino World. I need use a RFID to write on serial Monitor "The Door is open" or "Access Denied". With my Code that i found on internet, i can see the number of the card. But i don't know what the next step is. How should i modify my code to be able to see The Door is open or Access Denied. I would be really happy, if someone help to me.
CODE:
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5 // SPI Reset Pin
#define SS_PIN 53 // SPI Slave Select Pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // Instanz des MFRC522 erzeugen
void setup() {
// Diese Funktion wird einmalig beim Start ausgeführt
Serial.begin(9600); // Serielle Kommunikation mit dem PC initialisieren
SPI.begin(); // Initialisiere SPI Kommunikation
mfrc522.PCD_Init(); // Initialisiere MFRC522 Lesemodul
}
void loop() {
// Diese Funktion wird in Endlosschleife ausgeführt
// Nur wenn eine Karte gefunden wird und gelesen werden konnte, wird der Inhalt von IF ausgeführt
// PICC = proximity integrated circuit card = kontaktlose Chipkarte
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ) {
Serial.print("Gelesene UID:");
for (byte i = 0; i < mfrc522.uid.size; i++) {
// Abstand zwischen HEX-Zahlen und führende Null bei Byte < 16
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
// Versetzt die gelesene Karte in einen Ruhemodus, um nach anderen Karten suchen zu können.
mfrc522.PICC_HaltA();
delay(1000);
}
}
What are the conditions you are looking for that tell you to print the door open message? What are the conditions you are looking for the print the access denied message?
Hey sorry for the late answer. So i have 2 different cards that im using. 1. Card has the number DB 7F EA D5 and 2. card has D6 D0 84 8D. If i use my first card i want to see in my serial monitor that the door is open. And if i hold the 2. card access denied. I hope you understand what i mean. Thank You
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project See About the Installation & Troubleshooting category.