Offline
Newbie
Karma: 0
Posts: 6
|
 |
« on: December 30, 2012, 03:27:38 pm » |
So I got a sweet Batman Birthday card that plays a short clip of the Bat Theme when I open it. Then I cut the card open with my knife cause I wanted to see how they did it. So my question is I want to make something like this that has a simple trigger that will play one sound when the switch is opened, but so far the only thing I've seen is I have to buy a MEGA attached to a MP3 Shield etc and $150 later I have the same thing that this $5 card came with. Is there a simpler cheaper way to do this? Cheers
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Online
Tesla Member
Karma: 89
Posts: 9392
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #1 on: December 30, 2012, 03:31:35 pm » |
Is there a simpler cheaper way to do this? but another card ?
|
|
|
|
|
Logged
|
|
|
|
|
Indiana, US
Offline
Full Member
Karma: 12
Posts: 161
|
 |
« Reply #2 on: December 30, 2012, 03:42:52 pm » |
Hi DBL07,
Happy birthday!
Look at the switch on the card. If you can take it apart and solder a wire to the 2 leads, you can control it with your Arduino. Most likely, it is a ground closure switch (test that by grounding one of the leads to see if it makes it play, if not, try the other one),
Then connect the card's ground to the Arduino ground and connect the switch control lead to GPIO pin of your choice. Set it up as an output (HIGH). Then write a FALSE/LOW to it to trigger the sound.
Pat.
PS, but you have to admire robtillaart's response!
|
|
|
|
« Last Edit: December 30, 2012, 03:45:26 pm by patduino »
|
Logged
|
There are 10 types of people in the world, those that understand binary, and those that don't.
|
|
|
|
Anaheim CA.
Offline
Edison Member
Karma: 31
Posts: 2307
Experienced old Whitebeard with a Full head of Hair...
|
 |
« Reply #3 on: December 30, 2012, 03:49:51 pm » |
I would be VERY Careful of that method as the card electronics isn't likely 5 V tolerant. One 'suggestion' might be to use a diode cathode pointing to the card and anode pointing to the Arduino. a "Plain" 1N5818 schottky diode because the diode only has a .4V drop instead of the 'normal' silicon diodes .6V drop.
Bob
|
|
|
|
|
Logged
|
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
|
|
|
|
Indiana, US
Offline
Full Member
Karma: 12
Posts: 161
|
 |
« Reply #4 on: December 30, 2012, 04:00:46 pm » |
Hmmmm, that's true. The sound card I hacked was ok, but I'm not sure what powers a Bday card.
DBL, do you have a voltmeter to check?
|
|
|
|
|
Logged
|
There are 10 types of people in the world, those that understand binary, and those that don't.
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4668
|
 |
« Reply #5 on: December 30, 2012, 04:29:47 pm » |
So I got a sweet Batman Birthday card that plays a short clip of the Bat Theme when I open it. Then I cut the card open with my knife cause I wanted to see how they did it. So my question is I want to make something like this that has a simple trigger that will play one sound when the switch is opened, but so far the only thing I've seen is I have to buy a MEGA attached to a MP3 Shield etc and $150 later I have the same thing that this $5 card came with. Is there a simpler cheaper way to do this?
I reckon you could do it with an Attiny85 and the PWM Audio library, modified to play the tune direct from progmem instead of an SD card. See http://arduino.cc/forum/index.php/topic,112745.0.html.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #6 on: December 30, 2012, 04:43:47 pm » |
I made a little program that plays happy birthday a while back. Maybe not you want, and the notes and durations are not yet perfect, but it should not take too long to figure that out. /* Pelle Jansen - 15-8-2012 *Play Happy Birthday * *Componens: Any Arduino, NPN transistor or N-channel MOSFET, Resistor, speaker * The circuit: * base of NPN transistor through 500R(depends on transistor used) to pin 13, * Emitter of NPN transistor to ground * Collector to speaker negative * speaker positive to VDD * can also use mosfet. * */ // includes and defines: #include "pitches.h" // most used notes as defined frequencies
// constant var defenitions: const unsigned char button=2; const unsigned char spk=13;
// Variable and function defenitions: int happyBirthday[] = { NOTE_C4,NOTE_C4,NOTE_D4,NOTE_C4,NOTE_F4,NOTE_E4,NOTE_C4,NOTE_C4, NOTE_D4,NOTE_C4,NOTE_G4,NOTE_F4,NOTE_C4,NOTE_C4, NOTE_C5,NOTE_A4,NOTE_F4,NOTE_E4,NOTE_D4,NOTE_B4,NOTE_B4,NOTE_A4, NOTE_F4,NOTE_G4,NOTE_F4 }; unsigned char length=sizeof(happyBirthday)/2; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 3,16,4,4,4,2,3,16,4,4,4,2,3,16,4,4,4,4,4,3,16,4,4,4,2}; unsigned char lengthDur=sizeof(noteDurations)/2;
// Set up the microcontroller void setup(){ Serial.begin(9600); Serial.println("Serial active! "); pinMode(button, INPUT_PULLUP); }
// play the song void play(){ // check if there are as much notes as durations if (length != lengthDur){ Serial.println("ERROR: note durations not equal to number of notes! "); Serial.print("Length of happyBirthday: "); Serial.print(length); Serial.print("; Length of durations: "); Serial.println(lengthDur); } // iterate over the notes of the happyBirthday: for (unsigned char thisNote = 0; thisNote < length; thisNote++) { // to calculate the note duration, take one second divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurations[thisNote]; tone(spk, happyBirthday[thisNote],noteDuration); Serial.print("Current frequency: "); Serial.println(happyBirthday[thisNote]); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); noTone(spk); // stop the tone playing: } }
// main loop void loop(){ // play the song // to not repeat: move play() to setup() and remove delay play(); delay(300); // Slow repetition }
This code could also be used to play something else.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #7 on: December 30, 2012, 05:26:14 pm » |
Got your Batman theme! It is not much but here it is anyways /* Pelle Jansen - 30-12-2012 *Play Happy Birthday * * The circuit: * base of NPN transistor thrugh 500R(depends on transistor used) to pin 13, * Emitter of NPN transistor to ground * Collector to speaker negative * speaker positive to VDD * can also use mosfet. */ // includes and defines: #include "pitches.h" // most used notes as defined frequencies
// constant var defenitions: const unsigned char button=2; const unsigned char spk=13;
// Variable and function defenitions: int Batman[] = { NOTE_A3, NOTE_A3, NOTE_GS3, NOTE_GS3, NOTE_G3, NOTE_G3, NOTE_GS3, NOTE_GS3, NOTE_A3, NOTE_A3, NOTE_GS3, NOTE_GS3, NOTE_G3, NOTE_G3,NOTE_GS3, NOTE_GS3, NOTE_A3, NOTE_A3, NOTE_GS3, NOTE_GS3, NOTE_G3, NOTE_G3, NOTE_GS3, NOTE_GS3, NOTE_A3, NOTE_A3, NOTE_GS3, NOTE_GS3, NOTE_G3, NOTE_G3,NOTE_GS3, NOTE_GS3, NOTE_E4, NOTE_E4 }; unsigned char length=sizeof(Batman)/2; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4,8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4}; unsigned char lengthDur=sizeof(noteDurations)/2;
// Set up the microcontroller void setup(){ Serial.begin(9600); Serial.println("Serial active! "); pinMode(button, INPUT_PULLUP); }
// play the song void play(){ // check if there are as much notes as durations if (length != lengthDur){ Serial.println("ERROR: note durations not equal to number of notes! "); Serial.print("Length of Batman: "); Serial.print(length); Serial.print("; Length of durations: "); Serial.println(lengthDur); } // iterate over the notes of the Batman: for (unsigned char thisNote = 0; thisNote < length; thisNote++) { // to calculate the note duration, take one second divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurations[thisNote]; tone(spk, Batman[thisNote],noteDuration); Serial.print("Current frequency: "); Serial.println(Batman[thisNote]); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); noTone(spk); // stop the tone playing: } }
// main loop void loop(){ // play the song // to not repeat: move play() to setup() and remove delay play(); delay(1000); // Slow repetition }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #8 on: December 30, 2012, 06:24:57 pm » |
Is there a simpler cheaper way to do this? but another card ? Holy Hairballs Robin why didn't I think of that! Ha I mean, how can I build something like this from scratch to play my theme song 007 in a loop without spending 150 on the whole rig  Thanks for all your replies btw!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #9 on: December 30, 2012, 06:27:22 pm » |
Got your Batman theme! It is not much but here it is anyways /* Pelle Jansen - 30-12-2012 *Play Happy Birthday * * The circuit: * base of NPN transistor thrugh 500R(depends on transistor used) to pin 13, * Emitter of NPN transistor to ground * Collector to speaker negative * speaker positive to VDD * can also use mosfet. */ // includes and defines: #include "pitches.h" // most used notes as defined frequencies
// constant var defenitions: const unsigned char button=2; const unsigned char spk=13;
// Variable and function defenitions: int Batman[] = { NOTE_A3, NOTE_A3, NOTE_GS3, NOTE_GS3, NOTE_G3, NOTE_G3, NOTE_GS3, NOTE_GS3, NOTE_A3, NOTE_A3, NOTE_GS3, NOTE_GS3, NOTE_G3, NOTE_G3,NOTE_GS3, NOTE_GS3, NOTE_A3, NOTE_A3, NOTE_GS3, NOTE_GS3, NOTE_G3, NOTE_G3, NOTE_GS3, NOTE_GS3, NOTE_A3, NOTE_A3, NOTE_GS3, NOTE_GS3, NOTE_G3, NOTE_G3,NOTE_GS3, NOTE_GS3, NOTE_E4, NOTE_E4 }; unsigned char length=sizeof(Batman)/2; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4,8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4}; unsigned char lengthDur=sizeof(noteDurations)/2;
// Set up the microcontroller void setup(){ Serial.begin(9600); Serial.println("Serial active! "); pinMode(button, INPUT_PULLUP); }
// play the song void play(){ // check if there are as much notes as durations if (length != lengthDur){ Serial.println("ERROR: note durations not equal to number of notes! "); Serial.print("Length of Batman: "); Serial.print(length); Serial.print("; Length of durations: "); Serial.println(lengthDur); } // iterate over the notes of the Batman: for (unsigned char thisNote = 0; thisNote < length; thisNote++) { // to calculate the note duration, take one second divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurations[thisNote]; tone(spk, Batman[thisNote],noteDuration); Serial.print("Current frequency: "); Serial.println(Batman[thisNote]); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); noTone(spk); // stop the tone playing: } }
// main loop void loop(){ // play the song // to not repeat: move play() to setup() and remove delay play(); delay(1000); // Slow repetition }
I'm sorry I'm a noob, but what hardware would I use this code for? Be patient I'm learning
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6346
-
|
 |
« Reply #10 on: December 30, 2012, 07:11:17 pm » |
I mean, how can I build something like this from scratch to play my theme song 007 in a loop without spending 150 on the whole rig  Thanks for all your replies btw! How determined are you NOT to buy the cheap working solution? I'm sure you can buy these devices ready to be programmed, and since they include them in gift cards the hardware must be very cheap. You can develop your own equivalent on an Arduino, or a PC, or a mainframe, or whatever hardware takes your fancy, but you're back to how much time and money you're willing to invest in it. All you need is an Arduino and an MP3 shield and a switch. Or a dictaphone and a switch. Or a fifty cent gadget out of a gift card and a switch.
|
|
|
|
|
Logged
|
|
|
|
|
|