Introduction: Arduino Trumpet

This project emulates a trumpet by playing notes using the three buttons (valves). This is easy to make and fun to play with, though it can only play one octave and no sharps/flats.

Step 1: Code

Load this into your Arduino:



int speaker = 9; // Hook up speaker to digital pin 9
int sw1 = 15; // Switch hooked to analog pin 1
int sw2 = 16; // Switch hooked to analog pin 2
int sw3 = 17; // Switch hooked to analog pin 3
int valve1;
int valve2;
int valve3;

void c () { // Presets the note "c" to be used later
digitalWrite(speaker, HIGH);
delayMicroseconds(1915);
digitalWrite(speaker, LOW);
delayMicroseconds(1905);
}
void d () {
digitalWrite(speaker, HIGH);
delayMicroseconds(1700);
digitalWrite(speaker, LOW);
delayMicroseconds(1690);
}
void e () {
digitalWrite(speaker, HIGH);
delayMicroseconds(1519);
digitalWrite(speaker, LOW);
delayMicroseconds(1509);
}
void f () {
digitalWrite(speaker, HIGH);
delayMicroseconds(1432);
digitalWrite(speaker, LOW);
delayMicroseconds(1422);
}
void g () {
digitalWrite(speaker, HIGH);
delayMicroseconds(1275);
digitalWrite(speaker, LOW);
delayMicroseconds(1265);
}
void a () {
digitalWrite(speaker, HIGH);
delayMicroseconds(1136);
digitalWrite(speaker, LOW);
delayMicroseconds(1126);
}
void b () {
digitalWrite(speaker, HIGH);
delayMicroseconds(1014);
digitalWrite(speaker, LOW);
delayMicroseconds(1004);
}
void C () {
digitalWrite(speaker, HIGH);
delayMicroseconds(956);
digitalWrite(speaker, LOW);
delayMicroseconds(946);
}

void setup() {
pinMode(speaker, OUTPUT);
pinMode(sw1, INPUT);
digitalWrite(sw1, HIGH);
pinMode(sw2, INPUT);
digitalWrite(sw2, HIGH);
pinMode(sw3, INPUT);
digitalWrite(sw3, HIGH);
// Serial.begin(9600);
}

void loop() {
valve1 = digitalRead(sw1); // Reads switch 1
valve2 = digitalRead(sw2); // Reads switch 2
valve3 = digitalRead(sw3); // Reads switch 3

if ((valve1 == LOW) && (valve2 == LOW) && (valve3 == LOW)) { // If all valves are pressed, then
c(); // It plays a "c"
}
else if ((valve1 == LOW) && (valve2 == HIGH) && (valve3 == LOW)) { // If the first and third valves are pressed, then
d(); // It plays a "d"
}
else if ((valve1 == LOW) && (valve2 == LOW) && (valve3 == HIGH)) { // If the first and second valves are pressed, then
e(); // It plays a "e"
}
else if ((valve1 == LOW) && (valve2 == HIGH) && (valve3 == HIGH)) { // If the first valve is pressed, then
f(); // It plays a "f"
}
else if ((valve1 == HIGH) && (valve2 == HIGH) && (valve3 == HIGH)) { // If no valves are pressed, then
g(); // It plays a "g"
}
else if ((valve1 == HIGH) && (valve2 == HIGH) && (valve3 == LOW)) { // If the third valve is pressed, then
a(); // It plays a "a"
}
else if ((valve1 == HIGH) && (valve2 == LOW) && (valve3 == HIGH)) { // If the second valve is pressed, then
b(); // It plays a "b"
}
else if ((valve1 == HIGH) && (valve2 == LOW) && (valve3 == LOW)) { // If the second and third valves are pressed, then
C(); // It plays a "C"
}
else{
delay(1);
}
}

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.

Step 3: Materials

You will need:

-Arduino
-9v battery and clasp
-3 momentary switches (NO)
-Project box (4x2x1)
-Piezo speaker element
-Header pins
-Soldering stuff
-Hotglue
-Dremel
-Drill and 1/4 in bit along with 1/16 in

Step 4: Put It Together!!

First, open the box and on the outside, mark the center and an inch out from the center. These marks are where you will need to make a 1/4 in hole ( I would suggest using a pilot hole).

Now, dremel out the scraps of plastic and the holders used to hold a PC inside, we will not be needing these.

Step 5: Make It Fit

Insert the switches and make sure they fit and screw them in.

Insert the pins into the correct spot and then mark the case where they are and drill holes with a 1/16 in drill bit. Then, make sure it fits and then flip it over to the open side.

Step 6: Wireing

Now, solder a wire to each of the analog input posts and attach the other side to the corresponding switch. Make sure to not get mixed up and solder the wrong switch to the wrong pin. The other side goes to ground. Sound Fimiliar?

Like before, solder the piezo to pin 9 and ground and the battery clasp to ground and voltage in.

Then, Hotglue over the solder connections on the pins, and attach the battery, you should hear a tone, if not check your wireing.

Afterwords, cram in the battery and piezo, its a tight fit! I found it best to put the speaker by the pins and the battery on the other side. Whatever works.

Step 7: Playing

The fingerings on this trumpet are 'similar' to a normal trumpet. By 'similar' I mean I had to make a few changes.


on a normal trumpet its like this:
c..........0pen
d..........1-3
e..........1-2
f ..........1
g..........0pen / 1-3
a..........1-2 / 3
b..........2
C..........0pen / 2-3

On the Arduino Trumpet:
c..........1-2-3
d..........1-3
e..........1-2
f ..........1
g..........0pen
a..........3
b..........2
C..........2-3

I could have complicated things and put an octive changing switch and used half steps. Though it would be awsome, It would be more complicated and I would need a bigger box.

HAVE FUN

Comments

author
josei_ng (author)2016-07-19

Whats the schematic drawing of the circuit?

author
MikenHarnish (author)2016-04-17

how do you write more notes in? like another octave

author
RaeganH (author)2016-04-15

i am a middle school student that did this for a class project. could someone help me with adding another button to be the rest or something. i cant have the constant noise.

author
Lintang_Wisesa made it! (author)2016-02-02

Nice tutorial, here's mine: https://youtu.be/K7X3c-rtCKY ^_^

75. 2016 - Trompeto Uno.jpg
author
TomB88 (author)2015-11-09

it may have been possible to include another octave by adding a sensor that you could "blow" or just hold infront of your face, this could be achieved by a light sensitive or pressure sensitive module. LOVE the project though !

author
nmrobotics (author)2015-06-05

What would i have to change to use a buzzer instead of a speaker?

author
Arduino Tech (author)2014-11-05

is it a speaker or a buzzer ??

author
pyromaniac123456789 (author)2014-01-20

could have more pictures for the wiring?

author
Maker1721 (author)2012-11-24

Does this project need a breadboard?

author
hankenstien (author)2012-06-20

Cool IDea,
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.
PEACE~
Hankenstien
rduino.com

author
jonoxer (author)2009-06-11

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: http://www.practicalarduino.com/news/id/101

author
srikarbeechu (author)jonoxer2010-05-03

 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  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.

author
jonoxer (author)srikarbeechu2010-05-03

 @srikarbeechu Have you read the explanation in the book? I can't really help you unless I know what you've tried.

author
srikarbeechu (author)jonoxer2010-05-03

@ 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. 

author
no0x (author)2010-03-13

That's great !
How can we do to have more sound from the piezo ?
Have we to put an amplifier or something else ?
Thanks !

author
Kulf (author)2010-03-11

 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.

author
mman1506 (author)2009-11-07

don't you need a pull down resistor or somthing 

author
Ouroboros439 (author)2009-06-11

No vote until I hear it. How do I know if yours even works? Come on just a little blues or some Louie Armstrong.

author
ReCreate (author)Ouroboros4392009-09-18

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...

author
QuiksilverRox (author)ReCreate2009-09-19

Yah the square wave is kind-of robotic but it gets the job done.

author
ReCreate (author)QuiksilverRox2009-09-19

Yeah it sure does ;)

author
Mdob (author)ReCreate2009-09-19

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.

author
ReCreate (author)Mdob2009-09-19

Well then, It works, Just as i thought, Well good luck with that ;)

author
Istarian (author)2009-06-11

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: http://www.arduino.cc/playground/Main/InterfacingWithHardware#Output
Which has some interesting stuff on generating sound or playing it. Also this page: http://www.arduino.cc/en/Tutorial/Melody 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.

author
QuiksilverRox (author)Istarian2009-06-11

I based mine off the melody example.

author
Istarian (author)QuiksilverRox2009-06-11

Ah, ok. I',m curious why you chose not to have one function and preset tonal values, but rather a function for each sound.

author
ReCreate (author)Istarian2009-09-18

Its more fun the overly complicated way :D

author
Mdob (author)2009-07-04

Um sorry if i'm being a noob but would <a rel="nofollow" href="http://www.dipmicro.com/store/index.php?act=viewProd&productId=767">this</a> piezo work?<br/>

author
QuiksilverRox (author)Mdob2009-07-05

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.

author
ReCreate (author)QuiksilverRox2009-09-18

Now imagine Pumping 5V into that sucker, I guess that the sound level could reach 200DB O_O

author
Mdob (author)QuiksilverRox2009-07-05

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.

author
QuiksilverRox (author)Mdob2009-07-05

I use this 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.

author
Mdob (author)QuiksilverRox2009-07-06

Ok thank you so much! I'll start building it as soon as i get my arduino in a day or two.

author
ReCreate (author)2009-06-26

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 ;)

author
blackwellj (author)2009-06-16

code does not work

author
ReCreate (author)blackwellj2009-06-25

it should, but since you are providing so much information there is just too much we can do to help you.

author
QuiksilverRox (author)ReCreate2009-06-26

i fixed the code problem. It was missing a "{" at the end.

author
ReCreate (author)QuiksilverRox2009-06-26

Well then, It was missing the closing bracket? He still should have provided some more information...

author
hg341 (author)2009-06-04

wow i can now play the trumpet again!!i have played for 4 years but i have braces now

author
Wafflicious (author)hg3412009-06-05

Ive played for 3 years and got braces last month... I can still play the same

author
Bartboy (author)Wafflicious2009-06-06

Wait till you take them off.... that's when it gets hard.

author
Wafflicious (author)Bartboy2009-06-24

Lol

author
hg341 (author)hg3412009-06-04

low c is open btw

author
reywolf (author)hg3412009-06-14

if you read it says he had to modify it for the programming ;)

author
hg341 (author)reywolf2009-06-15

yea... i read that right affter i posted that

author
Damage, Inc. (author)hg3412009-06-05

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.

author
QuiksilverRox (author)hg3412009-06-04

I have braces also and it sucks. I can only reach a high 'C'. (above the staff 'C')

author
hg341 (author)QuiksilverRox2009-06-05

i haven't played in over a year my band theacher was a b$!@# so i quit (she would always pick on me)

author
scooterkid92 (author)2009-06-06

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?

author
abadfart (author)scooterkid922009-06-08

i had the same thought

About This Instructable

49,045views

249favorites

License:

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 LightsArduino Trumpet2gen Ipod touch jailbreak
Add instructable to: