Sequencer

Play beats and change the sequence in real time. It is basically all you need to become a hip-hop artist. That, and rapper skills. But that is another course.

Materials

  • 1 Arduino Uno board
  • 1 Education Shield
  • 1 micro SD card
  • 1 8 ohm speaker
  • 4 680 ohm resistors
  • 1 220 ohm resistor
  • 1 470 ohm resistor
  • 1 1.2k ohm resistor
  • 1 black jumper wire
  • 7 colored jumper wires
  • 4 black loose wires
  • 4 colored loose wires
  • Sequencer kit

 

Instructions

  1. Attach the shield onto the top of the Arduino board.
  2. Put the stripped end of a black wire through the two holes on one side of each heart. Using a stripped colored wire, do the same for the remaining holes of each heart.
  3. Assemble the Sequencer table.
  4. Place a resistor into each heart piece (220Ω, 470Ω, 680Ω, 1.2KΩ) and use the top piece to secure them in place.
  5. Connect three 680 ohm resistors over the breadboard gap.
  6. Connect one side of the resistors to 5V.
  7. Connect the other side of the resistors to analog pins A1 to A3. (Analog pin A4 has a built in resistor on the shield, this is why we don’t need to connect a resistor there.)
  8. Connect three colored wires from the sequencer table to A1 – A3 through the breadboard and the fourth wire directly to A4.
  9. Connect the black wires from the sequencer table to GND.
  10. Take the sound files provided named ‘seq0.wav’, ‘seq1.wav’, ‘seq2.wav’, ‘seq3.wav’, ‘seq4.wav’ and move them to the root directory of the micro SD card. You find them by going to Sketch>Show Sketch Folder.
  11. Place the 8 ohm speaker in the sequencer table.
  12. Plug the 8 ohm speaker in the audio socket and place the micro SD card into the shield’s micro SD slot.
  13. Connect the Arduino board to the computer and upload example Sequencer.

Code

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

How it works

  • The EducationShield and SD libraries are included.
  • The Player object player is declared.
  • The variables that has to do with the analog pins are declared, analog_pins[] and pin_count.
  • The char array filename[] is declared to hold the template filename “seq0.wav”.
  • In setup(), the serial communication is initialized.
  • The Player object is initialized.
  • In loop(), a for loop loops for as many times as the value of pin_count, one time for each analog sensor.
  • In each loop of the for loop, the variable slot_value is declared to hold the read analog value from analog_pins[i]. In the first loop i is equal to 0 which means the analog value is read from analog pin 4.
  • The variable sequence is declared to hold the value returned by getSeq().
  • The program jumps to the function getSeq() and slot_value is passed to the function.
  • In getSeq(), an if-else statement checks within which range the read analog value, analogVal, is.
  • A number from 1 to 4 is returned by the function getSeq(), depending on the result of the if-else statement. A 0 is returned if analogValis not within any of the ranges.
  • The program jumps back to loop() where the returned value is stored in the variable sequence.
  • The fourth character in filename[] is replaced with the value of sequence.
  • The file name is printed to the serial port so you can read it in the serial monitor.
  • The file is played.
  • “=======” is printed to the serial port.
  • loop() continues to loop.

Troubleshooting

  • Refer to the illustrations and double check all your connections. Make sure the shield and wires are firmly connected.
  • If you are having problems playing the sound files, check the reference for debugging the sound player.
  • Make sure you are using the right resistors. Check the reference to see how to check it.

Learn by doing

  • Record your own 5 wav sounds and name them ‘seq0.wav’, ‘seq1.wav’, ‘seq2.wav’, ‘seq3.wav’ and ‘seq4.wav’. They should all be equally long for the best result and ‘seq0.wav’ should be silent. See reference Prepare Wav Sound for details.