# Trinket / Gemma Mini-Theremin

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/011/046/medium800/trinket_Theramin-breadboard.jpg?1379551158)

In the Adafruit [Arduino Lesson 10, Pseudo-Theramin](http://learn.adafruit.com/adafruit-arduino-lesson-10-making-sounds/pseudo-theramin "Link: http://learn.adafruit.com/adafruit-arduino-lesson-10-making-sounds/pseudo-theramin"), an Arduino Uno is combined with a light-sensitive cadmium sulfide (CdS) photocell to make a light responsive music machine. This project allows you do do the same with an Adafruit Trinket or Gemma mini-microcontroller. This project costs less and works in smaller circuits or wearable projects.  
  
Changes in light intensity on the photocell will change the pitch of a note on the piezo speaker as you wave your hand in front of the cell. While not a true theramin (which uses changes in a circuit's reactance), this project is much simpler to build.

![](https://cdn-learn.adafruit.com/assets/assets/000/011/045/medium800/trinket_Trinket-Theramin.jpg?1379548818)

Info: 

# Trinket / Gemma Mini-Theremin

## Wiring

 **Schematic**  
  
If using a solderless breadboard, first solder pin headers on your Trinket board (they come included). For GEMMA you can use alligator jumpers. The parts you need are at right. You will need a resistor, nominally 1K to 10K ohms but this can vary a bit if you do not have that value, just do not make it too low or high.  
  
Pins used:

- GPIO #0 (Digital 0) is connected to the signal pin (+) on the piezo speaker.
- GPIO #2 (Analog 1) is connected to the junction of the photocell and the resistor.

You can power the circuit&nbsp;from the USB connection or from an external supply connected to BAT (or Vout on GEMMA)&nbsp;as shown below (4 to 6&nbsp;volts DC).

![](https://cdn-learn.adafruit.com/assets/assets/000/011/048/medium800/trinket_Trinket-Theramin.jpg?1379599704)

Primary: 

You should not hook a low impedance speaker in place of the piezo without additional circuitry. A speaker has a low DC resistance and may try to draw too much current from the microcontroller. A 100 ohm resistor in series may help, and it could be coupled with a 10 to 50 microfarad capacitor.

# Trinket / Gemma Mini-Theremin

## Arduino Code

Info: 

Here's the sketch, it's pretty simple.

- As more or less light hits the face of the CdS photo cell, the resistance changes
- When the resistance changes, the voltage on the analog pin will vary up and down
- We read the analog voltage from the analog pin
- We 'scale' the analog voltage to a frequency, then 'beep' the piezo buzzer to match
- ...and repeat!  

Danger: 

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Gemma/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino

You will note the tone function used in the Uno lesson is not used. The Arduino IDE does not implement tone for the ATtiny85 used for the Trinket and Gemma.  
  
The beep function in the code above will work in a similar fashion. It does not use the hardware pulse width modulation on the microcontroller, so you may use it to output a tone signal on any digital pin you have free.

# Trinket / Gemma Mini-Theremin

## CircuitPython Code

![](https://cdn-learn.adafruit.com/assets/assets/000/047/425/medium800/trinket_CircuitPython-Gemma-w-Blinka.jpg?1508447323)

 **Trinket M0** and **GEMMA&nbsp;M0** boards can&nbsp;run **CircuitPython** &nbsp;— a different approach to programming compared to Arduino sketches. In fact, **CircuitPython comes&nbsp;factory pre-loaded on these boards**. If you’ve overwritten it with an Arduino sketch, or just want to learn the basics of setting up and using CircuitPython, this is explained in the **[Adafruit Trinket M0](../../../../adafruit-trinket-m0-circuitpython-arduino/circuitpython)** and&nbsp;[**Adafruit GEMMA&nbsp;M0**](../../../../adafruit-gemma-m0/circuitpython-setup-1)&nbsp;guides.

Info: 

Below is CircuitPython code that works&nbsp;similarly&nbsp;to&nbsp;the Arduino sketch shown on the&nbsp;prior page. To use this, plug the Trinket/GEMMA M0 into USB…it should show up on your computer as a small **flash drive** …then edit the file “ **main.py** ” with your text editor of choice. Select and copy the code below and paste it into that file, **entirely replacing its contents** (don’t mix it in with lingering bits of old code). When you save the file, the code should **start running almost immediately** &nbsp;(if not, see notes at the bottom of this page).

**If Trinket or GEMMA M0 doesn’t show up as a&nbsp;drive, follow the corresponding&nbsp;guide link above to prepare the board for CircuitPython.**

Info: 

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

# Trinket / Gemma Mini-Theremin

## Demonstration and Going Further

Here is the circuit in action:

http://www.youtube.com/watch?v=MjDOewPg6VA

 **Going Further**  
  
You may change either the SCALE variable or even the entire calculation of the frequency freq. There is nothing you can do to "break" the sound values generated to feel free to vary the numbers generated, the time the tone is generated, and the delay between tones.   
  
You can generate precise notes by selecting the correct frequency. Which notes correspond to which frequencies may be found at [http://en.wikipedia.org/wiki/Mathematics\_of\_musical\_scales](http://en.wikipedia.org/wiki/Mathematics_of_musical_scales "Link: http://en.wikipedia.org/wiki/Mathematics\_of\_musical\_scales")
## Featured Products

### Adafruit Trinket - Mini Microcontroller - 5V Logic

[Adafruit Trinket - Mini Microcontroller - 5V Logic](https://www.adafruit.com/product/1501)
 **Deprecation Warning: The Trinket bit-bang USB technique it uses doesn't work as well as it did in 2014, many modern computers won't work well. So while we still carry the Trinket so that people can maintain some older projects, we no longer recommend it.** <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1501)
[Related Guides to the Product](https://learn.adafruit.com/products/1501/guides)
### Adafruit Trinket - Mini Microcontroller - 3.3V Logic

[Adafruit Trinket - Mini Microcontroller - 3.3V Logic](https://www.adafruit.com/product/1500)
 **Deprecation Warning: The Trinket bit-bang USB technique it uses doesn't work as well as it did in 2014, many modern computers won't work well. So while we still carry the Trinket so that people can maintain some older projects, we no longer recommend it.** <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1500)
[Related Guides to the Product](https://learn.adafruit.com/products/1500/guides)
### Adafruit Trinket M0 - for use with CircuitPython & Arduino IDE

[Adafruit Trinket M0 - for use with CircuitPython & Arduino IDE](https://www.adafruit.com/product/3500)
The&nbsp;Adafruit Trinket M0 may be small, but do not be fooled by its size! It's a tiny microcontroller board, built around the Atmel ATSAMD21, a little chip with _a lot_ of power. We wanted to design a microcontroller board that was small enough to fit into any project, and low...

In Stock
[Buy Now](https://www.adafruit.com/product/3500)
[Related Guides to the Product](https://learn.adafruit.com/products/3500/guides)
### Adafruit GEMMA v2 - Miniature wearable electronic platform

[Adafruit GEMMA v2 - Miniature wearable electronic platform](https://www.adafruit.com/product/1222)
 **Deprecation Warning: The Gemma bit-bang USB technique it uses doesn't work as well as it did in 2014, many modern computers won't work well. So while we still carry the Gemma so that people can maintain some older projects, we no longer recommend it.** <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1222)
[Related Guides to the Product](https://learn.adafruit.com/products/1222/guides)
### Adafruit GEMMA M0 - Miniature wearable electronic platform

[Adafruit GEMMA M0 - Miniature wearable electronic platform](https://www.adafruit.com/product/3501)
The **Adafruit Gemma M0** is a super small microcontroller board, with just enough built-in to create many simple projects. It may look small and cute: round, about the size of a quarter, with friendly alligator-clip sew pads. But do not be fooled! The Gemma M0 is incredibly...

In Stock
[Buy Now](https://www.adafruit.com/product/3501)
[Related Guides to the Product](https://learn.adafruit.com/products/3501/guides)
### Photo cell (CdS photoresistor)

[Photo cell (CdS photoresistor)](https://www.adafruit.com/product/161)
CdS cells are little light sensors. As the squiggly face is exposed to more light, the resistance goes down. When it's light, the resistance is about ~1KΩ, when dark it goes up to ~10KΩ.

To use, connect one side of the photocell (either one, it's symmetric) to power...

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

[Piezo Buzzer](https://www.adafruit.com/product/160)
Piezo buzzers are used for making beeps, tones and alerts. This one is petite but loud! Drive it with 3-30V peak-to-peak square wave. To use, connect one pin to ground (either one) and the other pin to a square wave out from a timer or microcontroller. For the loudest tones, stay around 4 KHz,...

In Stock
[Buy Now](https://www.adafruit.com/product/160)
[Related Guides to the Product](https://learn.adafruit.com/products/160/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

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

## Related Guides

- [Adafruit Trinket M0](https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino.md)
- [3D Printed Camera LED Ring](https://learn.adafruit.com/3d-printed-camera-led-ring.md)
- [Sound Reactive NeoPixel Peace Pendant](https://learn.adafruit.com/sound-reactive-neopixel-peace-pendant.md)
- [Textile Potentiometer Hoodie](https://learn.adafruit.com/textile-potentiometer-hoodie.md)
- [Your Very First Circuit Sculpture](https://learn.adafruit.com/first-simple-circuit-sculpture.md)
- [Using MPL3115A2 with CircuitPython](https://learn.adafruit.com/using-mpl3115a2-with-circuitpython.md)
- [3D Printed Glowing Mace Prop](https://learn.adafruit.com/3d-printed-glowing-mace-prop.md)
- [NeoPixel Ring Bangle Bracelet](https://learn.adafruit.com/neopixel-ring-bangle-bracelet.md)
- [IRIS LED and Prop Guards](https://learn.adafruit.com/iris-leds-prop-guards.md)
- [Esenciales para CircuitPython](https://learn.adafruit.com/esenciales-para-circuitpython.md)
- [3D Printed LED Fire Horns](https://learn.adafruit.com/3d-printed-led-fire-horns.md)
- [Gemma LightTouch](https://learn.adafruit.com/gemma-lighttouch.md)
- [GEMMA M0 Case](https://learn.adafruit.com/gemma-m0-case.md)
- [Gemma 3D Printed Tree Topper](https://learn.adafruit.com/gemma-3d-printed-tree-topper.md)
- [NeoPixel 60 Ring Wall Clock](https://learn.adafruit.com/neopixel-60-ring-clock.md)
- [Twinkly Earwarmer Headband](https://learn.adafruit.com/twinkly-ear-warmer.md)
