# 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")
## Related Guides

- [Sewable NeoPixels](https://learn.adafruit.com/flora-rgb-smart-pixels.md)
- [Adafruit Trinket M0](https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino.md)
- [Single Channel LoRaWAN Gateway for Raspberry Pi](https://learn.adafruit.com/raspberry-pi-single-channel-lorawan-gateway.md)
- [GEMMA M0 Case](https://learn.adafruit.com/gemma-m0-case.md)
- [Animatronic Fizzgig MonsterM4sk Puppet](https://learn.adafruit.com/animatronic-fizzgig-monsterm4sk-puppet.md)
- [Scrambled Number Security Keypad](https://learn.adafruit.com/scrambled-number-security-keypad.md)
- [CircuitPython 101: Basic Builtin Data Structures](https://learn.adafruit.com/basic-datastructures-in-circuitpython.md)
- [Using Crickit and Adafruit IO together](https://learn.adafruit.com/crickit-and-adafruitio.md)
- [NeoPixel Spats with Gemma and MakeCode](https://learn.adafruit.com/neopixel-spats.md)
- [Gemma M0 Sheikah Pendant](https://learn.adafruit.com/gemma-m0-sheikah-pendant.md)
- [Adafruit IO Basics: Digital Input](https://learn.adafruit.com/adafruit-io-basics-digital-input.md)
- [Proximity Based Lighting](https://learn.adafruit.com/proximity-based-lighting.md)
- [Phantom Mouse Jiggler](https://learn.adafruit.com/phantom-mouse-jiggler.md)
- [Make an AI Freezer Monitor](https://learn.adafruit.com/ai-freezer-monitor.md)
- [CircuitPython on the Arduino Nano RP2040 Connect](https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect.md)
- [CircuitPython Libraries on Linux and Google Coral](https://learn.adafruit.com/circuitpython-on-google-coral-linux-blinka.md)
- [Animating Animatronics](https://learn.adafruit.com/animating-animatronics.md)
