Arduino Trumpet





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);
digitalWrite(speaker, LOW);
void d () {
digitalWrite(speaker, HIGH);
digitalWrite(speaker, LOW);
void e () {
digitalWrite(speaker, HIGH);
digitalWrite(speaker, LOW);
void f () {
digitalWrite(speaker, HIGH);
digitalWrite(speaker, LOW);
void g () {
digitalWrite(speaker, HIGH);
digitalWrite(speaker, LOW);
void a () {
digitalWrite(speaker, HIGH);
digitalWrite(speaker, LOW);
void b () {
digitalWrite(speaker, HIGH);
digitalWrite(speaker, LOW);
void C () {
digitalWrite(speaker, HIGH);
digitalWrite(speaker, LOW);

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"

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:

-9v battery and clasp
-3 momentary switches (NO)
-Project box (4x2x1)
-Piezo speaker element
-Header pins
-Soldering stuff
-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:
f ..........1
g..........0pen / 1-3
a..........1-2 / 3
C..........0pen / 2-3

On the Arduino Trumpet:
f ..........1

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.




  • Epilog Challenge 9

    Epilog Challenge 9
  • Paper Contest 2018

    Paper Contest 2018
  • Science of Cooking

    Science of Cooking

We have a be nice policy.
Please be positive and constructive.




Whats the schematic drawing of the circuit?

how do you write more notes in? like another octave

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.

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 !

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

Does this project need a breadboard?

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.

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: