Pages: [1]   Go Down
Author Topic: Motion Activated MP3 Shield(Help!!)  (Read 2129 times)
0 Members and 1 Guest are viewing this topic.
Malaysia
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Nobbie,first time
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,i am a FNG in the world of arduino and i despreatly  need help. My project is about the PIR sensor detecting motion and sending it to the Arduino Uno which will trigger the MP3 Shield,i have the code from online but how do u add the libraries to the sketch?
*/   

// libraries

    #include <SPI.h>
    #include <SdFat.h>
    #include <SdFatUtil.h>
    #include <SFEMP3Shield.h>
    SFEMP3Shield MP3player;

 
// constant variables 
     
    int pirPin = 5;                    // PIR sensor input pin
    int calibrationTime = 10;   
    unsigned long playTime = 15000;      // how long a file will play in milliseconds (15000=15 seconds)
    unsigned long pauseTime = 10000;     // how long the pause will be after the sound ends (10000=10 seconds)
    int readingInterval = 20;            // how often to read the sensor
 
   
// changing variables 
 

    int rantrack = 0;                    // track number for randomizing
    unsigned long currentMillis = 0;     // time variable to track running time: current time
    unsigned long startingMillis = 0;    // time variable to track running time: starting time
    byte result;                         // variable for mp3 player shield, can be used to debug
       
// setup     
     
    void setup() {
  pinMode(pirPin, INPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
    for(int i = 0; i < calibrationTime; i++){
      delay(1000);
      }
    delay(50);

     pinMode(pirPin, INPUT);                        // make PIR sensor an input
      digitalWrite(pirPin, LOW);                    // activate internal pull-up resistor
      result = MP3player.begin();                      // start mp3 player shield
      MP3player.SetVolume(10, 10);                     // set volume of the mp3 player ( 0 = loudest )
    }
// loop
     
    void loop(){
      if (digitalRead(pirPin)== HIGH) {                // if movement sensed
          randomSeed(millis());                        // set a more random seed for the random function
          rantrack = random(55);                       // find random number
          result = MP3player.playTrack(rantrack);      // play track                         
          playtime();                                  // call function for play time       
         MP3player.stopTrack();                        // stop track   
          delay(pauseTime);                            // wait...   
    }
     
      delay(readingInterval);                          // wait with reading
   } 


// function to determine playtime

  void playtime() {
       startingMillis = millis();                                 // set both time counter
       currentMillis = millis();
      while ( currentMillis - startingMillis < playTime ) {      // while track plays, runs until playTime is reached
          currentMillis = millis();                               // set to actual time
          delay(40);                                              // debounce
       }     
   }

the help i need is in this:

    #include <SdFat.h>
    #include <SdFatUtil.h>
    #include <SFEMP3Shield.h>
    SFEMP3Shield MP3player;
how do i add these??Please URGENTLY reply!!
Thank You


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i have the code from online but how do u add the libraries to the sketch?
Use #include statements to add the header files.

If the header file defines a class, you need to create one (or more) instance(s) of the class.

Quote
the help i need is in this:

    #include <SdFat.h>
    #include <SdFatUtil.h>
    #include <SFEMP3Shield.h>
    SFEMP3Shield MP3player;
how do i add these??
Just like in your sketch.

Quote
Please URGENTLY reply!!
When is our homework due? Why did we wait until the last minute? What is the problem we are trying to address?
Logged

Malaysia
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Nobbie,first time
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have added these libraries To the sketch,figured it out but thanks anyway!i was trying to do it on my own but times running out and I am desperate!!my project is exactly the same with the YouTube video Arduino Cemetry Howler Project,i got the hardware down,I need help with the software.I followed the guys links ,but where do I name the tracks? Plz help!!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but where do I name the tracks?
I don't understand this question. The MP3 player library has a playTrack() method which plays the file named trackXXX.mp3 where XXX is supplied argument, or a playMP3() method that plays the named file.
Logged

Malaysia
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Nobbie,first time
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wat I mean is,in the SD card I name the track001.mp3,in the code where do I also name the track In the MP3 library?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Wat I mean is,in the SD card I name the track001.mp3,in the code where do I also name the track In the MP3 library?
You can play that file using either:
Code:
MP3player.playTrack(1);
or
Code:
MP3player.playMP3("track001.mp3");
Logged

Malaysia
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Nobbie,first time
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I mean do I write playmp3"track00" where!!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I mean do I write playmp3"track00" where!!
What have you tried? The code you posted back at the beginning played a random track. Replacing the call to playTrack() with the call to playMP3(), to play a specific track, is trivial.
Logged

Malaysia
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Nobbie,first time
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okok,based on the code I posted earlier with the said libraries will the code work?i need some one to verify it first?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Okok,based on the code I posted earlier with the said libraries will the code work?
Yes. Whether it does what you want, or not, is a different question.

Only you have the hardware, so only you can answer the new question.

Quote
i need some one to verify it first?
Why? You can verify it yourself.
Logged

Malaysia
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Nobbie,first time
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't tell whether the codes are in order,cause i got them online and I fun know programming!all the code suppose to do is receive the input for the PIR sensor and activate a random track on the shield
Logged

Pages: [1]   Go Up
Jump to: