Recycle Piano Keyboard With Arduino

Published

Introduction: Recycle Piano Keyboard With Arduino

About: Electronic Engineer :)

Do you have an old keyboard that works no more because the circuits are burnt?

Do you want a piano and are very low on budged?

In this tutorial I will show you how to make a 61 key keyboard play with very low effort and cost.

In this video you can see my working prototype. It is a bit more advanced as I built a system to play music and scales and a lot of stuff but that does not matter. Focus on the piano playing on arduino.

For this instructable you will need:

- Keyboard.

- Some 1kOhm resistors (8 should be OK) and 2 of 220Ohm resistors.

- Header strips (x24 minimum).

- Arduino MEGA (you can get it in ebay for under 10$).

- Multimeter.

- MIDI female.

- MIDI cable.

This is my first instructable and also I have a problem: I am short on words. If you get lost, please tell me in the commentaries and I will support you, adding aditional info on every step. Including photos, diagrams, etc.

Step 1: Cleaning the Piano & Disassembly

First step is dissasembling your keyboard. What we need exactly is to have it like in the photo shown. We will use that bus later to connect with the arduino.

In case you don't know how to dissasembly your keyboard... Well... every keyboard is different. You will have to find your way and trying to not destroy it. BUT DO NOT WORRY! I got you.

I attached to this step a video by the youtube channel "Innovation KH" where it is show how to get to the circuits and make keys work better.

Step 2: Understanding What We Are Doing

As every piano keyboard is different, it is important for you to understand the basics of what we are doing.

So basically we have one (or, really, two) push swtiches for every key. That means that everytime we press a key from our keyboard, we make a short circuit and we have to scan that. As we would need one pin for each key (each circuit), the engineers of the past found a way to optimize that: do a matrix and scan progressively.

I found a perfect scheme made by Mr. Tom Scarff that would have helped me a lot if I found it when I was designing the "Arduino Piano". It shows also some diods that make a perfect explanation of how we will implement the progressive scanning.

SO! GET THIS, IT IS SIMPLE:

You send a signal for each pin from 14 to 25 (look at the schematic). One signal at a time. Each time you send a signal (1 logic or 5V), you scan in the pins 11 to 8 if they have this signal. If they have 1 logic (or 5V) it means that the signal reached them, so the button must be pressed.

THE KEY ==> We will send one signal per input at every time and scan by every output, the number of scans is equivalent to the number of inputs.

Also, we will be sending MIDI from the arduino. You can transform this signal to music with another instrument or a computer. Check the pins and the resistors you need to use in the schematic.

Step 3: Getting It Done

Here comes the funny part. Check in the connector of your piano where the inputs are. It is easy with a multimeter because the inputs are disconnected while the outputs are connected to diodes.

Anyway I will make it simple and give you a hint by telling you how it was in my keyboard. Must be similar.

1 3 5 7 9 11 13 15 17 19 21 23 25

/ O O O O O O O O I I I I G /

/ O O O O O O O O I I I I G /

2 4 6 8 10 12 14 16 18 20 22 24 26

O as output, I as input an G as ground, what else? ;)

Well, what you must do in here is connect the bus to the circuit. Make sure you know what pins are inputs and what pins are outputs and also the order, because we will make a progressive scan (and emmit).

Note that there is two pins for each key in every set of keys (every set is 8 keys and has only one output).

Pull-down resistors from the inputs would be useful. That means take 1kOhm resistors and put them between each input and ground.

Step 4: Arduino Code

You will need the lib for the MIDI https://github.com/FortySevenEffects/arduino_midi_...

Connect the MIDI connector to the serial tx of the arduino as shown in the photo.

Copy this code to your arduino! It should work... :P

#include <midi_Message.h>

#include <midi_Defs.h>

#include <MIDI.h>

#include <midi_Settings.h>

#include <midi_Namespace.h>

void set_pins_mode (int initial, int final, boolean mode); void update_keyboard_status (); void send_midi();

//====CONSTANTS================= //Pins meant to scan keys const int IN_INI = 30; const int IN_FIN = 37; //Pins meant to be outputs const int OUT_INI = 38; const int OUT_FIN = 53; //Key positions const int HIGH_PRE[8] = {OUT_INI+9,OUT_INI+11,OUT_INI+13,OUT_INI+15, OUT_INI+14,OUT_INI+12,OUT_INI+10,OUT_INI+8}; const int LOW_PRE[8] = {OUT_INI+6,OUT_INI+4,OUT_INI+2,OUT_INI, OUT_INI+1,OUT_INI+3,OUT_INI+5,OUT_INI+7}; //====GLOBAL_VARIABLES========== byte keyboard_status[64]; byte keyboard_status_old[64]; short notes_on[8];

MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiOut);

void setup() { //Initialize global variables for(int i=0; i<8;i++) notes_on[i]=-1; for(int i=0; i<64;i++){ keyboard_status[i]=0; } //Setup pins set_pins_mode(IN_INI,IN_FIN,INPUT); set_pins_mode(OUT_INI,OUT_FIN,OUTPUT); //Initialize serial communication Serial.begin(31250); // Serial for MIDI }

void loop(){ update_keyboard_status(); send_midi(); }

void set_pins_mode (int initial, int final, boolean mode){ for (int i = initial; i<=final; i++) pinMode(i, mode); } void update_keyboard_status (){ //Scan pressed keys for (int i=0;i<8;i++){ digitalWrite(HIGH_PRE[i],HIGH); digitalWrite(LOW_PRE[i],HIGH); for (int j=0; j<8; j++){ if(digitalRead(IN_INI+j)==HIGH){ keyboard_status[i*8+j]=1; } else { keyboard_status[i*8+j]=0; } } digitalWrite(HIGH_PRE[i],LOW); digitalWrite(LOW_PRE[i],LOW); delay(1); } }

void send_midi () { //First determine commands short notes_pressed[8] = {-1,-1,-1,-1,-1,-1,-1,-1}; int aux=0; int i = 0; while(aux<8&&i<64){ if(keyboard_status[i]==1){ notes_pressed[aux]=i; aux++; } i++; } //Send commands //--First switch off unpressed notes for (int j=0;j<8;j++){ aux=0; while(aux<8&¬es_on[j]!=notes_pressed[aux]){ aux++; } if(aux==8&¬es_on[j]!=-1){ midiOut.sendNoteOff(notes_on[j]+36,0,j+1); notes_on[j]=-1; } } //---Then switch on newly pressed notes for (int k=0;k<8;k++){ aux=0; while(aux<8&¬es_pressed[k]!=notes_on[aux]){ aux++; } if(aux==8){ //Search an avaiable channel i=0; while(notes_on[i]!=-1) i++; //Write note on avaiable channel midiOut.sendNoteOn(notes_pressed[k]+36,127,i+1); notes_on[i]=notes_pressed[k]; //Update ON notes } } }

Step 5: Help Me!

If you find it too difficult or need some extra details about the how-to, help me out and give me your commentaries. For example, not all piano circuits will be the same. Send me photos of yours so I can give you my impressions about how to understand yours. For now I have only seen mine.

Microcontroller Contest

This is an entry in the
Microcontroller Contest

Share

    Recommendations

    • Casting Contest

      Casting Contest
    • Microcontroller Contest

      Microcontroller Contest
    • Make it Move Contest

      Make it Move Contest
    user

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

    Tips

    Questions

    2 Comments

    what libraries should be added in the code?

    1 reply

    I just updated the code with the libraries. Seems like putting things between "< >" makes the html crazy and erases some things.