Lego Sherlock Holmes figure focuses a light beam on a Lego criminal with a small magnifying glass.

LEGO Theremin

One way to build a musical instrument from Mindstorms/Raspberry Pi/BrickPi3 is to trigger sound samples from sensor input, such as in my previous blog post on LEGO Drum Machine. The sound sample is then played on the audio output of the Raspberry Pi. But I wanted to try a more direct approach to sound generation, rather than playing recorded samples. In other words, I wanted to take control of an oscillating signal to create sounds. So in the video above, I'm using a GPIO pin on the Raspberry Pi to implement a square wave of variable frequency. The square wave signal is fed into a guitar amplifier. Proximity measured by a Mindstorms Ultrasonic Sensor is linked to frequency, creating a variant on a musical instrument known as a theremin. With shorter distance measured by the Ultrasonic Sensor, the lower the pitch of the tone. The BrickPi3 ( is involved here for controlling the Ultrasonic Sensor, with the fast update rate allowed by the BrickPi3 being used to full advantage. A slow update rate from the sensor, such as would be found using the EV3 Intelligent Brick, would cause too much delay time for musical applications.