I have a question about the RFID MFRC522 project with two LED lights. If I scan with the RFID tag or card and I continuously hold my bag over the laser, it keeps scanning and you see the green and red LED lighting flashing back and forth.
Now if I do not place the badge over the laser, the LED light should glow red (this works) and if it remains constantly over the laser, the LED light should remain glowing green so that it only scans the ID once. (So it has to scan once when it is on it + green light, when I take it away the red light must remain on).
Is there no way to save the data in memory so that it continues to remember the ID and which code should I use for this?
You might want to look at this How to get the best out of this forum before you proceed any further.
It tells you what to do when asking a question here.
By the word laser I meant the continuous scanning of the RFID-RC522 with my tag or card. I have read the rules about the best use of the forum. My question is actually about this question (see topic how to make LED stay on after RFID is scanned).
It is a key project in which the tag (key) remains hanging over the scanner and the green light must remain on without continuing to scan. When I remove the tag (key) from the scanner, the red light should remain on.
#include <SPI.h>
#include <MFRC522.h>
#define Reset_PIN 9 // Pin to setup the reset of the Rfid
#define Liaison_SPI 10 // Pin for the SPI liaison
const int ledpin1 = 7;
const int ledpin2 = 6;
const int buzzer = 8;
MFRC522 mfrc522(Liaison_SPI, Reset_PIN);
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600); // We initialize the connection with the serial monitor
while (!Serial)
; // We do nothing as long as the serial monitor is open
SPI.begin(); // We initialize the SPI liaison Initialisation de la liaison SPI.
mfrc522.PCD_Init(); // We initialize the Rfid card
Serial.println("Gelieve u badge of kaart op de laser te plaatsen A.U.B...");
pinMode(ledpin1, OUTPUT);
pinMode(ledpin2, OUTPUT);
digitalWrite(ledpin1, HIGH); // We turn on the red led as long as the tag or UID card is not approached
digitalWrite(ledpin2, LOW); // We turn on the green led as long as the tag or UID card is approached
}
void loop() {
// We search if there are new cards
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
//Show UID on serial monitor
Serial.print("Sleutel ID:");
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("");
content.toUpperCase();
if (content.substring(1) == "EA CC 12 91" || content.substring(1) == "") //change here the UID of the card/cards that you want to give access
{
// Red LED off, green turns on
digitalWrite(ledpin1, LOW);
digitalWrite(ledpin2, HIGH);
delay(1000);
// Print on monitor
Serial.print("");
delay(500);
digitalWrite(ledpin1, HIGH);
digitalWrite(ledpin2, LOW);
}
else {
// Red LED on, green off
digitalWrite(ledpin1, HIGH);
digitalWrite(ledpin2, LOW);
delay(1000);
// Determines the frequency of the buzzer
tone(buzzer, 500);
// wait 1 second
delay(500);
// stops sound
noTone(buzzer);
Serial.println("");
digitalWrite(ledpin1, HIGH);
digitalWrite(ledpin2, LOW);
delay(1000);
}
}