Step 2: Hook it up

Each of the three switches go from ground to analog in 1, 2, and 3. The Piezo goes from digital pin 9 to ground. Make sure to have the switches in the right order in order to have the correct fingerings. Afterwords, download the file and upload it to your Arduino.
<p>it may have been possible to include another octave by adding a sensor that you could &quot;blow&quot; or just hold infront of your face, this could be achieved by a light sensitive or pressure sensitive module. LOVE the project though ! </p>
<p>What would i have to change to use a buzzer instead of a speaker?</p>
<p>Arduino is FUN! and it is cheap now!<br>https://sites.google.com/site/arduinouk/</p>
is it a speaker or a buzzer ??
<p>could have more pictures for the wiring?</p>
Does this project need a breadboard?
Cool IDea, <br>I took your idea, and instead of buttons i used potentiometers, just to see what would happen, it was kinda cool, you could get and hold various tones, might be fun if some one knew how to hack the code to read the potentiometer values, so it was more then an on or off type thing, any cool idea, i also like the piezo blow hole idea, read hears somewhere. <br>PEACE~ <br>Hankenstien <br>rduino.com
Adding a pressure sensor wouldn't be hard at all. You just need something like a MPX2010DP differential pressure transducer then feed it into an op-amp comparitor / amplifier, then read that with analog in on the Arduino. I've just done exactly that for a totally different purpose (measuring the depth of a water tank) and the circuit I built would work perfectly in this trumpet. In fact while building it I tested the circuit by blowing into the transducer and watching the analog read value change! There's more about it here including a photo of the shield: <a rel="nofollow" href="http://www.practicalarduino.com/news/id/101">http://www.practicalarduino.com/news/id/101</a><br/>
&nbsp;hello sir its great to hear as that we can use a DPT but sir i have a major problem making the transducer work for your own application for &nbsp;TANK DEPTH SENSOR. Sir i kindly oblige you to help me or teach how to work on DPT. please my sincere request please i would be glad if u could give me your facebook userbook i really need to chat with u sir.please.
&nbsp;@srikarbeechu Have you read the explanation in the book? I can't really help you unless I know what you've tried.
@ jonoxer sir kindly help me how to work with MPX@)!)DP DPT... i am unable to measure the output voltage of the transducer and the water tank depth sensor experiment.&nbsp;
That's great !<br /> How can we do to have more sound from the piezo ?<br /> Have we to put an amplifier or something else&nbsp;?<br /> Thanks !<br />
&nbsp;Would you be able to modify this code to use with a guitar hero guitar? So when you press the frets and strum the bar it plays the tones. That's what I'm planning on doing.
don't you need a pull down resistor or somthing&nbsp;
No vote until I hear it. How do I know if yours even works? Come on just a little blues or some Louie Armstrong.
It would theoretically work, And most likely would too, by looking at the code. Though it might sound a bit bad, as it generates square waves, the only easy way to create sound in the arduino, it would sound better if it was a sine wave...
Yah the square wave is kind-of robotic but it gets the job done.
Yeah it sure does ;)
It sounds fine I made it and it works. I'm in the process of making it only work if you press a button and making it light up when you press down the valves.
Well then, It works, Just as i thought, Well good luck with that ;)
This is really cool. However I have some suggestions. One, there is a page on the arduino website which has a number of sound related project/things here: <a rel="nofollow" href="http://www.arduino.cc/playground/Main/InterfacingWithHardware#Output">http://www.arduino.cc/playground/Main/InterfacingWithHardware#Output</a><br/>Which has some interesting stuff on generating sound or playing it. Also this page: <a rel="nofollow" href="http://www.arduino.cc/en/Tutorial/Melody">http://www.arduino.cc/en/Tutorial/Melody</a> has code for playing a pre coded series of tones on a piezo speaker/earphone and has the actual tones as variables. That think is a little easier. Like: a = 946; (that's not actually true) and then something like this: play(a) I'm thinking you might be able to simply/optimize/shorten your code to make it a little less complicated.<br/>
I based mine off the melody example.
Ah, ok. I',m curious why you chose not to have one function and preset tonal values, but rather a function for each sound.
Its more fun the overly complicated way :D
Um sorry if i'm being a noob but would &lt;a rel=&quot;nofollow&quot; href=&quot;http://www.dipmicro.com/store/index.php?act=viewProd&amp;productId=767&quot;&gt;this&lt;/a&gt; piezo work?&lt;br/&gt;<br/>
It would work but it's operating voltage is 1.5v so you'll need a resistor. Also it's sound level is 75db, that's pretty loud.
Now imagine Pumping 5V into that sucker, I guess that the sound level could reach 200DB O_O
I'm just starting in electronics so could you please tell me where to put the resistor (i think on the + wire of the piezo connecting to pin 9) and what the value of the resistor would be. Sorry for all of the questions. Thanks in advance.
I use <a rel="nofollow" href="http://led.linear1.org/led.wiz">this</a> to help me with resistors. You'll need a 56ohm resistor. Thats green blue black and attach it to a leg of the Piezo to pin 9 or ground.<br/>
Ok thank you so much! I'll start building it as soon as i get my arduino in a day or two.
This is actually pretty good! I get the code pretty well, I understand it, I will try this when i get my arduino, i am ordering one ;)
code does not work
it should, but since you are providing so much information there is just too much we can do to help you.
i fixed the code problem. It was missing a "{" at the end.
Well then, It was missing the closing bracket? He still should have provided some more information...
wow i can now play the trumpet again!!<sup>i have played for 4 years but i have braces now</sup><br/>
Ive played for 3 years and got braces last month... I can still play the same
Wait till you take them off.... that's when it gets hard.
low c is open btw
if you read it says he had to modify it for the programming ;)
yea... i read that right affter i posted that
I played for 2 years, got braces, and started playing again the next day. I can still play higher than some of my fellow band-mates. I do play the trombone, but I can't imagine it makes too much of a difference.
I have braces also and it sucks. I can only reach a high 'C'. (above the staff 'C')
i haven't played in over a year my band theacher was a b$!@# so i quit (she would always pick on me)
I have a few questions: Does that mean it plays constantly until it's turned off? Do you know if an air pressure sensor could be used to make it more realistic?
i had the same thought
I'm sure that everyone did :P Everyone that read the code, anyway. I think it should have some kind of sensor or at least a button for realism, and so that it only plays when you want it to. But otherwise, looks nice.
Please don't take this as a criticism of your work, this is an awesome project, and it looks really impressive. I'm into robot building, and so I'm a bit obsessive compulsive about short code and short runtime. Here are a couple of ways to make this code a bit cleaner and a tiny bit faster. Since this is a timing-based program, speed is of the essence.<br/><br/>First, you can define your speaker and switch ports using #define instead of declaring them as integer variables. Declaring them as variables stores the value in the memory register instead of in the program itself, which takes up registers, and requires a lookup every time you want to recall the pin value. By defining them, when you compile, the compiler automatically inserts the values themselves into the program, requiring no lookup, making the whole process faster. It would look like this:<br/><br/>#define speaker 9<br/>#define sw1 15<br/>#define sw2 16<br/>#define sw3 17<br/><br/>Second, the brackets on all of those if() statements are not strictly necessary. To make it cleaner, you can do it without any brackets at all because you're only running one line of code. It would look like this:<br/><br/>if ((valve1 == LOW) &amp;&amp; (valve2 == LOW) &amp;&amp; (valve3 == LOW)) c();<br/>else if ((valve1 == LOW) &amp;&amp; (valve2 == HIGH) &amp;&amp; (valve3 == LOW)) d();<br/>else if ((valve1 == LOW) &amp;&amp; (valve2 == LOW) &amp;&amp; (valve3 == HIGH)) e();<br/>else if ((valve1 == LOW) &amp;&amp; (valve2 == HIGH) &amp;&amp; (valve3 == HIGH)) f();<br/>else if ((valve1 == HIGH) &amp;&amp; (valve2 == HIGH) &amp;&amp; (valve3 == HIGH)) g();<br/>else if ((valve1 == HIGH) &amp;&amp; (valve2 == HIGH) &amp;&amp; (valve3 == LOW)) a();<br/>else if ((valve1 == HIGH) &amp;&amp; (valve2 == LOW) &amp;&amp; (valve3 == HIGH)) b();<br/>else if ((valve1 == HIGH) &amp;&amp; (valve2 == LOW) &amp;&amp; (valve3 == LOW)) C();<br/>else delay(1);<br/><br/>This is obviously with the comments removed, but you can see what I mean. This makes absolutely no difference in performance and is just for readability. It's pure individual preference, so if you like it the other way, feel free to completely ignore me. And the integer/define thing isn't really necessary if it works, it just makes it run a tiny bit faster in case you ever want to get more advanced. Do like very much, though! I'd love to see what this is like with an emulated trumpet waveform output.<br/><br/>Keep doing stuff like this, it's awesome!<br/>
Thanks for that. But I recognised that the code would take a while to read and found out it took 10 microseconds longer on the bottom of the square wave than the top. Thats why its 10 off:<br/><br/>void a () {<br/>digitalWrite(speaker, HIGH);<br/>delayMicroseconds(<strong>1136</strong>);<br/>digitalWrite(speaker, LOW);<br/>delayMicroseconds(<strong>1126</strong>);<br/>}<br/>

About This Instructable


195 favorites


Bio: I love the TV shows Psych and Monk Bands Relient K and Anberlin destroying things making things swimming and having fun.
More by QuiksilverRox: Arduino Christmas Lights Arduino Trumpet 2gen Ipod touch jailbreak
Add instructable to: