본문 바로가기

아두이노우노 R4

Arduino Uno, DFPlayer Mini 및 푸시 버튼 사용 오디오 재생

반응형

 

Arduino Uno, DFPlayer Mini 및 푸시 버튼을 사용하여 미리 선택된 오디오 재생 

 

이 흥미진진한 튜토리얼에서는 아두이노 우노와 DF플레이어 미니를 사용하여 맞춤형 사운드보드를 제작함으로써 DIY 전자제품의 세계로 뛰어들게 됩니다. 초보자든 숙련된 제작자든 이 프로젝트는 여러분에게 완벽합니다!

 

아두이노 우노와 DFPlayer 미니 모듈을 연결하고 푸시 버튼을 통합하여 좋아하는 사운드를 트리거하는 단계별 과정을 안내해 드립니다. 사운드보드에 생명을 불어넣는 필수 코딩 기술과 배선 팁을 배우게 됩니다.

 

배울 내용:

  •  Arduino Uno 및 DFPlayer Mini 설정 방법
  • 원활한 설정을 위한 배선도 및 회로 연결
  • 사운드 재생을 제어하기 위한 Arduino 프로그래밍
  • 사운드 보드용 사운드 파일 사용자 지정
  • 일반적인 문제 해결을 위한 팁

준비물

  •  아두이노 우노
  • DFPlayer 미니 MP3 플레이어 모듈
  • 푸시 버튼
  • 스피커
  • 점퍼 와이어
  • 저항
  • 브레드보드 (옵션)

 

 

연결도

 

 

 

Arduino Code

 

 

/* 
To create audio: https://ttsmaker.com/
DFPlayer module supports up to 3W. 
SD card: 2GB ~ 32GB formatted with FAT or FAT32. 
MP3 / WAV - audio files. 
*/

#include "SoftwareSerial.h"         // Include the SoftwareSerial library for serial communication
#include "DFRobotDFPlayerMini.h"    // Include the DFRobotDFPlayerMini library for the DFPlayer Mini module

SoftwareSerial mySoftwareSerial(10, 11); // Create a software serial connection on pins 10 (RX) and 11 (TX)
DFRobotDFPlayerMini myDFPlayer;          // Create a DFPlayerMini object

const int pushButtonPin = 2;        // Define the pin number for the push button
bool buttonState;                   // Variable to store the state of the button
bool wasButtonPressed = false;      // Flag to track whether the button was previously pressed

void setup() {
  mySoftwareSerial.begin(9600);     // Start software serial communication at 9600 baud rate
  Serial.begin(115200);             // Start serial communication at 115200 baud rate
  pinMode(pushButtonPin, INPUT_PULLUP); // Set push button pin as input with internal pull-up resistor
  
  if (!myDFPlayer.begin(mySoftwareSerial)) { // Initialize the DFPlayer Mini module
    Serial.println(F("Not initialized:"));
    Serial.println(F("1. Check the DFPlayer Mini connections"));
    Serial.println(F("2. Insert an SD card"));
    while (true);                  // If initialization fails, print error messages and halt the program
  }
  
  Serial.println();
  Serial.println(F("DFPlayer Mini module initialized!")); // Print initialization success message
  myDFPlayer.setTimeOut(500);       // Set the timeout value for serial communication
  myDFPlayer.volume(30);            // Set the volume level (0 to 30)
  myDFPlayer.EQ(0);                 // Set the equalizer setting (0: Normal, 1: Pop, 2: Rock, 3: Jazz, 4: Classic, 5: Bass)
}

void loop() {
  buttonState = digitalRead(pushButtonPin); // Read the state of the button

  if (buttonState == LOW) {          // If the button is pressed (assuming pull-up configuration)
    if (!wasButtonPressed) {         // If the button was not previously pressed
      Serial.println("Playing song 1");
      myDFPlayer.play(3);            // Play the third audio file on the SD card
      delay(2000);                   // Delay for 2 seconds

      wasButtonPressed = true;       // Set the flag to true to indicate that the button was pressed
    }
  } else {                           // If the button is not pressed
    Serial.println("Push button not pressed");
    wasButtonPressed = false;        // Reset the flag when the button is released
  }
}

 

 

유튜브 영상 참고 

다양한 튜토리얼 참고

 

 

반응형

더욱 좋은 정보를 제공하겠습니다.~ ^^