I have just started out using a Raspberry Pi, and for my first project, I wanted to build a pseudo theremin using an ultrasonic motion detector and other electronic components (requirements are laid out here https://www.raspberrypi.org/learning/ultrasonic-theremin/requirements/).

Since this is my very first Raspberry Pi project, I tried following the instructions laid out in https://www.raspberrypi.org/learning/ultrasonic-theremin/worksheet/ as carefully as possible. But I have run into a number of issues, chief among them being that the actual end product does not produce any kind of sounds whatsoever. Additionally, the worksheet is not clear as to how I should run the code that is required. Do I need to run the Python 3 code in the Terminal by supplying the command python3 exampletestscript.py? Or should I run the code in a different manner?

Step 3 is also proving to be quite complicated, as the instructions do not make it clear as to whether the different code blocks must be written in a single buffer, or if there is only one code block that must be written in a single buffer and then modified per each each step? To illustrate, should the two code blocks given in parts 2 and 3 of Step 3 be given in the buffer as:

live_loop :listen do
    set_sched_ahead_time! 0.1

live_loop :listen do
    message = sync "/play_this"

Or should there only be one block of code in the buffer, such that by the end of Step 3, the single code block in the buffer will read:

live_loop :listen do
    message = sync "/play_this"
    note = message[:args][0]
    play note

The final problem comes with the physical design of the ultrasonic motion sensor, bread board, and jumper and resistors. The sensors face down the board (please see the "Setting up the circuitry" in Step 1 of the worksheet in the URL provided above), and are thus always blocked by the cables themselves. It seems very counter-intuitive to have this kind of design (note: once I get a chance, I will upload a picture of the physical set-up).

I have bought all the pieces dictated by the "Requirements" section of the project, so I am quite sure that this is not a situation of having the wrong equipment. Rather, I think that this project assumes a certain level of proficiency with Raspberry Pi set-up, and has not properly explained the set-up properly. I should note that other buffers in my Sonic Pi do indeed produce sound, and the output of step 2 "Detecting distance" is consistent with the instructions, and my Raspberry Pi works fine otherwise.

  • 1
    I had a lot of trouble with this too, but it can work. Use the last live_loop above in SonicPi. Run your python3 code from the terminal or gui. I start the python code, then go into SonicPi and Run the script. Then wait - mine takes about 30 seconds before anything happens.
    – Glenn
    Commented Aug 7, 2017 at 18:48
  • I'll post the Python code in Answer as I cannot format it here.
    – Glenn
    Commented Aug 7, 2017 at 18:49
  • 1
    When reading your question, I think that you shall start by learning a bit of python before actually getting in "a project". About the electronic, they are only offering you one solution but you can actually reproduce the circuit as you want, the only import thing is to respect the circuitry.
    – YCN-
    Commented Jan 28, 2019 at 11:19

1 Answer 1


This is my python code without the sensor stuff:

  # sonic pi version of theremin
  from gpiozero import DistanceSensor
  from pythonosc import osc_message_builder
  from pythonosc import udp_client
  from time import sleep   

  #sensor = DistanceSensor(echo=24, trigger=23)
  sender = udp_client.SimpleUDPClient('', 4559)

while True:
    #pitch = round(sensor.distance * 100 + 30)
    pitch = 75
    sender.send_message('/play_this', pitch)
  • 1
    I suggest adding some sort of context to your answer otherwise it looks like you are asking a new question.
    – Darth Vader
    Commented Nov 24, 2017 at 10:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.