Binary LP

This sort of works as an LP player. The difference is that instead of using a needle on a plastic disc, you use three IR sensors in a row to read a pattern from a paper disc. If you are both musically and digitally inclined, you will have lots of fun creating melodies with this.

Materials

  • 1 Arduino Uno board
  • 1 Education Shield
  • 1 IR Array
  • 1 piezo speaker
  • 2 black jumper wires
  • 5 colored jumper wires
  • Binary LP kit
  • Binary LP paper disc

Instructions

  1. Attach the shield onto the top of the Arduino board.
  2. Connect a piezo speaker across the breadboard gap and connect one leg to digital pin 8 and the other to GND.
  3. Connect 5 loose jumper wires to the board, 1 black to GND, 1 red to 5V and 3 in different colors to A1, A2 and A3. These will later be connected to the IRArray so remember what color is connected to what.
  4. Assemble the Binary LP. (But do not put on the lid just yet.)
  5. Place the Arduino board in the Binary LP box, connect it to the computer, and upload example BinaryLP.
  6. Put the loose jumper wires through the hole on the lid of the Binary LP box.
  7. Place the lid on the box, and the gears on the lid.
  8. Place the IRArray in the holder. 
  9. Connect the loose wires to the IRArray. 5V to 5V, GND to GND, A1 to IR1, A2 to IR2, A3 to IR3.
  10. Use the processing sketch in the sketch folder to make your own disc. Find it by going to Sketch>Show Sketch Folder. Open the processing sketch in the folder ‘Processing sketch’. Print out the PDF it creates – make sure to print it Actual Size (not Fit to Page). You can also print out an empty disc and use a black marker to create the patterns.
  11. Tape the disc to the turntable making sure to correctly align the markings so that it is centered.

Code

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

How it works

  • The EducationShield library is included.
  • pitches.h is included, the file containing the definitions of the notes.
  • The IRArray object ir is declared.
  • The variables piezo and lastReading are declared.
  • In setup(), the pin where to which the piezo is connected is configured as an output using the variable piezo.
  • In loop(), the binary value read from the IR Array is stored in the variable reading. This value ranges from 0 to 7 and is the binary combination of the white and black areas on each line of the paper disc. 0 means all white, and 7 means all black.
  • The program jumps to the function playNote() and reading is passed to the function.
  • In playNote(), an if statement checks if lastReading and r is equal to each other. r is the read binary value passed to the function and lastReading is the previous read binary value.
  • If the if statement is true it means that the same two notes are to be played. To be able to distinguish the two notes, noTone() is called to make the piezo silent.
  • The program pauses for 20 milliseconds.
  • A switch case is used to decide what tone to play depending on the value held by r.
  • If r is equal to 0, nothing is done (the piezo is already silent), if r is equal to 1 the note NOTE_C4 is played etc.
  • If r is more than 0, the value of r is assigned to lastReading.
  • The program jumps back to loop().

Troubleshooting

  • Refer to the illustration and double check your connections. Make sure the shield and wires are firmly connected.
  • Debug the IRArray, see the IR Array reference.

Learn by doing

  • Compose a few different melodies.
  • Come up with new way to use the binary readings.