Arduino

Despacito Playing on Arduino Piano

Despacito Playing on Arduino Piano

Hello guys, in this tutorial we will see how to make Arduino piano, it may not sound like original song, because of two reason first I am not a piano artist and second is I am playing song on this hardware which is little difficult. I hope you will like my effort. So let’s get started.

 

For this you will need

  1. Arduino,
  2. Jumper wires,
  3. 1K ohms resistor,
  4. One copper wire,
  5. Cart board,
  6. Breadboard (optional).

Do connection as shown in diagram.

Arduino Paino Circuit
Arduino Paino Circuit

We are taking inputs from jumper wire to Arduino and send it to max software, which plays particular note. You need to download max 7 software.  You will also need a max patch file.

Downlaod max patch file

Copy the text in this file.

open new patcher file and paste in patcher.

new patcher
New Patcher

After pasting the file you can see your patch like this,

 

This code we will upload to Arduino.

// drawMIDI

int myKey[12];
int myOldKey[12];
int myNote[] = {79, 77, 76, 72, 74, 71, 69, 67, 65, 64, 62, 60};
int keyPin[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};


// Pins for MIDI keys


// This is the value required to consider the key 'touched' and trigger a MIDI signal
int touchedCutoff = 36;

// This is the value required for the first part of goMIDI
int midiInfo = 144;


// This is the section that sets up serial communications
void setup(){
 Serial.begin(19200); //if using hardward MIDI or HIDUINO, change to 31250 
 //19200 baud, requires serial to MIDI conversion on your computer
 
}


// This is the section that reads the capacitance and determines what to do, noteOn or noteOff
void loop(){
 


// only send MIDI messages when something changes
for (int i; i<12; i++) {
 myKey[i]=readCapacitivePin(keyPin[i]);
 
 if (myKey[i]>touchedCutoff){
 myKey[i]=127;
 }
 else{
 myKey[i]=0;
 }
 
 
 if (myKey[i] != myOldKey[i]) {
 myOldKey[i] = myKey[i];
 goMidi(midiInfo, myNote[i], myKey[i]);
 }
}
}


// The readCapacitivePin function is used to read whether the graphite strip connected to each pin is actually being pressed or not
// this part of the code is based on an open example on the Arduino playground for 'Capacitive Sensing'

// readCapacitivePin
// Input: Arduino pin number
// Output: A number, from 0 to 17 expressing
// how much capacitance is on the pin
// When you touch the pin, or whatever you have
// attached to it, the number will get higher

uint8_t readCapacitivePin(int pinToMeasure){
 volatile uint8_t* port;
 volatile uint8_t* ddr;
 volatile uint8_t* pin;
 
 byte bitmask;
 if ((pinToMeasure >= 0) && (pinToMeasure <= 7)){
 port = &PORTD;
 ddr = &DDRD;
 bitmask = 1 << pinToMeasure;
 pin = &PIND;
 }
 
 if ((pinToMeasure > 7) && (pinToMeasure <= 13)){
 port = &PORTB;
 ddr = &DDRB;
 bitmask = 1 << (pinToMeasure - 8);
 pin = &PINB;
 }
 
 if ((pinToMeasure > 13) && (pinToMeasure <= 19)){
 port = &PORTC;
 ddr = &DDRC;
 bitmask = 1 << (pinToMeasure - 13);
 pin = &PINC;
 }
 
 // Discharge the pin first by setting it low and output
 *port &= ~(bitmask);
 *ddr |= bitmask;
 delay(1);
 
 *ddr &= ~(bitmask);

int cycles = 16000;
 for(int i = 0; i < cycles; i++){
 if (*pin & bitmask){
 cycles = i;
 break;
 }
 }
 
 *port &= ~(bitmask);
 *ddr |= bitmask;
 
 return cycles;
}

 
// This is the section that translates the touches into MIDI signals
 
void goMidi(int cmd, int data1, int data2) {
 Serial.write(cmd); // set value stays the same
 Serial.write(data1); // note number, 60 or 49 or whatever
 Serial.write(data2); // velocity, keep at 127 for ON or 0 for OFF
 delay(2);
}

You can change note from here.

int myNote[] = {79, 77, 76, 72, 74, 71, 69, 67, 65, 64, 62, 60};

if you are getting constantly false signal from pin number 13, for example Tx LED constantly blinking then delete pin number 13 and note.

 int myNote[] = {79, 77, 76, 72, 74, 71, 69, 67, 65, 64, 62};

int keyPin[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

upload the code, after uploading close Arduino IDE software. And open max patch file. Check max console, Arduino port is showing or not.  If it is not showing remove USB cable and close max software and again restart. After opening patch file you have to turn ON serial output. And make sure it is same port where Arduino is connected. When we press jumper wire it touches 5v line and Arduino get high signal, and it goes to max software which play particular note. You can see when I press jumper wire it plays note.

LIST OF COMPONENT BUY ONLINE:

http://amzn.to/2fvSRJq   (Arduino)

http://amzn.to/2vmSK8l  (Resistor)

http://amzn.to/2wxPmWz  (Breadboard)

http://amzn.to/2vJ3lvo   (Jumper wire)

TILL THEN KEEP LEARNING KEEP MAKING 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *