我正在使用Arduino UNO R3,MFRC522 rfid和用于门禁的继电器。有时他们停止工作,无法再读取卡。 我不知道MFRC522是否有缺陷或代码中是否有错误。
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int in1 = 2;
int in3 = 7;
int a = 1;
void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
pinMode(in1, OUTPUT);
digitalWrite(in1, HIGH);
pinMode(in3, INPUT_PULLUP);
delay(1000);
}
void loop()
{
a = digitalRead(in3);
Serial.println(a);
digitalWrite(in1, HIGH);
if (a == 1) {
digitalWrite(in1, HIGH);
}
delay(80);
if (a == 0) {
digitalWrite(in1, LOW);
delay(80);
digitalWrite(in1, HIGH);
delay(1000);
}
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
String content = "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
content.toUpperCase();
if (content.substring(1) == "E3 41 E5 87" || content.substring(1) == "FE 42 93 3F" || content.substring(1) == "8D 2C 36 BF" || content.substring(1) == "4D 0E 2A 3F" || content.substring(1) == "AD 4E 2D CB")
{
//Serial.println("Authorized access");
digitalWrite(in1, LOW);
delay(80);
digitalWrite(in1, HIGH);
delay(1000);
}
else {
// Serial.println(" Access denied");
delay(2000);
}
}
我将此系统与YALA一起用于门禁。 但是当它停止时,我需要重置整个系统。