Go Down

Topic: DFmini player triggered by ldr (Read 162 times) previous topic - next topic

pranghead

Hey guys,

I've built this colour sensor using a simple LDR which senses colour and lights up LEDs depending on which colour it senses. However, I want to use the DFmini mp3 player to play sounds to acompany these lights, but i cant for the life of me figure out how to do it.

Ive tested that the player works using another programme and it does.

Has anyone got any experience with this and could possibly point me in the right diection.

Heres the code that i have, it runs the LDR fine but the speaker not do anything as im not sure how to command it to

Code: [Select]
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

float b;

const int ledPin = 3;
const int ledpinblue = 5;
const int buzzerpin = 7;
boolean isPlaying = false;

#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# 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 HIGH


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode (ledPin, OUTPUT); //red LED
pinMode (ledpinblue, OUTPUT); //blue LED
pinMode (buzzerpin, OUTPUT); //buzzer

mySerial.begin (9600);
delay(1000);
isPlaying = true;

}

void loop() {
  // put your main code here, to run repeatedly:

b=analogRead(A5);
b=b*5/1023;

if(b>=3.0&&b<=3.28) //if LDR reading between these values then red light turns on

{delay (600);
digitalWrite(3,HIGH);}
 
  else{digitalWrite(3,LOW);} // if not it stays off
 
  void playFirst();
{
 


}



if(b>=3.4&&b<4.4)

{delay (200);
digitalWrite(5,HIGH);

tone (buzzerpin, 200); //making the buzzer tone
delay (200);
noTone (buzzerpin);

(digitalRead(b>=3.4&&b<3.8) == ACTIVATED);
 
      isPlaying = false;
   
  }

else{digitalWrite(5,LOW);}

Serial.print(" A5 ");Serial.println(b);delay(10);   
}

 
thankyou

slipstick

You don't seem to have any code that even tries to use the DF player. And you have what looks like it's supposed to be a definition of a function "playFirst" in the middle of loop() but it has no code in it.

I'm sure your "another program" that does work the player has some code in there that is useful. So please post a version of your program where you tried to do something with the player...and then tell us what problems it has.

Steve

pranghead

hey,

I managed to get it to work with someone elses code to make an mp3 player, i did it to see if the module worked. Here is the code...

also heres the link to the video i worked from

https://www.youtube.com/watch?v=UodfePdNfg8&t=145s



Code: [Select]
///              MP3 PLAYER PROJECT
/// http://educ8s.tv/arduino-mp3-player/
//////////////////////////////////////////


#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# 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 buttonPause = 3;
int buttonPrevious = 4;
boolean isPlaying = false;



void setup () {

pinMode(buttonPause, INPUT);
digitalWrite(buttonPause,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(buttonPause) == ACTIVATED)
  {
    if(isPlaying)
    {
      pause();
      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(20);
  delay(500);
  execute_CMD(0x11,0,1);
  delay(500);
}

void pause()
{
  execute_CMD(0x0E,0,0);
  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]);
}[/code]
}


cheers


Go Up