Exercise 1: Imporve the Musical Instrument

Do this

Create a new, unique way to play the Arduino instrument! 

  • Use the instrument you made earlier in this chapter
  • Look for interesting shadow patterns or blinking lights. Use them to make rhythms and sounds!
  • How can you tweak the code to create better sounds?
  • Do you want to experiment and build the instrument with craft materials? Or do you want to instead concentrate on the code? You choose!


  • Plug in a battery to the board so you can move the instrument around. 
  • Clear shadows and sharp light (like the mobile phone's LED flashlight) are easy to make sounds with. 
  • About 15-20 minutes should be enough to complete this project -  don't make a super complicated instrument! You can always continue this project later on!

Programming tricks:

  • Work with the if statement: check the serial monitor to find the best threshold values

  • Work with the ranges in the map command

  • Spice up the sounds with a bit of randomness! For example:

random(min, max) creates a random number between given minimum and maximum values. It's a useful command!

Note: Be careful with parentheses - it's not a typo, you really need two closing parentheses  ))  in the end of the command.

You can use random  with the map command, too (or anywhere where you have numbers):

You can also try to...

  • ...change the note range with the map command (last two parameters)
  • ...use potVal as one of the parameters of the map command
  • ...use potVal as the second or third parameter of the tone command
  • ...change the "smaller than" symbol ( < ) into the "greater than" symbol ( > ) in the if statement
  • ...use ldrVal as the parameter for delay

Educator notes

Once again, the most important aspect of this exercise is not the outcome itself, but rather, letting the students experience different ways to create interaction and to use their surroundings as material.

It is sometimes tough to apply what you’ve learned when you’re still learning the basics - but it’s definitely not impossible! Moments of experimentation provide even beginners a chance to plant seeds for new ideas, those which may take a while to blossom. Free-form, relaxed activities are sometimes needed to keep the motivation up.

A great way to start this exercise is an observational walk.

  • When coding intensively, a break is sometimes needed anyway. Why not take a walk for 10 minutes or so, inside or outside, making observations of interesting shadow and light patterns? Be sure to take photos to document those observations - it’s useful later on.
  • If it’s tricky to use the actual observations when playing the Arduino instrument, replicate the phenomena with objects, crafts materials and light sources.

Note - For example, mobile phones have excellent flash lights, which are great for creating very sharp shadows!