0

我买了一个 rfid 长距离 Wiegand EM4095,

我找到了一个代码,但我需要替换 id 标签,

我需要找到放置密码卡或标签的方法

这是代码:

#include <SoftwareSerial.h>
#define ADD_TAG_CODE "000736087" //change this ID with your own card TAG
#define DEL_TAG_CODE "000555859" //change this ID with your own card 

SoftwareSerial mySerial(2, 3); // RX, TX
String msg;
String ID ; //string to store allowed cards

void setup()
{
Serial.begin(9600);
Serial.println("Serial Ready");

mySerial.begin(9600);
Serial.println("RFID Ready");
}

char c;

void loop(){

while(mySerial.available()>0){
c=mySerial.read();
msg += c;
Serial.println(msg); //Uncomment to view your tag ID
Serial.println(msg.length());
}
msg=msg.substring(1,13);
if(msg.indexOf(ADD_TAG_CODE)>=0) add();
else if(msg.indexOf(DEL_TAG_CODE)>=0) del();
else if(msg.length()>10) verifica();
msg="";

}

void add(){
Serial.print("What TAG do you wanna grant access?: ");
msg="";
while(msg.length()<13){
while(mySerial.available()>0){
c=mySerial.read();
msg += c;
}
}
if(ID.indexOf(msg)>=0) {
Serial.println("\nAccess already granted for this card.");
msg="";
}
else{
Serial.print("Card: ");
Serial.println(msg);
ID += msg;
ID += ",";
//Serial.print("ID: ");
//Serial.println(ID);
msg="";
Serial.println("Access granted for this card.");
}

}

void del(){
msg="";
Serial.print("What TAG do you wanna deny access?: ");
while(msg.length()<13){
while(mySerial.available()>0){
c=mySerial.read();
msg += c;
}
}
msg=msg.substring(1,13);
if(ID.indexOf(msg)>=0){
Serial.println(msg);
Serial.println("TAG found. Access for this card denied.");
//ID.replace(card,"");
int pos=ID.indexOf(msg);
msg="";
msg += ID.substring(0,pos);
msg += ID.substring(pos+15,ID.length());
ID="";
ID += msg;
//Serial.print("ID: ");
//Serial.println(ID);
} else Serial.println("\nTAG not found or already denied");
msg="";
}

void verifica(){
msg=msg.substring(1,13);
if(ID.indexOf(msg)>=0) Serial.println("Access granted.");
else
Serial.println("Access denied.");
} 

串行输出

有人可以帮我解决这个问题或给我一个项目链接吗?

如何修改手动存储的卡片?

是否将 ID 存储在内存中?

谢谢你。

4

1 回答 1

0

像这样做。

 long keys[] = { 0002573238 };

0002573238 这是您的 rfid 标签代码。如果您还有任何问题,请访问这里https://www.instructables.com/id/Reading-RFID-Tags-with-an-Arduino/

希望这会帮助你。

谢谢!

于 2018-09-22T11:49:51.580 回答