When I first became aware of Arduino, a theremin seemed like a natural project: sensor + actuator.  It turned out to be quite affordable and fun to make.  It is a naive design, using just one photocell and some hacked headphones.  After some experimentation, I decided that a  self-calibrating function was essential if I wanted repeatable performance in different light levels.  Also, I decided to autotune it using math instead of a lookup table.  To me, the pentatonic tuning is the most pleasant, although this can be adjusted easily to chromatic or other tuning schemes if desired.

Here's a list of the materials I used:

* Arduino Uno (running on Mac OS X 10.7.4 Intel)
* USB cable
* Breadboard
* Super-cheap earbud style headphones (from a plane flight, I think)
* standard small photocell
* 10K Ohm resistor
* Some wire
* Soldering gun with solder

Step 1: Hack the headphones

In order to send signals to the headphones, I cut the wires and soldered them to some jumper wires.  There are a few tricky points here. 

First, once you cut the wires and strip off some insulation, you should see 4 wires, 2 from each side.  Each pair forms a circuit with a single headphone.  So we can effectively think of each pair as containing a + wire (usually colored red or blue) and a ground wire (usually copper colored).  We can either just use 1 of the headphones (and thus one of the wire pairs), or we can combine the wires to use both, thereby achieving twice the fun.  To do this, we will want to solder the + wire from each pair together to one jumper wire, and the ground wire from each pair to the other jumper wire.  See detail photo of headphone hack above.

Second, beneath the obvious rubber insulation, there is often a mostly invisible resin layer coating the 4 individual wires.  The easiest way to get it off is to heat it with a lighter until the wires appear to burn briefly.  Note that after this is done, the colors can be very difficult to discern, so it is a good idea to leave a section unburned that you can use to identify them.  I also use a wet cloth to wipe of some of the residue from the burnt resin to improve conduction.

For the actual soldering, I have very primitive equipment, so I just twist the headphone wires together and around the jumper cable and then drip some solder on that.
<p>I also had problems with the sketch he provided, but with the advice of tomapatata I renamed the double variable logf to flogf and it worked just fine. I also did not need to solder my speaker wires to the jumper wires (since I don't have any solder supplies) but I just wrapped the speaker wires around the jumper wires and it works fine.</p>
<p>I'm getting some errors. ...sketch_feb22a.ino:13:8: error: 'double log' redeclared as different kind of symbol</p><p>/Users/mconstant/Downloads/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr/include/math.h:304:15: error: previous declaration of 'double log(double)'</p><p> extern double log(double __x) __ATTR_CONST__;</p><p> ^</p><p>sketch_feb22a.ino: In function 'void loop()':</p><p>sketch_feb22a.ino:62:8: error: assignment of function 'double log(double)'</p><p>sketch_feb22a.ino:62:8: error: cannot convert 'double' to 'double(double)' in assignment</p><p>In file included from sketch_feb22a.ino:8:0:</p><p>/Users/mconstant/Downloads/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Arduino.h:88:41: error: invalid operands of types 'double(double)' and 'double' to binary 'operator+'</p><p> #define round(x) ((x)&gt;=0?(long)((x)+0.5):(long)((x)-0.5))</p>
<p>I just had the same issue, you only need to rename the double variable named logf (I used flogf), probablly in line 9, because it overrides another variable from math.h library. You also need to rename it twice in void loop(). (At least that worked for me)</p>
<p>I'm having the same problem.. Solution?</p>
Turned out pretty well. Instead of headphones, I used a piezo buzzer. Also, I put in an LED and it looks awesome O_O
<p>totally cool! have you posted my resulting music on yutube or elsewhere?</p>
<p>@gwarbeh. Hi, I managed to make this cool project and even got it to work with a piezo buzzer, not with the headphones (probably joined the wrong cables)... But as an electronics virgin I can't figure out where to insert the values in the sketch to make a chromatic or pentatonic scale. Please help!</p>
<p>@gwarbeh, if you were to use an Ultrasonic Ping sensor rather than a photoresistor... how would your calibration and note mapping code change?</p>
<p>Hi, danielg19.</p><p>Not really sure, but my instinct is to say that you wouldn't have to change anything. Did you try it as is? The idea of the calibration loop is to adjust to whatever range of values you get. So if your ping sensor spits out totally different voltages than my photoresistor, it should still work as long as you give it a taste of the full range you want to use during calibration. I've never worked with the ping sensor. Maybe it will by more linear in response than the photoresistors. If so, the sound should be a lot easier to control. Let me know how it works out.</p>
<p>I'm getting this: 63:11: note: in expansion of macro 'round'</p><p>Error compiling.</p>
<p>added a push button before the speaker. though I'm sure I can put it anywhere, just so that I don't go insane with it on. this is a good activity to play with lots of variables.</p>
<p>Nice little job. Worked out of the box as you suggested. Used a buzzer for the audio out though. I'm gong to check into some of the mods. Thanks.</p>
<p>having some trouble with this project (my first), the sensor isn't getting any variation in its serial feed ( just 0,0,0) when you view it in the serial monitor. Any tips? the sensors work fine when tested and the circuits are correct when checked by a friend.</p>
<p>Hi! Can I ask you where I can get the sketch? I'm a beginner with Arduino and wanna practice with this project :)</p>
<p>Hi! Can I implement the code on windows 7?</p><p>Also I have a Arduino ng kit... Will this work fine???</p>
<p>Don't see why not. Just go to Arduino page and find the right download for you.</p>
ok. thanx... I will get back to u if need b... thanx <br>
<p>M a beginner... this being my first arduino project.... M doing it for my college technical fest... Plz help me... M a rookie!!!!!!!!!!! </p>
<p>No worries, nakul.tomarrajput. You can do it! Just follow the steps and let me know if you have other specific questions.</p>
Sounds great :-)
<p>Ha! This is the first thing I thought of making after I made aaaalll of the blinking LEDs. Thanks for a starting point and suggestions for improvements. :-D</p>
Is there anyway to get the theremin to be silent when in darkness, and only produce sound when light is introduced?
You could use a second photoresistor to act as the variable for an condition, putting the main function of the code inside the condition.
<p>Alternatively, loop could be modified as follows:</p><p>In place of:</p><p> tone(PHONES, f);</p><p>use:</p><p> if (val &gt; minored) {</p><p> tone(PHONES, f);</p><p> }</p><p> else {</p><p> notone(PHONES);</p><p> }</p><p>(Sorry about the weird linespacing, not sure how to coerce instructables into doing code snippets correctly.</p>
<p>I used your alternative, but I had to change your &quot;minored&quot; to &quot;minread&quot; and capitalize the t in notone (noTone), and then it worked awesome!!</p>
<p>Yep.... Sorry about the typos. Not sure how the casing got multilated on noTone. I copy/pasted it direct from the code. Probably autocorrect as minored appears to be an autocorrect from minread as well.</p>
<p>any reason as to why this won't compile on Ubuntu 12.x ? i keep getting errors dealing with double(double)'s etc.. </p><p>am i missing some libraries/includes it compiles fine in Win 7 environment.</p>
No idea. Never used Ubuntu. You could try changing all doubles to floats. I didn't use any special libraries. Good luck.
<p>The errors people are experiencing with the dobule/float issues are because logf is apparently a reserved (or at least used) word in a conflicting namespace in at least some versions of the Arduino IDE.</p><p>Renaming this variable to logfreq resolved all errors for me.</p>
<p>good circuit ,,, thanks :)</p>
Fun Stuff! I finally got around to trying this one out. Just like you I had a few pair of the airline headphones and they worked fine. I just used one pair it was hard to distinguish which was + or - but I lucked out and it worked first time around. Thanks for an entertaining afternoon. I am a big fan of Big Bang Theory. I felt like Sheldon while playing with my Theremin!
Glad you enjoyed it, &quot;Sheldon.&quot;
View Similar on <br>www.ieeexplorer.blogspot.in
Does it matter where in the breadboard I plug the wires as long as they are aligned and in the correct holes in the Arduino?
Just be sure that you understand the way a breadboard is wired, which holes are connected, etc. If you understand that, then you can hook up the wires however you want, as long as it's equivalent to my circuit. Good luck.
I noticed a couple of people used piezo's with success, I just tried it with a small 8 ohm speaker out of a kid's radio. It works well too.
I made a project similar to this. Then I shrunk it down to an ATtiny85 micro controller.<br> <br> Check it out here:<br> <a href="https://www.youtube.com/watch?v=BsKRtUCCle4" rel="nofollow">https://www.youtube.com/watch?v=BsKRtUCCle4</a>
I'm done with this project, and this is my first arduino project. Thanks a lot to you :) <br> <br>if I want to put potentiometer, where should i put? And what kind of potentiometer I should use? thanks before.
Cool. Does it work?<br>As for the potentiometer (pot), it depends on what you want it to do.<br><br>The pot can go in place of the resistor if you want it to affect the volume. A lower resistance will just let more cuurent through to the speaker. Not sure what all types of pots are available, but i'd try one that goes up to 100k; linear is probably fine.<br><br>If you put the pot in series with the photocell but before the A0 read, it could be used to affect pitch. You'd wanna use one with a max resistance similar to that of your photocell.<br>Good luck!
I want to try this cool project, but I'm a beginner in Arduino, for Step 3: Write the code, we're just have to write the code in sketch and that's it, or we have to do the step &quot;there are a lot of other things to be done:&quot;, because I really don't understand how to do the Variable definitions, Calibration loop, etc. Please help me..
Hi. The code should work as it is. All that about &quot;other things to be done&quot; is just me summarizing what the code is all about. You can just copy the code that I have there as an .rtf if you want. Then you can try fooling around with it to change it and/or learn how it works. Best of luck!
I wanted to save me having to use headphones and use a soldering iron and, as I have a piezo buzzer, I wondered if it would work well. The answer is a resounding yes, it sounds almost like your Theremin in the vid. Thanks for the code and the instructions!
I made a video here of mine. I plugged in a regular speaker from a set of desktop speakers. You can't really tell from the video but it does get fuller sound. <br> <br>http://www.youtube.com/watch?v=Opvzt_hryBE
Nice job, martzsam! Sounds good. Thanks for the comment.
pretty cool bro. im a master at circuitry and programming but new to microprosessors and the arduino programming language. u look good at all 3.
Thanks Trecool771<br><br>I am not a master of any of those, but I do enjoy learning.
I'v actually done stuff with headphones before, and its actually possible to weld the headphone wires with just a regular lighter. I had to do this once when I was in Italy on vacation: I needed a sound cable, and I didn't have access to hardly any of my tools, but fortunately I was able to weld two headphone wires together with that trick and use that.
Very cool, have you thought of reversing the way the sensor works, to no light being high frequency sound and low frequency when illuminated by light. Also maybe have the sound cut off at a certain brightness, so its not alway on.
Hi, judas79. <br>That's a really good idea. I think it will be part of the next version. Thanks.

About This Instructable


265 favorites


More by gwarbeh: Audio Laser Arduino Optical Theremin
Add instructable to: