Go Down

Topic: Hacked mp3 player (basically an $8 waveshield) (Read 5407 times) previous topic - next topic

Big Oil

Mar 19, 2011, 02:29 am Last Edit: Mar 29, 2011, 06:00 pm by Big Oil Reason: 1
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: http://arduino.cc/forum/index.php/topic,49979.msg356317.html#msg356315

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.

Code: [Select]

// 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.  

CrossRoads

Cool, ordered one myself!

Try this to get your arduino back for another project:
5V source is not shown

all parts available at www.dipmicro.com, maybe $10 for all
- atmega
- resistor
- 3 100nF caps
- 2 22pF caps
- 16MHz crystal
- socket
- piece of perfboard to assemble on




Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

biocow

LOL. I've become a verb!

Nice job. I've put mine aside for now but hope to resirect it with an AtTiny85 instead of an arduino.
10 PRINT CHR$(7)
20 GOTO 10

novice

Nice work Big Oil, and credit to Biocow too.

mowcius

Quote
LOL. I've become a verb!

That's the only reason I visited this thread - too see why :D

cris11

I'm sorry but I am super new at this, and I have to recreate something similar to this.  Where do you hook up the motion sensor to?  Is this just an improvement to Biocow's so you don't have to use the relays?

novice

cris11,

looking at the source code above, the line "motion=digitalRead(2);" appears to read the motion sensor input on digital pin 2.

Big Oil

#7
Mar 25, 2011, 05:30 pm Last Edit: Mar 25, 2011, 05:36 pm by Big Oil Reason: 1
Yes, it doesn't need relays.  The parts required are:
2 transistors (pins 13 and 8 with this code)
1 motion sensor (data input on pin 2), this one: http://www.adafruit.com/index.php?main_page=product_info&cPath=35&products_id=189
optional- 1 powerswitchtail (to turn the speakers off when not in use, on pin 0)

I've found that the mp3 player needs to be recharged once a week.  The wires to the battery are usable, so I'm looking at cutting into those and powering it off the arduino.  I'll update later.



I've cleaned up the code, removed some old junk from it, and added some more comments to make it easier for a beginner to read.  

Code: [Select]
// 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;    // song forward
int Play = 8;          // play/pause a song
                     


int motion = 1;
int entry=0;

void setup()   {
 
//Serial.begin(9600);  

 pinMode(Forward, OUTPUT);     //to a transistor
 pinMode(Play, OUTPUT);         //to a transistor
pinMode(0,OUTPUT); //speaker
pinMode(2,INPUT);   //motion sensor input

digitalWrite(speaker,LOW); //speakers off
}


void loop()                    
{

motion=digitalRead(2); // read motion sensor on pin 2

if(motion==1){  // if the motion sensor has been activated

 if(entry==1){  // entry goes from 0 to 1 and 1 to 0 every time that
                // the motion sensor is activated.  It will only
                // play a song every other time, when it's 1
 
 //TURN the MP3 player ON by pressing 'play' for 3 seconds
 digitalWrite(Play, HIGH);  
 delay(3500);                  
 digitalWrite(Play, LOW);  
 delay(5260);                //wait for the mp3 to come on
                         
                           

// TURN SPEAKERS ON
digitalWrite(speaker,HIGH);

//PLAY SONG
delay(60000); //wait 1 minute while the song plays

// 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

//TURN mp3 player OFF by pressing 'play' for 3 seconds
 digitalWrite(Play, HIGH);  
       
 delay(3500);                
 digitalWrite(Play, LOW);  
 
delay(4000);
entry=0;      // make 'entry' 0 so that next time it won't play a song
 } else{
   entry=1;   // else, next time play the song
   delay(20000);  //waits 20 seconds for the person to leave the house
 }//end entry if statement


} //END MOTION SENSOR IF STATEMENT

delay(100);
} // END MAIN LOOP

biocow

Looks good.

BTW, the only reason I used relays is because I tried transistors but they didn't work. Tried relays and they worked. I later realized I didn't common ground the MP3 player and Arduino. DUH! But I actually liked the mechanical *click* of the relays.
10 PRINT CHR$(7)
20 GOTO 10

martin_bg

how about using optocoupler for activating the button? to me this is the cheapest and easiest option.

mowcius

transistors are easy, optos are easy.

For a beginner, optos are easier to understand but not normally cheaper.

daveg360

What voltage does the mp3 player use through these switches?
If your system involves lethal voltages/life critical/flamable elements - you probably shouldn't need to ask.
The Arduino != PC.

Big Oil

It has a 3.7 volt battery so I measure around 2-3v. 
I'm not able to keep the battery charged directly with the Arduino because it's a Lithium-ion battery.  It has to be recharged once a week.  I'm thinking about cutting off the battery entirely and just powering it with the 3.3 v pin on the Arduino.  I'll update later.

mowcius

Quote
I'm not able to keep the battery charged directly with the Arduino because it's a Lithium-ion battery.  It has to be recharged once a week.  I'm thinking about cutting off the battery entirely and just powering it with the 3.3 v pin on the Arduino.  I'll update later.

I'd suggest that would be the best thing to do - I'd have thought it would be fine with 3.3V personally - make sure it doesn't require more than 50mA (if it's going to be powered off a duemilanove/old mega - 200mA I think if it's an uno/new mega - I'd go check that to be sure though)

CrossRoads

Big Oil,
How did you open the MP3 player?
http://www.brilliantstore.com/4g-players-os-cpa-6184.html
Mine finally arrived, I can't Windows Vista to recognize it, says a drive is removed, installed, removed, installed.

Any tips?

Thanks
Robert
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up