Cov txheej txheem:

MP3 Player Nrog Arduino: 6 Kauj Ruam
MP3 Player Nrog Arduino: 6 Kauj Ruam

Video: MP3 Player Nrog Arduino: 6 Kauj Ruam

Video: MP3 Player Nrog Arduino: 6 Kauj Ruam
Video: TonUINO - Arduino-RFID-MP3-Player 2024, Kaum ib hlis
Anonim
Image
Image
Cov ntaub ntawv
Cov ntaub ntawv

Hauv qhov kev sib dhos no, peb tau siv lub mp3 player nrog Arduino Uno, lub tshuab PAM8403 lub suab nrov me me nrog kev hloov kho ntim, ib qho mp3 module DFPlayer Mini, thiab ib khub ntawm 3-Watt hais lus.

Cov phiaj xwm no ua haujlwm tsis yog rau cov neeg ua suab paj nruag nkaus xwb, tab sis kuj tseem tso cai lub suab rau lub chaw nres tsheb nres lossis cov neeg hlau, thiab lwm yam. Cov rooj sib tham no yuav tso cai rau tso cov suab kaw hauv cov khoom siv. Lub suab no yuav yog ntuj tsim thiab tsis tsim tawm. Rau cov neeg feem coob, cov no yog cov yam ntxwv zoo dua piv rau lwm txoj hauv kev.

Rau qhov kev sib dhos no, peb tau hais tshwj xeeb siv Arduino Uno, tab sis koj tseem tuaj yeem txuas rau ESP8266 lossis ESP32. Pom tseeb, yuav tsum muaj kev hloov pauv ntawm tus pin.

Kauj ruam 1: Cov ntaub ntawv

Kauj Ruam 2: DFPlayer Module

DFPlayer Module
DFPlayer Module

DFPlayer module siv kev sib txuas lus txuas RX TX, VCC, GND. Nws muaj cov zis rau ob tus neeg hais lus thiab lub suab tawm tswv yim.

Kauj Ruam 3: Mini Amplifier PAM8403

Mini Amplifier PAM8403
Mini Amplifier PAM8403

Kauj ruam 4: Sib dhos

Los ua ke
Los ua ke

Kauj ruam 5: Cov tsev qiv ntawv

Tsev qiv ntawv
Tsev qiv ntawv

Ntxiv cov ntawv hauv qab no "DFRobotDFPlayerMini" rau kev sib txuas lus nrog lub mp3 module.

Cias nkag mus rau "Sketch >> suav nrog Tsev Qiv Ntawv >> Tswj Tsev Qiv Ntawv …"

Kauj ruam 6: Source Code

Peb yuav pib los ntawm kev txhais cov tsev qiv ntawv thiab qhov peb yuav siv nrog peb cov cai.

Pib los ntawm kev tsim ib qho khoom, cov software txuas, thiab lwm qhov, uas yog myDFPlayer.

Qhov sib txawv ntawm buf, uas yog hom String, yuav ua haujlwm khaws cov ntaub ntawv los ntawm Arduino Serial, uas yuav yog cov lus txib rau MP3 module. Qhov "ncua" qhov sib txawv yuav raug siv los qhia yog tias lub suab nkauj tab tom ua si lossis ncua (ncua = muaj tseeb, thiab qhia tias nws tau raug ncua, txwv tsis pub nws ua si).

#include "SoftwareSerial.h" #include "DFRobotDFPlayerMini.h" // Inicia a serial por software nos pinos 10 e 11 SoftwareSerial mySoftwareSerial (10, 11); // RX, TX // Objeto responsável pela comunicação com o módulo MP3 (DFPlayer Mini) DFRobotDFPlayerMini myDFPlayer; // variável responsável por armazenar os comandos enviados para controlar o player String buf; // variável responsável por armazenar o estado do player (0: tocando; 1: pausado) boolean pausa = tsis tseeb; // variável responsável por armazenar o estado da equalização // varia de 0 a 5 int equalizacao = 0; // (0 = Normal, 1 = Pop, 2 = Rock, 3 = Jazz, 4 = Classic, 5 = Bass) "// variável responsável por armazenar o total de músicas presentes no SD card. Int maxSongs = 0;

Teeb

Hauv cov kauj ruam no, peb muab cov kev xaiv luam tawm los muab qhia rau koj tias nws tau teeb tsa lub Circuit Court, nrog rau kev tshuaj xyuas cov xwm txheej tsis raug, piv txwv.

teeb tsa tsis muaj dab tsi () {// Comunicacao serial com o modulo mySoftwareSerial.begin (9600); // Inicializa serial do Arduino Serial.begin (115200); // Verifica se o modulo esta respondendo e se o // cartao SD foi encontrado Serial.println (); Serial.println ("DFRobot DFPlayer Mini"); Serial.println ("Txheeb xyuas qhov tseeb DFPlayer … (3 ~ 5 segundos)"); yog (! myDFPlayer.begin (mySoftwareSerial)) {Serial.println ("Nao inicializado:"); Serial.println ("1. Cheque as conexoes do DFPlayer Mini"); Serial.println ("2. Insira um cartao SD"); thaum (muaj tseeb); } Serial.println (); Serial.println ("Modulo DFPlayer Mini inicializado!"); // Definicoes iniciais myDFPlayer.setTimeOut (500); // Timeout serial 500ms myDFPlayer.volume (10); // Volume 10 vai de 0 a 30 myDFPlayer. EQ (0); // Equalizacao normal // recupera o numero de Músicas encontradas no SD. maxSongs = myDFPlayer.readFileCounts (DFPLAYER_DEVICE_SD); Serial.println (); Serial.print ("Numero de arquivos tsis muaj cartao SD:"); Serial.println (maxSongs); // Mostra o menu de comandos menu_opcoes ();

Ntawv qhia zaub mov

Koj tswj hwm qhov kev sib dhos no tag nrho los ntawm cov saib. Yog li txhua lub sijhawm, cov phiaj xwm yuav luam tawm Cov Ntawv Qhia Xaiv Koj muaj, nrog cov lus txib, cov lus qhia.

void menu_opcoes () {Serial.println (); Serial.println ("Comandos:"); Serial.print ("[1-"]; Serial.print (maxSongs); Serial.println ("] Para selecionar o arquivo MP3"); Serial.println ("[s] parar reproducao"); Serial.println ("[p] pausa/txuas ntxiv mus rau musica"); Serial.println ("[e] seleciona equalizacao"); Serial.println ("[+ lossis -] aumenta ou diminui o volume"); Serial.println (); }

Loop

void loop () {// Aguarda a entrada de dados pela serial thaum (Serial.available ()> 0) {// recupera os dados de entrada buf = Serial.readStringUntil ('\ n'); // Reproducao (dandice da música) yog ((buf.toInt ()> = 1) && (buf.toInt () <= maxSongs)) {Serial.print ("Reproduzindo musica:"); Serial.println (buf.toInt ()); myDFPlayer.play (buf.toInt ()); // dá play na música menu_opcoes (); } // Pausa/Continua a musica if (buf == "p") {if (pausa) {Serial.println ("Continua musica …"); myDFPlayer.start (); } lwm {Serial.println ("Musica pausada …"); myDFPlayer.pause (); } pausa =! pausa; menu_opcoes (); cov. } // Parada yog (buf == "s") {myDFPlayer.stop (); Serial.println ("Musica parada!"); menu_opcoes (); cov. } // Seleciona equalizacao yog (buf == "e") {equalizacao ++; yog (equalizacao == 6) {equalizacao = 0; } myDFPlayer. EQ (sib npaug sib npaug); Serial.print ("Equalizacao:"); Serial.print (sib npaug sib npaug); Serial.println ("(0 = Li qub, 1 = Pop, 2 = Pob Zeb, 3 = Jazz, 4 = Classic, 5 = Bass)"); menu_opcoes (); cov. } // Aumenta ntim yog (buf == "+") {myDFPlayer.volumeUp (); Serial.print ("Ntim atual:"); Serial.println (myDFPlayer.readVolume ()); menu_opcoes (); cov. } // Diminui ntim yog (buf == "-") {myDFPlayer.volumeDown (); Serial.print ("Ntim atual:"); Serial.println (myDFPlayer.readVolume ()); menu_opcoes (); cov. }} // thaum} // voj

Pom zoo: