Theremin
Introduction
A theremin is a musical instrument that is played by holding your hand in front of a sensor. The farther out from the sensor, the higher the tone.
Today, we’re going to make Sparki into a theremin, using the ultrasonic range finder as input, and the buzzer as output.
What You’ll Need
- A Sparki.
How It Works
This program makes Sparki into a theremin, using Sparki’s ultrasonic distance sensor to measure the hand distance, and the buzzer to play the tone:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <Sparki.h> // include the sparki library void setup() { } void loop() { int note = sparki.ping(); // measure the distance in front of the sensor if ( note != -1 ) // meke sure there is no error { sparki.beep(note*10); // plays a note proportional to the distance } if ( note > 100 ) // if the distance is too far, turn off the tone { sparki.noBeep(); } delay(10); } |
Related Lessons
If you have enjoyed what you have learned here, and if you have not read it yet, you may find the other lesson about making music interesting: Making Music with the Accelerometer.