Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« on: November 16, 2012, 10:00:27 pm » |
Hi,I am new to arduino and have no experince in c programming,my project involves an motion sensor detecting motion and activating the MP3 shield to ply a random track through the Arduino UNO,I have compiled codes I have found online together,I got the hardware together I just need help in software area.
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #1 on: November 16, 2012, 10:07:20 pm » |
#include <SdFat.h> #include <SdFatUtil.h> #include <SPI.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 } }
this is the code i have compiled to randomly play any track when motion is detected,all of it i found online!:D now i am going to name the tracks in the SD card track000.mp3 and etc. The problem i am having is where do i change in the code for these names?? I got the libraries online. I am on a deadline and a prompt answer is very much appreciated Thanks ,Newbie
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #2 on: November 17, 2012, 12:47:49 am » |
Please you code tags (#) they work wonders for everyone! Here see if this helps, it's rather detailed. http://garagelab.com/m/blogpost?id=6484258%3ABlogPost%3A5856
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #3 on: November 17, 2012, 02:20:09 am » |
ive downloaded the SDFIle,but when i extract everything i cant find the Sd2PinMap.h file??
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #4 on: November 22, 2012, 03:34:42 am » |
The code compiler successfully but there is no sound playing!how long must I w8 for the sensor to calibrate itself?
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #5 on: November 22, 2012, 01:24:48 pm » |
Maybe it has an internal volume that has to be set.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #6 on: November 22, 2012, 09:34:25 pm » |
I've set the volume and everything,I've changed the chip select from 10 to 9,and the code uploads fine but it cannot ply.!!
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #7 on: November 22, 2012, 10:58:40 pm » |
Does it know what your tracks are labeled, because it takes a certain format like track001 ,002 ,003 and so on. Some have different formats but it is relatively the same.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #8 on: November 23, 2012, 06:08:11 am » |
I only uploaded one track to tr SD card to test it out first,I've made the changes in te code ran track from 55 to 1 and I named it track001.mp3
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #9 on: November 23, 2012, 03:32:07 pm » |
Maybe the track itself needs to be named track1.where did you get your mp3 shield, it may need its own code and not a generic code from on line. You need to find everything you can about your mp3 shield.
If you have a link to your shield and ITS code post it.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Malaysia
Offline
Newbie
Karma: 0
Posts: 19
Nobbie,first time
|
 |
« Reply #10 on: November 24, 2012, 05:34:45 am » |
All tutorial I've read states that the track should be named track000.mp3-tracknnn.mp3 The mp3 shield is from sparkfun electronics MP3 shield https://www.sparkfun.com/products/10628
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2348
|
 |
« Reply #11 on: November 24, 2012, 06:20:21 am » |
Try a more minimal sketch until you get things going: in setup, just call the begin method on the MP3player object, serial print the return value and then call playMP3 with the filename of your track. Print the return value of this function too. In loop, do nothing. What happens now?
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #12 on: November 24, 2012, 03:25:50 pm » |
take a look at this code, Dont use it but look how it is written, how it calls a track, the volume,etc... http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Dev/Arduino/Shields/MP3_Player_Example_Control.pde
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
|