Project in progress
Arduino Keyboard

Arduino Keyboard © GPL3+

As a musician and music passionate, this little Keyboard is my first (but not last) Arduino project. Hope you have fun with it :)

  • 9,462 views
  • 16 comments
  • 18 respects

Components and supplies

About this project

Didn't know what to do as my first Arduino Project, so i thought of starting out with something little and temporary, like this Arduino Keyboard which you can edit as you like.

Again, hope you have fun with it. :)

Code

Arduino Keyboard codeC/C++
That's the code that will make your keyboard play
#include "pitches.h" //Notes are stored into this library

int C = 7; //First button on pin 7
int D = 8; //Second button on pin 8
int E = 9; //Third button on pin 9
int F = 10; //Fourth button on pin 10
int G = 11; //Fifth button on pin 11
int A = 12; //Sixth button on pin 12
int B = 13; //Seventh button on pin 13

int c[] = {N_C5}; //Plays C Note
int d[] = {N_D5}; //Plays D Note
int e[] = {N_E5}; //Plays E Note
int f[] = {N_F5}; //Plays F Note
int g[] = {N_G5}; //Plays G Note
int a[] = {N_A5}; //Plays A Note
int b[] = {N_B5}; //Plays B Note

int duration(500); //Every note lasts 500 milliseconds. You can change it as you like

void setup() {
  //Set every button as an INPUT_PULLUP
  pinMode(C, INPUT_PULLUP);
  pinMode(D, INPUT_PULLUP);
  pinMode(E, INPUT_PULLUP);
  pinMode(F, INPUT_PULLUP);
  pinMode(G, INPUT_PULLUP);
  pinMode(A, INPUT_PULLUP);
  pinMode(B, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(C) == LOW) { //Reads button state when pressed
    for (int Note = 0; Note < 1; Note++) {
      tone(6, c[Note], duration); //Plays note on pin 6, where the Buzzer is connected (change it if you connected it on another pin)
    }
  }
  if (digitalRead(D) == LOW) {
    for (int Note = 0; Note < 1; Note++) {
      tone(6, d[Note], duration); 
    }
  }
  if (digitalRead(E) == LOW) {
    for (int Note = 0; Note < 1; Note++) {
      tone(6, e[Note], duration);
    }
  }
  if (digitalRead(F) == LOW) {
    for (int Note = 0; Note < 1; Note++) {
      tone(6, f[Note], duration);
    }
  }
  if (digitalRead(G) == LOW) {
    for (int Note = 0; Note < 1; Note++) {
      tone(6, g[Note], duration);
    }
  }
  if (digitalRead(A) == LOW) {
    for (int Note = 0; Note < 1; Note++) {
      tone(6, a[Note], duration);
    }
  }
  if (digitalRead(B) == LOW) {
    for (int Note = 0; Note < 1; Note++) {
      tone(6, b[Note], duration);
    }
  }
}

Schematics

Keyboard schematics
And that's how you should wire it, standing to the code
Cattura wcebhdlt9y

Comments

Similar projects you might like

Keyboard V2.0

Project in progress by Gabriele Scordamaglia

  • 5,154 views
  • 18 comments
  • 14 respects

Keyboard Melodies

Project tutorial by Ava Baker -21 and Natalie Clark -20

  • 1,842 views
  • 2 comments
  • 8 respects

Electronic Piano Keyboard With Preset Songs

Project tutorial by Lindsay Fox

  • 80,585 views
  • 64 comments
  • 161 respects

Arduino Programmed Keyboard Strikes

Project in progress by Sam

  • 1,095 views
  • 0 comments
  • 1 respect

How to Make a Customizable Punchable Keyboard Button

Project tutorial by Amal Mathew

  • 3,115 views
  • 7 comments
  • 9 respects

Keyboard Macro Mat

Project showcase by Fidgety Fred

  • 2,090 views
  • 0 comments
  • 6 respects
Add projectSign up / Login