Go Down

Topic: $150 Happy Birthday to you? (Read 899 times) previous topic - next topic

DBL07

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
Matthew Rings

CEO & Founder DBL07 Consulting Web Design Columbia SC
http://www.dbl07.co
Web Design columbia s

robtillaart

Quote
Is there a simpler cheaper way to do this?

but another card ?
Rob Tillaart

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

patduino

#2
Dec 30, 2012, 09:42 pm Last Edit: Dec 30, 2012, 09:45 pm by patduino Reason: 1
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!
There are 10 types of people in the world, those that understand binary, and those that don't.

Docedison

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

--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

patduino

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?
There are 10 types of people in the world, those that understand binary, and those that don't.

dc42


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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Volta500

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.

Code: [Select]

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

Volta500

Got your Batman theme!
It is not much but here it is anyways

Code: [Select]
/* 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
}

DBL07


Quote
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!
Matthew Rings

CEO & Founder DBL07 Consulting Web Design Columbia SC
http://www.dbl07.co
Web Design columbia s

DBL07


Got your Batman theme!
It is not much but here it is anyways

Code: [Select]
/* 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
Matthew Rings

CEO & Founder DBL07 Consulting Web Design Columbia SC
http://www.dbl07.co
Web Design columbia s

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up