Products for USB Sensing and Control
Products for USB Sensing and Control

A Phidgets Theremin With Processing

Creating a non-contact instrument with Phidgets

by Ben

Hour of Code

If you are an educator with Hour of Code, you can get the hardware for this project for free here!


What's A Theremin?

Theremin's are unique instruments that are completely contactless. Instead of musicians handling the instrument, they simply move their hands in the air above. The position of the musician's hands determines the sound produced. Check out this video for an example.

In this project, you will recreate this futuristic non-contact effect using a distance sensor.


This project assumes you are familiar with Processing and have completed the following guides:


The goal of this project is to translate distance data, collected by the Distance Phidget, into audio output. In the end you should have a functional theremin.

Parts Inventory

Note: Any distance sensor can be used for this project (including the DST1200 from the Rover Kit), however, results may vary depending on resolution and sample rate.


For this project, simply connect two distance sensors to your VINT Hub and connect your VINT Hub to your computer.

Interpreting Data

The Distance Sensors will return values between 0mm and 650mm depending on the position of your hands above the sensors. You can map these values directly to pitch and volume. As a hand rises above the pitch sensor, the pitch of the theremin rises. Identically, as a hand rises above the volume sensor, the volume of the theremin rises.For example, if your hand is at 325mm (50% of max distance) your volume should be at 50% max volume.


Configure Sound Library

In this project, you will be using Processing's Sound Library, however, the Beads Library, available for Java, could be equally suited to the task. If you wish to complete this project in another language, you will need to find a compatible sound library.

Open Processing and navigate to
Sketch > Import Library... > Add Library...

Enter "Sound" in the search bar and install it

You will see a green checkmark if the installation is successful

The Sound Library will allow you to play a variety of different sounds from within Processing. To start, you will need to create a sine wave oscialltor. Check the SinOsc API on the processing website for more information.

Step 1: Setup

Here we need to define and configure the oscillator and Phidgets. Make sure the oscillator is initialized before the Phidgets.

import processing.sound.*;
import com.phidget22.*;

static SinOsc sine;
DistanceSensor pitchDistance;
DistanceSensor volumeDistance;

void setup(){
    size(640, 360);
    //Create start oscillator before initializing Phidgets
    sine =  new SinOsc(this);;

    //TODO: Create Phidget Objects, Addess Objects, 
    //      Register for Events, Open Objects
    //      Set Distance Objects Data Interval to Min

Step 2: Events

The map() function is very useful for converting a distance value to a pitch value or a distance value to a volume value.

pitchDistance.addDistanceChangeListener(new DistanceSensorDistanceChangeListener() {
    public void onDistanceChange(DistanceSensorDistanceChangeEvent e) {
        print("\nPitch Distance: " + e.getDistance());
        //TODO: use map() to map distance to a frequency range of your choice
        //TODO: Update SinOsc frequency.

volumeDistance.addDistanceChangeListener(new DistanceSensorDistanceChangeListener() {
    public void onDistanceChange(DistanceSensorDistanceChangeEvent e) {
        print("\Volume Distance: " + e.getDistance());
        //TODO: use map() to map distance to a volume range
        //TODO: Update SinOsc volume (hint: amplitude).

Make sure you close your oscillator before your Phidgets.

void exit() {
    //TODO: close phidgets

Step 3: Draw

The draw function keeps the window open, so include it even if there is no code inside!

void draw(){
    //TODO: Nothing!


By the end of this article you will have created your very own instrument! Experiment with different sounds and see if you can recreate your favourite melody!

Have you created a musical application with Phidgets? We would love to hear about it or any other projects at

Next Steps

  • More complex oscillators - try varying the types of oscillators or stack overtones to create a richer sound.
  • Visualize the sound output by attaching graphics to the input parameters.
  • Add effects - read the Sound Library API