Pages: [1]   Go Down
Author Topic: First project: Motion activated random mp3 player  (Read 3600 times)
0 Members and 1 Guest are viewing this topic.
Silly-con Valley, Ca, U.S.
Offline Offline
Sr. Member
****
Karma: 17
Posts: 420
Lernin' to tinker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Other than some simple flashing LEDs this is my first Arduino project. I came up with an idea on the fly in this thread actually) to build something that would play sounds and possibly flash LEDs when someone walks up to it or by it. I thought it might be difficult at first but this past weekend I decided to give it a go.

I started out with a cheap mp3 player:

 

The way it works is to turn it on you press and hold play for a little over a second to turn it on. It takes a few seconds to power up. Then it has all the standard buttons you would expect. Forward/Back, Volume, etc... I figured if I could bypass the play and forward button I could control it with the Arduino.

So I ripped it apart:

 

And lucky for me you can see in the next pic the 2 far right buttons are the play and forward track buttons. If they had been next to the battery it would have been a lot tougher.

 

Looking at the buttons I saw some open contacts that were not being used. Measured with a milti meeter to make sure they worked and they did.

 

I took some magnet wire (24 gauge I think) cause it was tiny and flexible and did my best to solder to the tiny contacts.

 

It took a lot of time and the solder joints were not very strong. 2 wires fell off and had to be reattached. Finally I bent them down and taped them in place to reduce the stress on them.

 

Even after this the far left one fell off and had to be redone but I think they're all pretty good now.

I hooked it up to a breadboard with buttons to test it out. WARNING: Very boring video <a href="http://www.biocow.com/arduino/mp3hack/1.MOV" target="_blank">here</a>. (Takes a bit to load.)

Next I moved to the Arduino with protoboard. Got some 2n2222a transistors and various resisters and tried to hook it up but I couldn't get it to work. I hooked up an LED and the Arduino would make that work but I couldn't make them switch the mp3 player on or forward the tracks. It dawned on me later that I wasn't using a common ground and that was probably my problem. But I figured finding ground on the player would be difficult. Instead I opted for relays. I went to my local electronics surplus store (Halted Electronics) and picked up these relays.

 

Got it wired up right and it worked flawlessly.

I wrote a little code and got it running in a loop:

Turn on
Play
Pause
Forward a random # of tracks
Power down
Pause

I had also ordered some Sharp IR sensors so next I plugged that in and added some code. I honestly thought that would be the hardest part but I had that working in about 10 minutes.

 

Here is the whole setup:

 

I'll post the code in the next post.
Logged

10 PRINT CHR$(7)
20 GOTO 10

Silly-con Valley, Ca, U.S.
Offline Offline
Sr. Member
****
Karma: 17
Posts: 420
Lernin' to tinker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <SoftwareSerial.h>

/*
 Random Sound Player
 By biocow
 November 2010
*/


int distanceVal;

const int numReadings = 10;

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int inputPin = A5;

void setup() {             
 // initialize the digital pin as an output:
 pinMode(6, OUTPUT); // On, Play and pause   
 pinMode(7, OUTPUT); // Forward track
 pinMode(0, INPUT);  // will listen for the end of the track

 for (int thisReading = 0; thisReading < numReadings; thisReading++)
   readings[thisReading] = 0;

 Serial.begin(9600);
}

void loop() {

 // Get the readings from the IR sensor
 // and smooth them out.

 // subtract the last reading:
 total= total - readings[index];     
 // read from the sensor: 
 readings[index] = analogRead(inputPin);
 // add the reading to the total:
 total= total + readings[index];   
 // advance to the next position in the array: 
 index = index + 1;                 

 // if we're at the end of the array...
 if (index >= numReadings)           
   // ...wrap around to the beginning:
   index = 0;                       

 // calculate the average:
 average = total / numReadings;     
 // send it to the computer (as ASCII digits)
 Serial.println(average, DEC);




 // is someone there? Let's see

 if(average > 30) {
 
   // turn on the MP3 player
   Serial.println("turning on player");
   digitalWrite(6, HIGH);
   delay(1400);
   digitalWrite(6, LOW);
 
   // wait for it to power up
   delay (4500);
 
   // advance one track to make sure we're at the start of a song
   digitalWrite(7, HIGH);
   delay(200);
   digitalWrite(7, LOW);
   delay(900);
   Serial.println("advance one track");
 
   // Play the current track
   digitalWrite(6, HIGH);
   delay(200);
   digitalWrite(6, LOW);
   Serial.println("Play");
 
   // listen to the current song for a bit
   // later we'll wait and listen for the end of the track
   delay(5000);
   Serial.println("How do you like this song?");
   delay(5000);
 
   // pause the song
   digitalWrite(6, HIGH);
   delay(200);
   digitalWrite(6, LOW);
   Serial.println("Song is over");
 
   // Advance the tracks a random number of times
   for(int x = 1; x <= random(1,7); x++) {
      digitalWrite(7, HIGH);
      delay(200);
      digitalWrite(7, LOW);
      delay(1000);
      Serial.print("Advance track ");
      Serial.print(x);
      Serial.println(" time(s)");
   }
 
   // delay
   delay(700);
 
   // turn off the MP3 player
   Serial.println("shutting down");
   digitalWrite(6, HIGH);
   delay(1400);
   digitalWrite(6, LOW);
   delay(5000); // give it time to turn off
 
 
 
   // Reset all the sensor stuff
   average = 0;
   total = 0;
   for(int l = 0; l < numReadings; l++) {
      readings[l] = 0;
   }
 
   // wait a good bit of time before we reset
   int pause = random(10000,20000);
   Serial.print("Pausing for ");
   Serial.print(pause / 1000);
   Serial.println(" seconds");
   delay(pause);
 
 }

}
Logged

10 PRINT CHR$(7)
20 GOTO 10

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12425
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice tinkering, I like the idea as you could create a number of phrases or sounds that can be played when needed. especially alarms or "Tresspassers not allowed" or "please state the nature of the medical emergency" etc.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 262
bluesmokelabs.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you find the wires come off a bit too easy, try holding the heat a little longer when soldering, or should fix your problem.

Cool project too!
Logged

Silly-con Valley, Ca, U.S.
Offline Offline
Sr. Member
****
Karma: 17
Posts: 420
Lernin' to tinker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, the second go seems to have stuck it but I kept it taped anyway just in case. You're probably right though, i was trying not to damage anything. It's a very small pad.
Logged

10 PRINT CHR$(7)
20 GOTO 10

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Very Cool. On a USB port there is a ground; if it can charge via USB maybe you can use it as a common ground with transistors.
Logged

Pages: [1]   Go Up
Jump to: