Boom Box

This is your first step towards these kinds of skills. The boom box is a small sample player you can use to make music, or just random sound. It comes with three prerecorded samples but we probably don’t have the same creative cleverness when it comes to recording as you do so you should definitely record your own samples too!

Materials

  • 1 Arduino Uno board
  • 1 Education Shield
  • 1 micro SD card
  • 3 buttons
  • 1 8 ohm speaker
  • 3 10k ohm resistors
  • 3 black jumper wires
  • 6 colored jumper wires

Instructions

  1. Attach the shield onto the top of the Arduino board.
  2. Connect 3 buttons across the breadboard gap.
  3. Connect one pin of the first button to digital pin 5.
  4. Connect the same pin to a 10k ohm resistor and then connect that resistor to GND.
  5. Connect digital pins 6 and 7 to a corresponding button following the same method.
  6. Connect the other ends of the buttons to 5V.
  7. Record 3 wav sound files naming them “0.wav”, “1.wav” and “2.wav”. See reference Prepare Wav Sound for instructions. You can choose to use the sound files provided instead. Find them by going to Sketch>Show Sketch Folder. This will open the BoomBox sketch folder, there you see a folder named ‘Sound files’, where the pre recorded sound files are located. Save the sound files you want to use to the root directory of the SD card.
  8. Place the SD card into the shield’s slot and plug in the 8 ohm speaker to the audio socket.
  9. Connect the Arduino board to the computer and upload example BoomBox.
    Note: Use only the paper speaker for the audio socket, as it gives you the best possible quality.

Code

Find the code in File>Examples>EducationShield>Block3-Magic>Projects>BoomBox

How it works

  • The EducationShield and SD libraries are included.
  • The button group variables are declared, bg, buttons[] and buttonsCount.
  • The Player object, player is declared.
  • In setup(), the serial communication is initialized.
  • The player and button group are configured and initialized.
  • The variable pressedButton is declared and assigned the value read from bg.
  • A switch case is used to decide what to do depending on the value held by pressedButton.
  • If pressedButton is equal to 0, “sound 0” is printed to the serial monitor and the sound file 0.wav is played.
  • If pressedButton is equal to 1, “sound 1” is printed to the serial monitor and the sound file 1.wav is played.
  • If pressedButton is equal to 2, “sound 0” is printed to the serial monitor and the sound file 2.wav is played.
  • loop() continues to loop.

Troubleshooting

  • Refer to the illustration and double check your connections. Make sure the shield and jumper wires are firmly connected.
  • Debug the buttons, see the button reference.
  • Debug the music player, see the Player reference for details.

Learn by doing

  • Play more sounds: add more buttons.