Home Forums Sparkfun MP3 Shield Library Support Forum Mp3 shield and Pir motion detector problem

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3229
    Anonymous
    Inactive

    Hi i can´t get my arduino to play a mp3 song with a Mp3 Shield, pir motion detector and arduino.

    When the detector se a person it should start to play a mp3 song from the MP3 Shield that is conected to the arduino and Pc Speakers. Nothing happens, i get no sound nothing.

    This is my code:

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

    SdFat sd;
    SFEMP3Shield MP3player;
    // Create Mp3 library object
    // These variables are used in the MP3 initialization to set up
    // some stereo options:
    int8_t current_track = 0;
    const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)
    const uint16_t monoMode = 3;  // Mono setting 0=off, 3=max

    const int pirPin = 12;
    long unsigned int lowIn;
    long unsigned int pause = 5000;
    boolean lockLow = true;
    boolean takeLowTime;
    int calibrationTime = 30;
    byte result;

    void setup()
    {
    initSD();  // Initialize the SD card
    initMP3Player(); // Initialize the MP3 Shield
    pinMode(pirPin, INPUT);//led indicator when singing a note
    Serial.begin(9600);
    digitalWrite(pirPin, LOW);
    Serial.print(“calibrating sensor “);
    sd.begin(9, SPI_HALF_SPEED);
    MP3player.setVolume(10, 10);

    for(int i = 0; i < calibrationTime; i++)
    {
    Serial.print(“.”);
    delay(100);
    }
    Serial.println(” done”);
    Serial.println(“SENSOR ACTIVE”);
    delay(50);

    }

    void loop()
    {
    MP3player.available();
    if (digitalRead(pirPin) == HIGH)
    {
    if(lockLow)
    {
    lockLow= false;
    Serial.println(“—“);
    Serial.println(“001″);
    Serial.print(millis()/1000);
    Serial.println(” sec”);
    MP3player.playTrack(1);

    delay(50);
    }
    takeLowTime = true;
    }

    if(digitalRead(pirPin) == LOW)
    {
    lowIn = millis();
    takeLowTime = false;
    }
    if(!lockLow && millis() -lowIn > pause)
    {
    lockLow = true;
    Serial.print(“motion ended at “);
    Serial.print((millis() – pause)/1000);
    Serial.println(” sec”);
    MP3player.stopTrack();
    delay(50);
    }
    }

    void initSD()
    {
    //Initialize the SdCard.
    if(!sd.begin(SD_SEL, SPI_HALF_SPEED))
    sd.initErrorHalt();
    if(!sd.chdir(“/”))
    sd.errorHalt(“sd.chdir”);
    }

    void initMP3Player()
    {
    uint8_t result = MP3player.begin(); // init the mp3 player shield
    if(result != 0) // check result, see readme for error codes.
    {
    // Error checking can go here!
    }
    MP3player.setVolume(volume, volume);
    MP3player.setMonoMode(monoMode);
    }

    my e mail is Lill_henge@hotmail.com if u want to send answer there or u can send it here!

     

     

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.