NerdKits Theremin Halloween Costume

NerdKits Theremin Halloween Costume


Hi. Last year around Halloween, we brought
you our capacitive touch sensor video, which you could use to spook victims reaching into
your candy bowl. Like I mentioned in that video, my favorite thing about this holiday
is that I get to wear a cape outdoors, but a close second is the fact that I get to strap
electronics on my clothing, and call it a creative costume. A marathon brainstorming session of our R&D
team over lunch last Tuesday yielded our official NerdKits Halloween costume for the year: the
human theremin. Here is a clip of it in action. A theremin is a musical instrument that is
played without any physical contact with the instrument. It has two antennae that sense
the position of the performers hands. One hand controls the pitch of the note, and the
other controls the volume or amplitude of the note. For our project, we simplified the concept
a little and are using two infrared LED and phototransistor pairs — one pair mounted
on each wrist. The infrared LED is emitting infra red light, which bounces off the musician’s
hands and back into the phototransistor. When the player moves his or her hand closer,
more light bounces back and is detected by the phototransistor. Here is a look at the simple circuit that
runs the hand position detector. On the LED side, we use a current limiting resistor so
we can dictate the amount of current going through the LED. On the other side, we use
the fact that the phototransistor will pass a small current based on how much infrared
light it is receiving. This current will flow through the resistor and create a voltage
across it, remember V=IR. We take that voltage and run it over to the analog to digital converter
on our our microcontroller. On the microcontroller we use PWM to create
a triangle wave. In our making music with a microcontroller
video we showed you how you can use PWM to create a square wave to make musical tones.
In this project we went with a triangle wave because it sounded smoother, and less scratchy
sound, and ultimately just spookier. Let’s take a second to talk about how make
a triangle wave using PWM. With PWM, you are stuck outputting a square wave a certain duty
cycle. We vary that duty cycle to create the output value we want. So to create a triangle
wave, we first output a duty cycle of 1, then a duty cycle of 2 all the way up to 255, then
back down again. If you smooth out those pulses over time, you get a triangle wave. Here on the yellow trace we are seeing the
PWM signal on our oscilloscope. If I scroll across, you can see the duty cycle increasing,
and then decreasing. On the green trace, we are seeing a smoothed out version of the signal.
And if I zoom out, you can see the triangle wave. To make a higher pitched triangle wave we
just increase the duty cycle by two at every go around, which means we reach 255 faster,
making the frequency twice as high. In order to give us more resolution in the
variability of the frequency, and not have to resort to using floating point numbers,
we used a fixed point decimal representation. This is actually nothing too complex, but
it can take a bit to wrap your head around it if you are not used to it. The basic idea
is this: instead of representing our step size using an 8 bit integer, we represent
it using a 16 bit integer, and just pretend amongst ourselves that there is a decimal
point separating the bottom 8 bits from the top 8 bits. When it comes time to actually
increase the PWM value we chop off the top 8 bits and use that. This means that in order
to increase this number by 1, we have to add 256 to it. Anything less we add would increase
it by a fractional amount. So adding 128 to the number actually increases the step size
by a half. This might sound like a really strange to do, but having the ability to increase
the step size by a fractional amount lets us create that really smooth pitch change
as your hand moves up and down. If you are curious about this, take a look through the
source code for this project, it can be a very useful trick to know when speed prevents
you from using floating point math. To actually output the sound we just use our
piezo electric buzzer at the output of the PWM. Take a look at our making music with
a micrcontroller video for more on how the buzzer turns a voltage into a sound. The direct
output of the PWM was sufficiently spooky enough for us. You might try adding a low
pass filter to yours if you want a smoother sound, or you could hook up a real speaker
if you want to be louder and draw even more attention to yourself. What makes this costume particularly great
is that it has interactive component to it. Now when you are at your Halloween party and
someone asks you what you are dressed as you have more than a one word answer followed
by an awkward silence. Instead you can show them how to use your costume, and proceed
to have a roaring good time as your project becomes the life of the party. We hope you have learned a little bit about
PWM and using IR as close range distance sensor, or at worst, got a neat idea for a Halloween
costume. For more information about our kits, and more videos like this one, visit us at
www.nerdkits.com.

Leave a Reply

Your email address will not be published. Required fields are marked *