Devices & Components
Arduino Nano
Jumper wire
Df player mini
SD Card
Card Board
Hard metal wire
1 k Resistors
3.7volt battery
3 watt Speaker
10 k Resistors
Project description
Code
Code
arduino
1#include "SoftwareSerial.h" 2#include "DFRobotDFPlayerMini.h" 3 4// Use pins 2 and 3 to communicate with DFPlayer Mini 5static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX 6static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX 7SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX); 8 9const int wirePin = 4; 10const int endPin = 5; 11 12// Create the Player object 13DFRobotDFPlayerMini player; 14 15void setup() { 16 17pinMode(wirePin, INPUT); 18pinMode(endPin, INPUT); 19 20 // Init USB serial port for debugging 21 Serial.begin(9600); 22 // Init serial port for DFPlayer Mini 23 softwareSerial.begin(9600); 24 25 // Start communication with DFPlayer Mini 26 if (player.begin(softwareSerial)) { 27 Serial.println("OK"); 28 29 // Set volume to maximum (0 to 30). 30 player.volume(30); 31 // Play the first MP3 file on the SD card 32 player.play(1); 33 } else { 34 Serial.println("Connecting to DFPlayer Mini failed!"); 35 } 36} 37 38void loop() { 39 40 if (digitalRead(wirePin) == HIGH) { 41 player.play(2); 42 delay(5000); 43 44 } 45 if (digitalRead(endPin) == HIGH) { 46 player.play(3); 47 delay(5000); 48 49 } 50 } 51
Code
arduino
1#include "SoftwareSerial.h" 2#include "DFRobotDFPlayerMini.h" 3 4// Use pins 2 and 3 to communicate with DFPlayer Mini 5static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX 6static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX 7SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX); 8 9const int wirePin = 4; 10const int endPin = 5; 11 12// Create the Player object 13DFRobotDFPlayerMini player; 14 15void setup() { 16 17pinMode(wirePin, INPUT); 18pinMode(endPin, INPUT); 19 20 // Init USB serial port for debugging 21 Serial.begin(9600); 22 // Init serial port for DFPlayer Mini 23 softwareSerial.begin(9600); 24 25 // Start communication with DFPlayer Mini 26 if (player.begin(softwareSerial)) { 27 Serial.println("OK"); 28 29 // Set volume to maximum (0 to 30). 30 player.volume(30); 31 // Play the first MP3 file on the SD card 32 player.play(1); 33 } else { 34 Serial.println("Connecting to DFPlayer Mini failed!"); 35 } 36} 37 38void loop() { 39 40 if (digitalRead(wirePin) == HIGH) { 41 player.play(2); 42 delay(5000); 43 44 } 45 if (digitalRead(endPin) == HIGH) { 46 player.play(3); 47 delay(5000); 48 49 } 50 } 51
Downloadable files
Diagram
Diagram

Comments
Only logged in users can leave comments