Musicduino

466

8

3

Musicduino is an arduino that has similar functions to that of a piano keyboard. Musicduino allows you to play up to six different notes, which are interchangeable in its coding.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Buttons

First, put the desired amount of buttons on the breadboard. Insert one side of the button in the "E" column and the other side of the button in the "F" column.

Step 2: Resistors

Next, obtain the same amount of 4.7 K resistors as buttons. The color bands of the resistors should be red, orange, purple, then gold. Place one end of the resistor into the positive input on the same row as the bottom of the button. Insert the opposite side of the resistor into the same row as the top of the button. This side of the resistor should be parallel to the legs of the button.

Step 3: LEDs

LEDs are put onto the breadboard after the resistors and buttons are implemented. One prong of the LED is put into the "A" or "B" column, on the opposite side of the resistors. Make sure a diagonal line can be made between the LED and the resistor, that passes through the button. The other prong in put into the corresponding positive input.

Tip: We learned that blue and white LEDs require more power, than other colors, for operation. You may need to use a different Ohm level-resistor for operation. We used red and yellow LEDs for our project, but you can experiment and see what works for your project.

Step 4: Wires

Acquire male-wires for this process. Attach one end of the wire to one of the ports (numbers 2-13) on the Arduino. Attach the other end of the wire to the breadboard so it is parallel to the resistor.

Step 5: Powering

Attach a male-wire to the Arduino port labeled, "GND," and attach its other end to the positive input on the resistor side of the board.

Acquire another male-wire and attach one end to the 5V port on the Arduino. Attach the other end to the LED positive side of the board.

Step 6: Grounding

Wire from "GND" port, located next to the 5V port, to the negative input on the resistor side of the breadboard.

Step 7: Speaker

This step may not be applicable to some speakers.

Wire the positive speaker-wire to an open port on the numbers side of the arduino (numbers 2-13).

Then, wire the negative end to the negative input on the breadboard, on the same side as the resistors.

Step 8: Coding

This code should work....

/*
This sketch uses the buzzer to play songs. The Arduino's tone() command will play notes of a given frequency. We'll provide a function that takes in note characters (a-g), and returns the corresponding frequency from this table:

note frequency c 262 Hz d 294 Hz e 330 Hz f 349 Hz g 392 Hz a 440 Hz b 494 Hz C 523 Hz

created 2005 by DojoDave modified 30 Aug 2011 by Tom Igoe

This example code is in the public domain.

/ constants won't change. They're used here to // set pin numbers:

const int buttonPin = 2; const int buttonPintwo = 4; const int buttonPinthree = 7; const int buttonPinfour = 8; const int buttonPinfive = 12; const int buttonPinsix = 13; // the number of the pushbutton pin const int ledPin = 1; // the number of the LED pin

// variables will change: int buttonState = 0; // variable for reading the pushbutton status

const int buzzerPin = 10;

// put your main code here, to run repeatedly:

#define NOTE_G5 784 #define NOTE_A5 880 #define NOTE_1C 523 #define NOTE_2D 587 #define NOTE_3E 659 #define NOTE_4F 698 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_G4 392 #define NOTE_DS5 622 #define NOTE_D5 587 #define NOTE_B4 494 #define NOTE_A4 440 #define NOTE_FS5 740 #define NOTE_F5 698 #define NOTE_AS5 932 #define NOTE_DS6 1245 #define NOTE_D6 1175 void setup() {

pinMode(2, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); pinMode(7, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(10, OUTPUT); pinMode(12, INPUT_PULLUP); pinMode(13, INPUT_PULLUP); Serial.begin(9600);

}

void loop() {

Serial.println(digitalRead(3)); if (digitalRead(2) == HIGH) { // play the note corresponding to this sensor:

tone(10, NOTE_1C); } else if (digitalRead(4) == HIGH ) { // play the note corresponding to this sensor:

tone(10, NOTE_2D); } else if (digitalRead(7) == HIGH ) { // play the note corresponding to this sensor:

tone(10, NOTE_3E); } else if (digitalRead(3) == HIGH ) { // play the note corresponding to this sensor: Serial.println("yes"); tone(10, NOTE_4F);

} else if (digitalRead(12) == HIGH ) { // play the note corresponding to this sensor:

tone(10, NOTE_G5);

} else { if (digitalRead(13) == HIGH ) { // play the note corresponding to this sensor:

tone(10, NOTE_A5);

} else { noTone(10); }

} }

Recommendations

• Internet of Things Class

22,843 Enrolled