Arduino mp3 shield with ultrasonic sensor

Hello, I am trying to play an mp3 file with an mp3 s :pray:hield from sparkfun and an ultrasonic sensor for a school project. I an very new to this stuff and have no idea what I am doing. I got this code off the internet and I got an error saying I don't have SdFat.h and so I downloaded the library for that, but now I don't have SdFatUtil.h and I can't find the library for it and its not in the SdFat library. Can someone please tell me where to find this. :pray:

Code that I found on the internet (no idea if this is actually what I need)

\
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h> 
#include <SFEMP3Shield.h>


/*
 *This project triggers an MP3 when a short-range ultra-sonic 
 *sensor is triggered. Tested on a VS1053 MP3 shield and 
 *Virtuabotix ultrasonic distance rangefinder.
 */
SdFat sd;
SFEMP3Shield MP3player;

#define trigPin 5
#define echoPin 4

void setup() {

  Serial.begin(9600);
  delay(3000);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  //start the shield
  sd.begin(SD_SEL, SPI_HALF_SPEED);
  MP3player.begin();
  MP3player.setVolume(0);

}

void loop() {
  long duration, distance;
  long avgDistance = 0;
  /*
   *Currently receiving an invalid reading every fourth attempt.
   *This loop averages out the readings to compensate for this.
   */
  for(int i=0; i<4; i++){
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    //Convert to centimeters
    distance = (duration/2)/29;
    //Serial.print(distance);
    //Serial.println("cm");
    avgDistance += distance;
    delay(50);
  }
  avgDistance = (avgDistance/4);
  Serial.print(avgDistance);
  Serial.println("cm");
  if(avgDistance < 20 && avgDistance > 0){
    //Tracks need to be named in the following manner on the sd card:
    //track00x.mp3, where x is the track number. Track 1 is being played below.
    MP3player.playTrack(1);
    delay(20000);
  }
}

websearch
sdfatutil.h
SD/SdFatUtil.h at master ยท arduino-libraries/SD ยท GitHub

How do I use this

@harrypotter72, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

Use what?
Install the library?
Make use of the code you copied?

Actually, I am still getting SdFatUtil.h no such file or directory. Im not actually sure if the library was added.

That library is a higher order library utility, install the full library and I assume you will have access to it.

I did download the entire SD-master library but I don't know how to add it. :cry:

In the IDE menu : Program / include library /add zip library and look for it where the download was made.

I do that and it doesn't show up anywhere and I still get the error. I then go to: file / preferences / then select the file and location but nothing happens, other than I am now getting the SdFat.h no file found error, but I have also downloaded that library as well.

The IDE ("the Arduino program") should be Closed when installing a library 'manually'.
If the IDE is 'up' and a library is installed manually, the 'IDE' will not find it till it's re-started.

I restart Arduino and I still can't find where the library is.

I don't have the Arduino mp3 shield, so I can't test it and its libraries. But in what little I have seen on the net, the SdFat.h library is used but not the SdFatUtil.h.

I advise you to examine this PAGE thoroughly and try to execute some example of the ones that the library that indicates to use brings, once it works, adding the ultrasonic sensor will be an easy task.

So how do I change my code so it soesn't use 'SdFatUtil.h'?

c:\program files (x86)\arduino\libraries

How do I edit the code so that the code doesn't use 'SdFatUtil.h'?
Also, when I go to add a library I do this : sketch / include library / add .ZIP library / downloads (that is where the file is) / select SD-master (I have tried this with and without extracting the files)
and either way I end up not seeing the library in added libraries.

when I go to program files I don't have an arduino option

program files (x86)

Ok, I have finally figured out how to got the libraries into my sketches and it is using the sketch book, just manually moving the files over to the sketchbook folder in files, opening up arduino and bam, it works.
Thank you all for your help, it was much appreciated. :heart:
(I am just editing this post because I am out of new posts for today).

You do know what the blindingly obvious problem is here, don't you? :roll_eyes:

Wouldn't it be nice if the forum admins would actually :face_with_raised_eyebrow: fix it?

Muggle Potter, please read the instructions. :grin:

1 Like