MP3 Shield coding PIR sensor

Hello Guys,

I want my arduino with MP3 shield to play a song (1 song) when a PIR sensor detects movement. I have found some projects who look a lot like my project (used that code). The difference with my project is that the other projects played a random song when movement was detected. When I ran the code below (no faults where noticed by arduino) I got no music :frowning: I know it's not the hardware because my PIR sensor worked with a LED and my MP3 Shield worked with the serial monitor. Can you guys help me with this? ( I'm not an experienced programmer).

#include <SFEMP3Shield.h>
#include <SFEMP3ShieldConfig.h>
#include <SFEMP3Shieldmainpage.h>

#include <ArduinoStream.h>
#include <bufstream.h>
#include <ios.h>
#include <iostream.h>
#include <istream.h>
#include <MinimumSerial.h>
#include <ostream.h>
#include <Sd2Card.h>
#include <SdBaseFile.h>
#include <SdFat.h>
#include <SdFatConfig.h>
#include <SdFatmainpage.h>
#include <SdFatStructs.h>
#include <SdFatUtil.h>
#include <SdFile.h>
#include <SdInfo.h>
#include <SdSpi.h>
#include <SdStream.h>
#include <SdVolume.h>

#include <SPI.h>

SFEMP3Shield MP3player;
SdFat sd;
//   
// constant variables  
     
    int pirPin = 5;                    // PIR sensor input pin
    int calibrationTime = 10;   
    unsigned long playTime = 150000;      // 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 
                       // find random number
          result = MP3player.playTrack(1);      // 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
       }      
   }

That is
just about
the crappiest
indenting
I've seen
this month.

Use Tools + Auto Format to fix that. Delete code that is irrelevant, like the call to randomSeed() and the useless comment about getting a random number (you don't). Post your code again.