Introduction: ElecTrumpet (Arduino)
I had seen a project on here before to make a sort of trumpet with an Arduino by rigging up three buttons, but its range was limited and it couldn't play sharps or flats. This design uses a joystick to allow for different ranges that can be reached by tightening one's lips when using a real trumpet. By using only the X-axis on the joystick, the range is from C3 to G4, including sharps and flats. In theory, by using both axes, the range can be expanded further, but I'd rather keep things simpler and easier to understand.
Step 1: Materials
Most of the materials I used came from an Arduino starter kit, specifically this one, but there's no reason it wouldn't work on most other Arduino microcontrollers. Regardless, this build used:
- 1 Arduino Mega
- 1 Mega prototype shield with a mini breadboard attached
- 1 Breadboard
- 3 10K resistors
- 1 120-ohm resistor/ 1 100-ohm resistor (see below)
- 3 Pushbuttons
- 1 PS2 Joystick Module
- Jumper wires
- 1 Speaker
- 1 Potentiometer (10K)
- 1 4uF capacitor
- 1 NPN transistor
The whole thing can also work with a smaller speaker or even a piezo buzzer without needing the last 3 items, but it won't be as loud.
The build I made also requires the NewTone or toneAC libraries, depending on how loud you want it to be. toneAC gives a clearer tone quality, but isn't as loud as NewTone. In addition, the build with toneAC will use a 100 ohm resistor, while the NewTone build will use a 120-ohm resistor.
Step 2: The Build
Most of the setup is the same whether you will be using toneAC or NewTone.
The buttons will each be connected to ground by a 10K pull down resistor, and will be connected to digital pins 4, 5, and 6.
The pins on the joystick should be labelled something like GND, +5V, X, Y, and SW or KEY.
GND and 5V should, naturally, be connected to ground and the 5V pin respectively.
The X and Y axes are read as analog inputs, so connect X to analog pin 0 and Y to analog pin 1
SW is the button activated by pushing down on the joystick, and should be connected to digital pin 3.
Step 3: Build - ToneAC
This is the simpler of the two options, but again, it won't be as loud.
All that's left to connect to finish the build as is is to connect the speaker/buzzer. What pins to connect it to depend on what Arduino board you're using. As mine has the ATMega2560 chip, I connected the positive and negative ends to digital pins 12 and 11, respectively. If you're using a small speaker rather like this one rather than a piezo buzzer, connect the 100-ohm resistor between one of the speaker wires and the Arduino pin.
Step 4: Build - NewTone
This will be more complicated than the other build.
First, the negative end of the speaker can just be connected straight to ground.
Connect the 120-ohm resistor from 5V on the Arduino to the collector pin on the transistor. The positive end of the speaker will be connected, through the capacitor, to the collector pin as well. (See the image for a better idea of how it's wired.)
Connect the wiper pin of the potentiometer to pin 12, and either one of the remaining pins to the base of the transistor.
Finally, connect the emitter pin of the transistor to ground.
Step 5: Code(s)
The code for either build is attached above. The file pitches.h should be placed in the folder with the Arduino file in order to run properly.
From here, all that's left is to test it out and find a song to play. Hope you enjoy!