RFID演奏音乐
引言:Arduino做的各种应用广泛被开源硬件爱好者喜欢。今天给大家介绍一个互动性强的arduino RFID乐器,适合放松娱乐,这个项目利用了RFID和MP3模块,把从RFID采集的数据通过MP3模块播放特定的音符,从而带来适合少儿娱乐的互动音乐游戏。 https://www.bilibili.com/video/BV1Q44y167uh?share_source=copy_web 第一步:展示内容用的这个模块这个是RFID的连线图第三步:硬件搭建
序号 名称 数量
1 arduino uno 1
2 rfid模块rc5221
3 rfid tag 7
4 DF MP3模块 1
5 8欧喇叭 1
6
第五步:发一些硬件的图片。让人有个直观的认识
从arduino串口找到每个tag的编码。具体是打开arduino-实例文件-rfid-cardread,打开cardread文件并上传,之后用RFID扫描tag,然后在串口里查每个tag的编码。在串口看扫描tag后的tag编码
第七部:连线图第八部:代码部分的设计
/*
*/
#include <SPI.h>
#include <MFRC522.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
unsigned char order = {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(); // InitiateSPI 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 < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte, HEX);
content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte, 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 = {0xAA,0x07,0x02,0x00,Track,Track+0xB3};//0xB3=0xAA+0x07+0x02+0x00,即最后一位为校验和
Serial1.write(play,6);
}
void volume( unsigned char vol)
{
unsigned char volume = {0xAA,0x13,0x01,vol,vol+0xBE};//0xBE=0xAA+0x13+0x01,即最后一位为校验和
Serial1.write(volume,5);
}
作品很有创意,漂亮 rzegkly 发表于 2021-5-3 10:25
作品很有创意,漂亮
多谢评价
页:
[1]