Dfplayer mini sound module

I am in the process of making a sound module for my son's car but after several weeks of struggle. anyone who can help. It must be like this when he presses the accelerator (the switch) which secures the buckle when the car is moving. and that would mean reach the arduino for a HIGH signal the motor sound should run and LOW it should switch off / pause

using arduino uno


> #include "SoftwareSerial.h"`
> SoftwareSerial mySerial(1, 0);
> # define Start_Byte 0x7E
> # define Version_Byte 0xFF
> # define Command_Length 0x06
> # define End_Byte 0xEF
> # define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
> # define ACTIVATED LOW
> int buttonNext = 2;
> int buttonPlay = 3;
> int buttonPrevious = 4;
> boolean isPlaying = false;
> void setup () {
>   pinMode(buttonPlay, INPUT);
>   digitalWrite(buttonPlay, HIGH);
>   pinMode(buttonNext, INPUT);
>   digitalWrite(buttonNext, HIGH);
>   pinMode(buttonPrevious, INPUT);
>   digitalWrite(buttonPrevious, HIGH);
>   mySerial.begin (9600);
>   delay(1000);
>   playFirst();
>   isPlaying = true;
> }
> void loop () {
>   if (digitalRead(buttonPlay) == ACTIVATED)
>   {
>     if (isPlaying)
>     {
>       play();
>       isPlaying = false;
>     } else
>     {
>       isPlaying = true;
>       play();
>     }
>   }
>   if (digitalRead(buttonNext) == ACTIVATED)
>   {
>     if (isPlaying)
>     {
>       playNext();
>     }
>   }
>   if (digitalRead(buttonPrevious) == ACTIVATED)
>   {
>     if (isPlaying)
>     {
>       playPrevious();
>     }
>   }
> }
> void playFirst()
> {
>   execute_CMD(0x3F, 0, 0);
>   delay(500);
>   setVolume(27);
>   delay(500);
>   execute_CMD(0x11, 0, 1);
>   delay(500);
> }
> 
> void pause()
> {
>   execute_CMD(0x0E, 0, 1);
>   delay(500);
> }
> 
> void play()
> {
>   execute_CMD(0x0D, 0, 1);
>   delay(500);
> }
> void playNext()
> {
>   execute_CMD(0x01, 0, 1);
>   delay(500);
> }
> void playPrevious()
> {
>   execute_CMD(0x02, 0, 1);
>   delay(500);
> }
> void setVolume(int volume)
> {
>   execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
>   delay(2000);
> }
> void execute_CMD(byte CMD, byte Par1, byte Par2)
> // Excecute the command and parameters
> {
>   // Calculate the checksum (2 bytes)
>   word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
>   // Build the command line
>   byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
>                             Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte
>                           };
>   //Send the command line to the module
>   for (byte k = 0; k < 10; k++)
>   {
>     mySerial.write( Command_line[k]);
>   }
> }

What Arduino are you using? On most Arduino boards, pins 0 and 1 are the hardware serial and it makes no sense to use those pins for software serial.

Your improperly posted code is hard to read and follow with no formatting. And are the defines really in bold or did the forum software misinterpret your post because of the lack of code tags?

Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.

What does the code actually do that is different from what you want?

A schematic would help, too. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.

I'm new here on the site, so I just have to learn. Thanks fixed it

Those > signs make it so that the code will not compile. Please remove them if you want help.

There is an extra ` at the end of that statement that is causing a warning. You do have compile warnings enabled in the IDE, File , Preferences, don't you. It is important to know of and deal with warnings.

I suggest that you move the software serial to different pins so that you can open and use the hardware serial port for debugging. Insert serial prints at strategic points in the code to follow code execution and monitor variable values.

I will wait for a schematic and description of what the code is doing.

@NHPoulsen

Definitely don't use pins 1 and 0. I've used a dfplayer a bit, you are best off following this diagram:
kit_m87_mp3_1

Make sure you have that resistor in or it will not work at all. I've noticed that it works best when you use the software serial on pins that have the ~ symbol next to them.

Certainly use serial prints. If you have a clone DFPlayer mini, Serial print will be your best friend. The clones can be a little touchy especially regarding the SD card.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.