Shopping Cart

Piper Coding Project: Make music with the wave of a hand!

Posted by on

Did you know you could make music without even touching an instrument?  You can with a Theremin!  Watch the video below for the Game of Thrones theme song played on a Theremin:

Making a Theremin

Neat stuff!  Here's how to build your very own Theremin with a Piper Computer Kit and an HC-SR04 Ultrasonic Sensor.  

Step 1) Build the circuit

Connect the HC-SR04 Ultrasonic Sensor to the Raspberry Pi using the diagram below.  

Step 2) Install the Sonic-Pi libraries 

From your Piper Computer Kit's desktop, open a terminal window by clicking the Terminal button (shown in green).

Next you'll need to connect a keyboard to the Raspberry Pi. If you don't have one, you can open the on-screen keyboard and use that instead.

First we'll install the python-osc library.  This enables the musical notes to be sent to the Sonic-Pi music synthesizer program.  Type the following command into the terminal and press enter:  

$ sudo pip3 install python-osc

You'll may also need to update Sonic-Pi.  Type the following command and press enter:

$ sudo apt-get install sonic-pi 

Step 3) Download the Theremin Code

On your Piper Computer Kit, open the Chromium web browser from the task bar, open this blog post and download the Theremin Code file by clicking here

Step 4) Unzip the Theremin Code

Next we need to unzip the Theremin Code file that you just downloaded. 

Go back to the terminal window and enter the following command:

$ sudo unzip /Downloads/ 

Step 5) Run the Theremin Code

Now we can run the code that detects the signal from the Ultrasonic Sensor and converts the detected distance into musical notes.

In the terminal, enter the following command:

$ sudo python3 /theremin/

You'll notice numbers appear in the terminal window, these are the notes that will be sent to Sonic Pi. Take a look at how the numbers change as you move your hand over the Ultrasonic Sensor. 

Step 6) Connect to Sonic-Pi

Open Sonic-Pi from the Start Menu -> Programming-> Sonic-Pi

Now click Load and select the sonicTheremin.txt file from the /home/pi/theremin folder.

Step 7) Select the headphone output 

Let's make sure the sound output is set to headphone jack rather than HDMI. Click on the Pref button from the Sonic-Pi menu bar and then select Headphones.  You may need to press the >> button to show extra menu buttons.


 Step 8) Make music!

Now that the Sonic-pi code is loaded, click the Run button from the menu bar.  You should hear the notes changing as you move your hand over the distance sensor!  

Congratulation on making your very own Piper Theremin musical instrument! 

Making a Theremin

Extension Ideas 

See if you change the music by playing around with the sonic-pi code. You can get more help by clicking the Help button from the menu bar to see example of sonic-pi code. It is a very cool piece of software that allows you to make music with simple code and it's very fun to experiment with. 

Older Post


Leave a comment