# Jack-o-Theremin

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/064/350/medium800thumb/sensors_JackOTheremin.jpg?1540419371)

## What is a theremin?

A [theremin](https://en.wikipedia.org/wiki/Theremin) is an electronic musical instrument that you can play without even touching it - spooky! The theremin senses the distance from its antennae to the player's hands, and changes its pitch and volume based on these distances. The theremin was used to make soundtrack music for many iconic spooky movies, like The Day the Earth Stood Still (1958), and is perfect inspiration for a Halloween project!

Here, I've turned a pumpkin into a Jack-o-Theremin using an ultrasonic distance sensor and a Circuit Playground Express (CPX). The CPX uses the distance measurement to generate a sound and flash the onboard NeoPixels in various colors. This version of a theremin has a much more digital-bleepy-bloopy sound than a traditional theremin, but you still get to make music by waving your hand around in the air!

## Materials

You'll need:

### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
![A Black woman's manicured hand holds a round microcontroller with lit up LEDs.](https://cdn-shop.adafruit.com/640x480/3333-05.jpg)

### HC-SR04 Ultrasonic Sonar Distance Sensor + 2 x 10K resistors

[HC-SR04 Ultrasonic Sonar Distance Sensor + 2 x 10K resistors](https://www.adafruit.com/product/3942)
If you're like me, you've dreamed of being a dolphin - smoothly gliding through the water. Using your echo-location abilities to detect tasty fish treats. Until genetic modifications catches up with our desires, we'll just have to make do with these handy **HC-SR04 Ultrasonic...**

In Stock
[Buy Now](https://www.adafruit.com/product/3942)
[Related Guides to the Product](https://learn.adafruit.com/products/3942/guides)
![Video of a woman's hand rising above a blue ultrasonic sonar distance sensor plugged into a half-size breadboard. An OLED screen displays the rising distance between the woman's hand and the sensor.](https://cdn-shop.adafruit.com/product-videos/640x480/3942-04.jpg)

### 3 x AAA Battery Holder with On/Off Switch and 2-Pin JST

[3 x AAA Battery Holder with On/Off Switch and 2-Pin JST](https://www.adafruit.com/product/727)
This battery holder connects 3 AAA batteries together in series for powering all kinds of projects. We spec'd these out because the box is slim, and 3 AAA's add up to about 3.3-4.5V, a very similar range to Lithium Ion/polymer (Li-Ion) batteries and have an on-off switch. That makes...

In Stock
[Buy Now](https://www.adafruit.com/product/727)
[Related Guides to the Product](https://learn.adafruit.com/products/727/guides)
![Front angled shot of 3 x AAA battery holder with on-off switch and 2-pin JST PH connector.](https://cdn-shop.adafruit.com/640x480/727-07.jpg)

### Mini Metal Speaker w/ Wires - 8 ohm 0.5W

[Mini Metal Speaker w/ Wires - 8 ohm 0.5W](https://www.adafruit.com/product/1890)
Listen up! This tiny 1" diameter speaker cone is the perfect addition to any small audio project where you need an 8 Ω impedance and will be using 0.5W or less of power. We particularly like this cone as it's very simple and its metal body is extremely lightweight. <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1890)
[Related Guides to the Product](https://learn.adafruit.com/products/1890/guides)
![Mini Metal Speaker with Wires](https://cdn-shop.adafruit.com/640x480/1890-06.jpg)

### 2-pin JST SM Plug + Receptacle Cable Set

[2-pin JST SM Plug + Receptacle Cable Set](https://www.adafruit.com/product/2880)
These 2-wire cables&nbsp;are 16cm long and come as a set. &nbsp;One side has a 2-pin JST SM type connector plug on the end. &nbsp;The other side has a matching 2-pin JST SM type receptacle connector. &nbsp;They are good for whenever you have 2 wires you want to be able to plug and unplug....

In Stock
[Buy Now](https://www.adafruit.com/product/2880)
[Related Guides to the Product](https://learn.adafruit.com/products/2880/guides)
![Angled Shot of the 2-pin JST SM Plug + Receptacle Cable Set.](https://cdn-shop.adafruit.com/640x480/2880-11.jpg)

Note: For my project, I used a scavenged speaker that I had in my spare parts box, but the speaker listed above will work just fine!

You'll also need a pumpkin to carve, and I highly recommend choosing a plastic or foam pumpkin for this project. That way, you can enjoy your Jack-o-Theremin for many Halloweens to come! If you do build this into a real pumpkin, you'll need to cover all the electronics with plastic wrap or seal them in a plastic bag inside the pumpkin.

# Jack-o-Theremin

## Carve the Pumpkin

Start by carving a fun face (or other design) into your pumpkin as you normally would. Have fun with this, the spookier the better! Don't forget to cut a lid, too (and consider a notch so you remember the orientation if the lid).

When you're done decorating the front of your pumpkin, we need to add a few extra holes for our electronics.

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/064/226/medium800/sensors_build_098.jpg?1540355292)

## Holes for the Rangefinder

Hold the rangefinder face down on where you want to install it on the Jack-o-Theremin. To the right of the face is a nice spot so you can watch the flash go while you play it. Use a pencil to trace around the sensor's emitters. Then, use your carving tool to carefully cut the holes.&nbsp;

For a foam pumpkin, I found that a hot knife attachment for my craft iron worked fairly well, but it takes patience (that I don't have!) to get a clean cut. Take your time and cut slowly and carefully.

![](https://cdn-learn.adafruit.com/assets/assets/000/064/228/medium800/sensors_build_103.jpg?1540355539)

## Hole for the Speaker

On the other side of the pumpkin, cut a hole for the speaker to fit in. Again, holding the speaker in place, trace around it so you know where to cut. Depending on the shape of your speaker, you may want to just cut a small hole for the speaker's wires to run through, and glue the speaker securely to the outside of the pumpkin.

![](https://cdn-learn.adafruit.com/assets/assets/000/064/229/medium800/sensors_build_110.jpg?1540355580)

## Hole for the Battery Holder

**This hole is optional.** If you prefer to not have to reach inside the pumpkin to turn your Jack-o-Theremin on and off, you may want to keep the battery holder, with the on/off switch, outside the pumpkin. If so, cut a small hole in the back of the pumpkin for the wires to run through.&nbsp;

# Jack-o-Theremin

## CircuitPython Code

## Getting Set Up for CircuitPython

This project is written in CircuitPython. If you're new to CircuitPython, visit the&nbsp;[Welcome to CircuitPython guide](https://learn.adafruit.com/welcome-to-circuitpython)&nbsp;for everything you need to know to get started!

For in-depth instructions on how to program your Circuit Playground Express with the code shown below, visit [this page in the Circuit Playground Express guide](https://learn.adafruit.com/adafruit-circuit-playground-express/creating-and-editing-code).

While you can edit CircuitPython in any text editor of your choice, Adafruit highly suggests using Mu Editor, which contains helpers and an interactive REPL. To install Mu and learn how to use it, visit the&nbsp;[Mu guide](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor).

This code uses the [Adafruit HC-SR04 library](https://github.com/adafruit/Adafruit_CircuitPython_HCSR04), which you will need to download and add to the lib folder on your Circuit Playground Express, if it's not already there.&nbsp;You can learn about installing the&nbsp;`adafruit_HC-SR04`&nbsp;library in the [Library guide](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).&nbsp;It is easiest to install the&nbsp;whole library package.

## The Code

In a nutshell: This code sets up the HC-SR04 as a sensor for the Circuit Playground Express to read. The distances sent from the sensor can range from zero to over 400 cm. With a little math (the `pitchMultiplier` variable), we turn the distance into a frequency for the Circuit Playground Express to play through the connected speaker. We also use the `wheel` helper function, commonly used in Adafruit code with rainbow animations, to turn this distance measurement into an RGB value for the NeoPixels on-board the Circuit Playground Express.

When the sensor detects an object, your hand for instance, within 3 - 25 cm, it plays a sound and flashes its lights!

To learn more about the super handy&nbsp;`wheel` function and how it works, see [this page](https://learn.adafruit.com/hacking-ikea-lamps-with-circuit-playground-express/generate-your-colors#wheel-explained) in Kattni Rembor's Ikea Lamp Hack guide.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Pumpkin_Theremin/code.py

# Jack-o-Theremin

## Build the Circuit

![](https://cdn-learn.adafruit.com/assets/assets/000/064/750/medium800/sensors_theremin_CircuitDiagram_bb.png?1540738539)

The connections are as follows:

**Sensor:**

- **VCC** on the HC-SR04 to **VOUT** on the CPX
- **TRIG** on the HC-SR04 to **A2** on the CPX
- **ECHO** on the HC-SR04 to voltage divider (one end of the two 10k resistors)
- Divided voltage (other end of the two resistors) to **A1** on CPX
- **GND** on the HC-SR04 to **GND** on the CPX
- Also connect a wire from between the two resistors to **GND** on the CPX

**Speaker + Amplifier:**

- PAM8302 **A+** to CPX **A0**
- PAM8302 **A-** to CPX **GND**
- PAM8302 **Vin** to CPX **Vout**
- PAM8302 **GND** to CPX **GND**
- Speaker to PAM8302 output pins (wire color/order doesnt matter)

Warning: 

## Connect the Sensor

Start by soldering four wires to the HC-SR04 Distance Sensor. Make your wires long enough to reach from the inside bottom of your pumpkin to the holes you cut for the sensor. For use in future pumpkins, that may be larger, give yourself a little extra length.

Cut and tin four wires for the HC-SR04 Distance Sensor.

![sensors_build_010.jpg](https://cdn-learn.adafruit.com/assets/assets/000/064/237/medium640/sensors_build_010.jpg?1540355962)

Solder the wires to the pins of the HC-SR04.

![sensors_build_021.jpg](https://cdn-learn.adafruit.com/assets/assets/000/064/245/medium640/sensors_build_021.jpg?1540356161)

Slide some heat shrink tubing over each pin and heat with a hot air gun for insulation.

![sensors_build_024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/064/247/medium640/sensors_build_024.jpg?1540356345)

## Add the Resistors

The Echo pin on the sensor outputs a 5v signal, but the Circuit Playground Express (like many microcontrollers) is a 3.3V device. This means you'll need to divide the voltage of the Echo pin with two 10k resistors. For a more in-depth explanation of this setup, check out [Kevin Walters' guide](https://learn.adafruit.com/distance-measurement-ultrasound-hcsr04/connect-the-sensor) on using this sensor with a Circuit Playground Express.

Twist the two resistors together and solder the twist, then trim the wires to about 1 cm long. Be careful not to bend the wires back and forth too much, or they will break.

![sensors_build_033.jpg](https://cdn-learn.adafruit.com/assets/assets/000/064/267/medium640/sensors_build_033.jpg?1540357160)

Solder wires to the resistors as shown. The white wire in this image connects to the Echo pin on the HC-SR04. The green and black wires will be soldered to the Circuit Playground Express in the next step.

![sensors_build_081_diagram.jpg](https://cdn-learn.adafruit.com/assets/assets/000/064/332/medium640/sensors_build_081_diagram.jpg?1540406302)

Cover each connection with heat shrink tubing, then cover the whole resistor assembly with a larger piece of heat shrink tubing.

![sensors_build_084.jpg](https://cdn-learn.adafruit.com/assets/assets/000/064/333/medium640/sensors_build_084.jpg?1540407103)

Make sure that the two wires that will go to the Circuit Playground Express are pointing in the same direction.

![sensors_build_086.jpg](https://cdn-learn.adafruit.com/assets/assets/000/064/334/medium640/sensors_build_086.jpg?1540407328)

## Connect the Circuit Playground Express

Follow the circuit diagram to connect the sensor to the Circuit Playground express. Solder the wires as shown below.

![](https://cdn-learn.adafruit.com/assets/assets/000/064/335/medium800/sensors_build_087.jpg?1540407532)

## Add the Speaker

In most cases, you'll need to extend the wires of your speaker to reach from the hole you cut in your pumpkin to the bottom of the pumpkin, where the Circuit Playground Express will be.

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/064/336/medium800/sensors_build_091.jpg?1540408024)

 **For permanent installation in a fake pumpkin:** If your speaker will be inserted into its hole from the outside of the pumpkin, you'll need to feed it through this hole first before soldering it to the Circuit Playground Express.

![](https://cdn-learn.adafruit.com/assets/assets/000/064/337/medium800/sensors_build_103.jpg?1540408066)

**For temporary installation in a real (or fake) pumpkin:** To make it easy to move the whole project to a new pumpkin, add a 2-pin connector between the speaker and the CPX as shown.

![](https://cdn-learn.adafruit.com/assets/assets/000/064/338/medium800/sensors_build_106.jpg?1540408103)

Connect the speaker wires to the Circuit Playground Express. Since there is just one speaker in this project, it doesn't really matter which wire is positive and which is ground. Solder one wire to A0 and the other to GND on the CPX.

![](https://cdn-learn.adafruit.com/assets/assets/000/064/339/medium800/sensors_build_093.jpg?1540408334)

## Installation

Plug the battery pack into your Circuit Playground Express (if locating inside) and carefully place the whole circuit inside your pumpkin. Slide the sensor into its holes and the speaker into its hole. If you kept the holes snug, the components should stay in place without additional help.

![](https://cdn-learn.adafruit.com/assets/assets/000/064/342/medium800/sensors_build_096.jpg?1540409067)

![](https://cdn-learn.adafruit.com/assets/assets/000/064/343/medium800/sensors_build_113.jpg?1540409106)

The Circuit Playground Express and battery pack will sit at the bottom of your project, and it can be helpful to stick the CPX to the battery pack with tape to keep it facing the front of the pumpkin. For a layer of diffusion, place a crumpled piece of white tissue paper or a paper towel in front of the Circuit Playground Express.

![](https://cdn-learn.adafruit.com/assets/assets/000/064/341/medium800/sensors_build_116.jpg?1540409055)

When everything is installed, just add batteries and you're ready to play with your Jack-o-Theremin!

# Jack-o-Theremin

## Play!

![](https://cdn-learn.adafruit.com/assets/assets/000/064/349/medium800thumb/sensors_JackOTheremin.jpg?1540419263)

Playing your Jack-o-Theremin is easy! Just turn it on and move your hand back and forth in front of the distance sensor. The Circuit Playground Express will translate your hand movements into interpretive pumpkin sound art, and provide a light show to go along with it. What could be spookier?&nbsp;


## Featured Products

### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### HC-SR04 Ultrasonic Sonar Distance Sensor + 2 x 10K resistors

[HC-SR04 Ultrasonic Sonar Distance Sensor + 2 x 10K resistors](https://www.adafruit.com/product/3942)
If you're like me, you've dreamed of being a dolphin - smoothly gliding through the water. Using your echo-location abilities to detect tasty fish treats. Until genetic modifications catches up with our desires, we'll just have to make do with these handy **HC-SR04 Ultrasonic...**

In Stock
[Buy Now](https://www.adafruit.com/product/3942)
[Related Guides to the Product](https://learn.adafruit.com/products/3942/guides)
### 3 x AAA Battery Holder with On/Off Switch and 2-Pin JST

[3 x AAA Battery Holder with On/Off Switch and 2-Pin JST](https://www.adafruit.com/product/727)
This battery holder connects 3 AAA batteries together in series for powering all kinds of projects. We spec'd these out because the box is slim, and 3 AAA's add up to about 3.3-4.5V, a very similar range to Lithium Ion/polymer (Li-Ion) batteries and have an on-off switch. That makes...

In Stock
[Buy Now](https://www.adafruit.com/product/727)
[Related Guides to the Product](https://learn.adafruit.com/products/727/guides)
### Mini Metal Speaker w/ Wires - 8 ohm 0.5W

[Mini Metal Speaker w/ Wires - 8 ohm 0.5W](https://www.adafruit.com/product/1890)
Listen up! This tiny 1" diameter speaker cone is the perfect addition to any small audio project where you need an 8 Ω impedance and will be using 0.5W or less of power. We particularly like this cone as it's very simple and its metal body is extremely lightweight. <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1890)
[Related Guides to the Product](https://learn.adafruit.com/products/1890/guides)
### 2-pin JST SM Plug + Receptacle Cable Set

[2-pin JST SM Plug + Receptacle Cable Set](https://www.adafruit.com/product/2880)
These 2-wire cables&nbsp;are 16cm long and come as a set. &nbsp;One side has a 2-pin JST SM type connector plug on the end. &nbsp;The other side has a matching 2-pin JST SM type receptacle connector. &nbsp;They are good for whenever you have 2 wires you want to be able to plug and unplug....

In Stock
[Buy Now](https://www.adafruit.com/product/2880)
[Related Guides to the Product](https://learn.adafruit.com/products/2880/guides)

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [Ultrasonic Sonar Distance Sensors](https://learn.adafruit.com/ultrasonic-sonar-distance-sensors.md)
- [SpaceX Helmet](https://learn.adafruit.com/spacex-helmet.md)
- [The MonkMakes Plant Monitor and CircuitPython](https://learn.adafruit.com/monkmakes-plant-monitor-and-circuitpython.md)
- [CircuitPython Basics: Analog Inputs & Outputs](https://learn.adafruit.com/circuitpython-basics-analog-inputs-and-outputs.md)
- [Pearl's Gem Weapon – Steven Universe](https://learn.adafruit.com/pearl-s-spear-steven-universe.md)
- [Make It Log](https://learn.adafruit.com/make-it-data-log-spreadsheet-circuit-playground.md)
- [Personal UV HotSpot Parasol](https://learn.adafruit.com/personal-blacklight-uv-parasol.md)
- [3D Printed Dragon Lamp](https://learn.adafruit.com/dragon-lamp.md)
- [Creating and sharing a CircuitPython library](https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library.md)
- [Epoxy Resin Torch Lamp with Touch Control & 3D Printed Base](https://learn.adafruit.com/epoxy-resin-torch-lamp-with-touch-control-3d-printed-base.md)
- [CircuitPython Hardware: PCA9685 DC Motor & Stepper Driver](https://learn.adafruit.com/micropython-hardware-pca9685-dc-motor-and-stepper-driver.md)
- [Spy Theme Playback Device](https://learn.adafruit.com/spy-theme-playback-device.md)
- [Sensor Plotting with Mu and CircuitPython](https://learn.adafruit.com/sensor-plotting-with-mu-and-circuitpython.md)
- [Music Box with Dancing Adabot](https://learn.adafruit.com/music-box-with-circuit-python.md)
- [Mystery Box: The Freefall Deck](https://learn.adafruit.com/mystery-box-freefall-deck.md)
- [Professor Bubbleton’s Breathing Head in a Jar](https://learn.adafruit.com/professor-bubbleton-s-breathing-head-in-a-jar.md)
