Advice on Mp3 player shield interfaced with E18-D80NK IR sensor (FIXED/UPDATED)

Hi everyone,

I am trying to trigger a single sample off the Sparkfun Mp3 player shield using a sensor as input. In this example I am talking about the E18-d80NK, as it returns just 0's and 1's as opposed to going through conditional statements or whatever using a rangefinder etc, but I have a number of other sensors so if you think it will work better with one of them I am open to suggestions. I have got the sample loaded and mp3 shield working with example patches, and the sensor working, but both in isolation of each other.

I have done similar things before, but always interfaced with maxuino and this time that is not an option. I have been going crazy trying to make it work for over a week but so far no luck, even using the various other very similar projects posted around the web.

This is where I have got to splicing various other pieces together, I tried to go step by step as simple as possible but it just wont work, I figured it was time to ask the experts!

// libraries
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
 
// initialize MP3 card
SdFat sd;
SFEMP3Shield MP3player;
 
// constant variables  
     
    int inputPin = 5;                    // IR sensor input pin
    unsigned long pauseTime = 10000;     // how long the pause will be after music turned off
    int readingInterval = 10;            // interval to read the sensor
 
   
// changing variables  
 
    int trigger = 1;                     // variable for pin status
    byte result;                         // variable for mp3 player shield, can be used to debug

        
// setup     
     
    void setup() {
      pinMode(inputPin, INPUT);                        // make sensor an input
      digitalWrite(inputPin, HIGH);                    // activate internal pull-up resistor
      result = MP3player.begin();                      // start mp3 player shield
      MP3player.setVolume(10, 10);                     // set volume of the mp3 player 
      

  
    } 


// loop
     
    void loop(){ 
      
      trigger = digitalRead(inputPin);                 // read sensor
      if (trigger == 0) {                              // if sensed
          result = MP3player.playTrack(1);      // play track                          
          delay(pauseTime);                            // wait...   
          
          
        
    }
      delay(readingInterval);                          // wait with reading
   }

Thanks in advance, too much sleep has already been lost.

Jack

Hi guys, managed to work it out with a fun all night coding experience.

Here is my updated and very messy code, I have it working with 3 sensors, two E18's on the digital inputs and a sharp distance on the analog.

Any additional advice to make it cleaner or anything would be greatly appreciated.

But I did it! (patting myself on back)

Cheers

// libraries
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
 
// initialize MP3 card
SdFat sd;
SFEMP3Shield MP3player;
 
// constant variables  
     
    int inputPin = 0;                    // IR sensor input pin
    unsigned long pauseTime = 5000;     // how long the pause will be after music turned off
    int readingInterval = 10;     // interval to read the sensor
    int SignalPin=5;
    int SignalPin2=4;
    #define SignalPin 5
    #define SignalPin2 4
    
   
   
  


        
// setup     
     
    void setup() {
      Serial.begin(9600);
      sd.begin(SD_SEL, SPI_HALF_SPEED);
      MP3player.begin();
      MP3player.setVolume(10, 10);                     
      pinMode(inputPin, INPUT);
      pinMode(SignalPin, INPUT);
      
      

  
    } 


// loop
     
    void loop(){
      if (analogRead(inputPin) > 450)       {                             
          MP3player.playTrack(2);                          
          delay(pauseTime);     
                  
   
   
      }
      {
      {  
      int Signal = 1;

  Signal = digitalRead(SignalPin);
  
  if (Signal == 1){
    Serial.print (Signal);
    Serial.println("  no obstacle");
  }
  
  else {
    MP3player.playTrack(1);                          
          delay(pauseTime); 
  }
  
      }
    
      {
    int Signal = 1;

  Signal = digitalRead(SignalPin2);
  
  if (Signal == 1){
    Serial.print (Signal);
    Serial.println("  no obstacle");
  }
  
  else {
    MP3player.playTrack(2);                          
          delay(pauseTime); 
  }
    
   
      }
      } 
    
      
      delay(readingInterval);                          // wait with reading
      
  
    
      }