智能门禁
arduino rc522读卡器 sg90舵机 校园卡
我的校园卡号识别为 30fcb4a8d
#include
#include
#include
RFID rfid(10,5);
unsigned char RC_size;
unsigned char blockAddr; //选择操作的块地址0~63
unsigned char i,tmp;
unsigned char status;
unsigned char str[MAX_LEN];
Servo servo_5;
char * card[]={"30fcb4a8d","10aab4afb","30fcb4a83"};
char * name[]={"wu","liu","lu"};
String rc;
String RFID_readcardnum() {
rfid.readCardSerial();
String stringserNum=String(rfid.serNum[0], HEX)+String(rfid.serNum[1], HEX)+String(rfid.serNum[2], HEX)+String(rfid.serNum[3], HEX)+String(rfid.serNum[4], HEX);
//选卡,返回卡容量(锁定卡片,防止多次读写)
rfid.selectTag(rfid.serNum);
return stringserNum;
}
//4字节卡序列号,第5字节为校验字节
//新扇区A密码,16个扇区,每个扇区密码6Byte
unsigned char sectorNewKeyA[16][16] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},};
unsigned char serNum[5];
//写卡数据
//原扇区A密码,16个扇区,每个扇区密码6Byte
unsigned char sectorKeyA[16][16] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},};
void setup(){
rc = "";
Serial.begin(9600);
SPI.begin();
rfid.init();
servo_5.attach(5);
Serial.begin(9600);
}
void loop(){
if ( rfid.isCard() ) {
rc = RFID_readcardnum();
for (int i = (1); i <= (sizeof(card)/sizeof(card[0])); i = i + (1)) {
if (rc == card[(int)(i - 1)]) {
servo_5.write(90);
delay(3000);
servo_5.write(0);
delay(0);
}
}
Serial.println(RFID_readcardnum());
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章