电子工程师技术服务社区
公告
登录
|
注册
首页
技术问答
厂商活动
正点原子
板卡试用
资源库
下载
文章
社区首页
文章
RFID演奏音乐
分 享
扫描二维码分享
RFID演奏音乐
RFID
arduino
MP3模块
gada8881
关注
发布时间: 2021-05-21
丨
阅读: 722
# 引言: ### Arduino做的各种应用广泛被开源硬件爱好者喜欢。今天给大家介绍一个互动性强的arduino RFID乐器,适合放松娱乐,这个项目利用了RFID和MP3模块,把从RFID采集的数据通过MP3模块播放特定的音符,从而带来适合少儿娱乐的互动音乐游戏。 [https://www.bilibili.com/video/BV1Q44y167uh/](https://www.bilibili.com/video/BV1Q44y167uh/) ## 第一步:展示内容 ![](https://cf04.ickimg.com/bbsimages/202105/9c55174b534ff324626f4b2f59824b4d.png) 用的这个模块 ![](https://cf04.ickimg.com/bbsimages/202105/91706f26b1a9225aac5c4a29b73e20ed.png) 这个是RFID的连线图 ## 第三步:硬件搭建 序号 名称 数量 1 arduino uno 1 2 rfid模块rc522 1 3 rfid tag 7 4 DF MP3模块 1 5 8欧喇叭 1 ## 第五步: 发一些硬件的图片。让人有个直观的认识 ![](https://cf04.ickimg.com/bbsimages/202105/50350b8f10c657a24b29fb80d8a95cb9.jpg) ![](https://cf04.ickimg.com/bbsimages/202105/fd3df617d5058aafe716d9a4bf703b84.png) 从arduino串口找到每个tag的编码。具体是打开arduino-实例文件-rfid-cardread,打开cardread文件并上传,之后用RFID扫描tag,然后在串口里查每个tag的编码。 ![](https://cf04.ickimg.com/bbsimages/202105/81c863420b710827f5f54809391df3eb.jpg) ![](https://cf04.ickimg.com/bbsimages/202105/2b95f1acaa57f551dd6ed567b5c8d2c3.png) 在串口看扫描tag后的tag编码 ### ### 第七部:连线图 ![](https://cf04.ickimg.com/bbsimages/202105/e65902f713213469c0fdee32bebf6924.png) ### 第八部:代码部分的设计 ```c /@@* */ #include
#include
#include "Arduino.h" #include "SoftwareSerial.h" unsigned char order[4] = {0xAA,0x06,0x00,0xB0}; #define SS_PIN 10 #define RST_PIN 9 MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. SoftwareSerial Serial1(7, 6); // RX, TX //============SETUP================ void setup() { Serial1.begin(9600); volume(0x1E);//音量设置0x00-0x1E Serial.begin(115200); // Initiate a serial communication SPI.begin(); // Initiate SPI bus mfrc522.PCD_Init(); // Initiate MFRC522 Serial.println("Approximate your card to the reader..."); Serial.println(); } void loop() { // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } //Show UID on serial monitor Serial.print("UID tag :"); 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("Message : "); content.toUpperCase(); if (content.substring(1) == "69 E4 3C A3") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); play(0x01);//指定播放:0x01-文件0001 delay(1000); } if (content.substring(1) == "67 33 7E 7A") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); play(0x02);//指定播放:0x02-文件0002 delay(1000); } if (content.substring(1) == "D7 3F 7C 7B") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); play(0x03);//指定播放:0x03-文件0003 delay(1000); } if (content.substring(1) == "F7 E6 51 7B") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); play(0x04);//指定播放:0x04-文件0004 delay(1000); } if (content.substring(1) == "E7 B6 72 7B") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); play(0x05);//指定播放:0x05-文件0005 delay(1000); } if (content.substring(1) == "37 18 84 7B") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); play(0x06);//指定播放:0x06-文件0006 delay(1000); } if (content.substring(1) == "87 2E 79 7A") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); play(0x07);//指定播放:0x07-文件0007 delay(1000); } else { Serial.println(" Access denied"); delay(1000); } } //==========FUNCTION========== void play(unsigned char Track) { unsigned char play[6] = {0xAA,0x07,0x02,0x00,Track,Track+0xB3};//0xB3=0xAA+0x07+0x02+0x00,即最后一位为校验和 Serial1.write(play,6); } void volume( unsigned char vol) { unsigned char volume[5] = {0xAA,0x13,0x01,vol,vol+0xBE};//0xBE=0xAA+0x13+0x01,即最后一位为校验和 Serial1.write(volume,5); } ```
原创作品,未经权利人授权禁止转载。详情见
转载须知
。
举报文章
点赞
(
0
)
gada8881
关注
评论
(1)
登录后可评论,请
登录
或
注册
神马姐
334
天前...
非常棒
0
回复
发布
相关文章推荐
MK-米客方德推出工业级存储卡
Beetle ESP32 C3 蓝牙数据收发
Beetle ESP32 C3 wifi联网获取实时天气信息
开箱测评Beetle ESP32-C3 (RISC-V芯片)模块
正点原子数控电源DP100测评
DP100试用评测-----开箱+初体验
Beetle ESP32 C3环境搭建
【花雕体验】16 使用Beetle ESP32 C3控制8X32位WS2812硬屏之二
X
你的打赏是对原创作者最大的认可
请选择打赏IC币的数量,一经提交无法退回 !
100IC币
500IC币
1000IC币
自定义
IC币
确定
X
提交成功 ! 谢谢您的支持
返回
我要举报该内容理由
×
广告及垃圾信息
抄袭或未经授权
其它举报理由
请输入您举报的理由(50字以内)
取消
提交