Saturday, November 28, 2015

How to make Arduino Trumpet-Robomart

This is simple project using the three buttons, emulates a trumpet by playing notes. This is so easy to make and fun to play with, though it can only play one octave and no flats.
Step 1: Code

Load this code 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: How can hook it up
Each of the three switches go to analog from ground 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: Resources

For this project you will need: 
Project box (4x2x1) 
Drill and 1/4 in bit along with 1/16 in
•3 momentary switches (NO) 
Step 4: Put it Together!!
First of all, open the box and on the outside of the box, mark the center and an inch out from the center. Where you will need to make a 1/4 in hole Now, dremel out the scraps of plastic and used the holders to hold a PC inside.
Step 5: How can I Fit it!



Insert switches and make sure that they fit and screw them . They are situated in the right place and enter the PIN and drill bit to drill holes with a 1/16 mark .
Step 6: Wireing

Now, wire and solder 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. Like before, solder the piezo to pin 9 and ground and the battery clasp to ground and voltage in. 
Step 7: Playing
Fingerings on the trumpet to trumpet a general ' as are' . ' Identical ' I mean , I had to make some 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 used half-step complicated and changing things and switches can put a octive . It would be awsome , however , it may be more complex and will require a large box .
HAVE FUN!!!!

No comments:

Post a Comment