mp3-trigger

Hi, Im working on a project right now. I’m using a ldr sensor to trigger hitec hs-422 motor which in turn should play a sound from the mp3 trigger. The motor is triggered fine but I’m having trouble with the sound. I don’t think there’s a problem with the circuit but maybe is to do with the coding. Here is my code:

#include <Servo.h>
#include <MP3Trigger.h>
#include <SoftwareSerial.h>
#define MOTOR 4 //motor is plugged in to pin 4
#define SENSOR 7 //sensor is plugged in to pin 7
#define LED 13 //LED is plugged in to pin 13

//Mp3 Trigger pin Rx is connected to Arduino's pin Tx
//Power is supplied correctly with Gnd pinned in the right place.


int trigger = 1;//if button's not pressed, trigger = 0, else trigger = 1
MP3Trigger mp3trigger;
SoftwareSerial trigSerial = SoftwareSerial(2,3);
Servo myservo;

void setup()//initializing
{
 mp3trigger.setup(&trigSerial);//sound
 trigSerial.begin(MP3Trigger::serialRate());//sound
 myservo.attach(MOTOR); //motor
 pinMode(LED , OUTPUT); //LED
 pinMode(SENSOR , INPUT); //Sensor
 //setting button(7) as an INPUT
}


int move = 0;//movement of the motor in degrees(angle) initially 0

void loop()
{
  trigger = digitalRead(SENSOR);
  //checks if the button is pressed or not

  if(trigger == 0)//if the sensor detects darkness
  {//move the motor and produce sound
    
   mp3trigger.trigger(1); // the name of the mp3 file in the SD card is TRACK001.mp3 with 128kbps

    digitalWrite(LED , HIGH);//turn on the LED
   
    delay(2000);//wait for 2 sec

    //moves the motor 30 degrees 0 to 30
    //move += 1 increments the value of move by 1
    for(move = 0; move < 30; move += 1)
    {
      myservo.write(move);//move the motor by the given value
      delay(4);//waits for 4ms
    }//end of for
    
    
    //this for loop moves back the position of the motor from 30 degrees to 0
    //move -= 1 decrements value of move by 1
    for(move = 30; move >= 0; move -= 1)
    {
     myservo.write(move);
     delay(5); 
    }
    delay(1000);
  
  }//end of if  
  else
  {
     //turn off LED
    digitalWrite(LED , LOW);
  }
  
  
  //delay(2000);

  
}

All of the examples show a update() method being called. So where is your mp3trigger.update()?

Also, could you change your subject to something useful? "URGENT" doesn't describe anything in this thread.

Can you also use the proper code tags. Modify that post, select the code then hit the # icon and save. You might not think it is the circuit but without seeing it code makes little sense.

You talked about the update() method..but Im not sure where i should be using that method in the code. :( It plays the sound if i press the navigation button on the mp3 trigger board(although not completely).

oddthumb: You talked about the update() method..but Im not sure where i should be using that method in the code. :( It plays the sound if i press the navigation button on the mp3 trigger board(although not completely).

Have you looked at any of the examples? It is pretty obvious. Just make sure it gets called on a regular basis. So, like all of the examples, put it at the start of void loop().

I went through some examples in the MP3Trigger library folder…Wasnt able to find much codings in the internet.

#include <SoftwareSerial.h>
#include <MP3Trigger.h>

SoftwareSerial trigSerial = SoftwareSerial(2, 3);
MP3Trigger trigger;

void setup() {
  // Start serial communication with the trigger (over SoftwareSerial)
  trigger.setup(&trigSerial);
  trigSerial.begin( MP3Trigger::serialRate() );
  
  // Start looping TRACK001.MP3
  trigger.setLooping(true,1);
}

void loop() {
  // process signals from the trigger
  trigger.update();
}

I think you are talking about trigger.update() method here. So I’ve tried to change my codes to work similar to this.

#include <Servo.h>
#include <MP3Trigger.h>
#include <SoftwareSerial.h>

#define MOTOR 4 //motor is plugged in to pin 4
#define SENSOR 7 //button is plugged in to pin 7
#define LED 13


byte track = 100;
int triggerVal = 1;//if button's not pressed, trigger = 0, else trigger = 1
MP3Trigger trigger;
SoftwareSerial trigSerial = SoftwareSerial(2,3);
Servo myservo;

void setup()//initializing
{
 trigger.setup(&trigSerial);
 trigSerial.begin(MP3Trigger::serialRate());
 trigger.setLooping(true,1);
 myservo.attach(MOTOR); 
 pinMode(LED , OUTPUT); 
 pinMode(SENSOR , INPUT); 
 //setting button(7) as an INPUT
}

int move = 0;//movement of the motor in degrees(angle)

void loop()
{

  triggerVal = digitalRead(SENSOR);
  //checks if the button is pressed or not

  if(triggerVal == 0)//if the sensor detects darkness
  {//move the motor
    trigger.update();
    digitalWrite(LED , HIGH);
    
    delay(2000);

    //moves the motor 30 degrees 0 to 30
    //move += 1 increments the value of move by 1
    for(move = 0; move < 30; move += 1)
    {
      myservo.write(move);//move the motor by the given value
      delay(4);//waits for 4ms
    }//end of for
    
    
    //this for loop moves back the position of the motor from 30 degrees to 0
    //move -= 1 decrements value of move by 1
    for(move = 30; move >= 0; move -= 1)
    {
     myservo.write(move);
     delay(5); 
    }
    delay(1000);
  
  }//end of if  
  else
  {
    digitalWrite(LED , LOW);
  }
  
  
}

but it’s still not working.
And I have found out that the code does not play the sound even if i press the navigation button on the MP3Trigger board while motor is moving.
I’m sorry I’m a beginner with arduino…

I’m sorry I’m a beginner with arduino…

And you will remain one until you learn to answer requests about your problem.

void loop() {
    trigger.update();
//... the rest of your code

hmmm, it’s still not working :<
i think i will disconnect it from the arduino and try an get it to work that way first!
thank you for your help James :slight_smile: x