I Biocowed an mp3 player and connected it to the arduino. When I walk in the house, a motion sensor is activated and the mp3 player plays a welcome home song.
Biocow's original post is here, with a slightly different mp3 player: First project: Motion activated random mp3 player - #2 by system - Audio - Arduino Forum
Here's a blurry photo of my dismantled mp3 player.
The buttons have an outer ring, and an inner ring. When the two pieces of metal are connected, then it is a button press.
The only tricky part about controlling the mp3 player is soldering one wire to the inner ring, and soldering another to the outer ring. Just add a bit of solder to each one.
The two wires are then connected to a transistor. When the Arduino activates the transistor then the button on the mp3 player is connected. IMPORTANT: the transistor needs a common ground connected to Arduino ground.
The button represents the button on the mp3 player.
After the soldering was done, I put hot glue over the wires and buttons to hold everything firmly in place, otherwise the wires would eventually detach.
I connected the Arduino to the pause/play button, which allows me to turn the mp3 player on and off with this particular mp3 player. I also connected it to the forward button.
My mp3 player was purchased here: http://www.brilliantstore.com/4g-players-os-cpa-6184.html
Not a bad deal for $8. It has 4 gigs of memory and comes with a cord to connect it to your computer.
// when I walk in the house a motion sensor is activated.
//The arduino turns on the speakers with a powerswitchtail. Then
// it activates the mp3 player. After playing the song for 1
// minute, the speakers are turned off. Then the song is forwarded
// to the next one, and the mp3 player is turned off.
//A song will play every other time so that it doesn't play
// on exit, only entry.
int speaker = 0; //powerswitchtail for speakers
int Forward = 13; // forward 1
int Play = 8; // play/pause
// LED on 6, motion sensor on 2
int del = 949;
int i;
int song=1;
long SongLength;
int motion = 1;
int entry=0;
void setup() {
//Serial.begin(9600);
// initialize the digital pin as an output:
pinMode(Forward, OUTPUT);
pinMode(Play, OUTPUT);
pinMode(6,OUTPUT);
pinMode(0,OUTPUT);
SongLength=10000;
digitalWrite(speaker,LOW);
}
void loop()
{//949 delay and 150 press on the Forward buttons
//play
//200, shut off
motion=digitalRead(2);
if(motion==1){
if(entry==1){
//TURN IT ON
digitalWrite(Play, HIGH);
digitalWrite(6,HIGH); //turn an led on
delay(3500);
digitalWrite(Play, LOW);
digitalWrite(6,LOW);
delay(5260); //wait for the mp3 to come on
//4641 works, but small part of song
//4643 too short, misses
// TURN SPEAKERS ON
digitalWrite(speaker,HIGH);
//PLAY SONG
delay(60000); //1 minute
// TURN SPEAKERS OFF
digitalWrite(speaker,LOW);
//GO FORWARD ONE SONG
digitalWrite(Forward, HIGH); //pass the current song
delay(145);
digitalWrite(Forward, LOW);
delay(300); // let it load in, (was del variable)
//TURN IT OFF
digitalWrite(Play, HIGH); //
digitalWrite(6,HIGH); //LED on
delay(3500);
digitalWrite(Play, LOW);
digitalWrite(6,LOW);
delay(4000);
entry=0;
} else{
entry=1;
delay(20000);
}//end entry if statement
} //END MOTION SENSOR IF STATEMENT
delay(100);
} // END MAIN LOOP
**UPDATE:
Good news. I have found that the mp3 player can be powered from the 3.3v pin on the Arduino so that it doesn't have to be recharged. Otherwise, you would have to charge it once a week.
It's pretty simple. The battery is just stuck to the mp3 player with a bit of tape, it comes right off. It's connected with red and black wires, power and ground. I cut off the battery and soldered yellow wires to the red and black:
Here is the finished product, with yellow wires replacing the battery, red wires connected to the 'play' button, and green to the 'forward button, with hot glue over the whole thing to hold the wires in place (you could use tape instead of glue):
I posted some updated code below with more comments for readability.