Mixly-RFID智能门禁实验内容
【1】读取校园卡ID号。
【2】读取到指定校园卡使用S90舵机开门,并延时3秒后自动关闭。
步骤一:读取校园卡ID号
代码实现如下:
#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];
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(){
Serial.begin(9600);
SPI.begin();
rfid.init();
Serial.begin(9600);
}
void loop(){
if ( rfid.isCard() ) {
Serial.println(RFID_readcardnum());
}
}
Mixly图形化编程
步骤2:读取到指定校园卡使用S90舵机开门,并延时3秒后自动关闭。
代码实现如下:
#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[]={"9089a4a59","9089a0a","9020fc89a","9089020fc","902090890"};//这个数组存放的是从卡中读取到的编号
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();
Serial.begin(9600);
servo_5.attach(5);
}
void loop(){
if ( rfid.isCard() ) {
Serial.println(RFID_readcardnum());
rc = RFID_readcardnum();
Serial.println(rc);
for (int i = (0); 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);
}
}
}
Mixly图形化编程
实验视频链接:[https://www.ixigua.com/i6752314594468823560/]
实验思路:
①、先用步骤的简单实验得到存储在卡内的编号;
②、将读取到的编号存放一个数组里面,FRID侦测到信号后,首先将读到的卡号赋值给RC,然后去到数组card中去找,如果找的到,就将舵机转90度,三秒后舵机自动回转(模拟现实中,开门后自动关门)。
写在最后:
以上是本人Arduino课程的一些实验报告,在此作为一个学习记录和分享,难免会有一些错误欢迎指正!