Project tutorial

Simple Arduino Piano © GPL3+

A simple yet functional button based MIDI piano.

  • 3,737 views
  • 1 comment
  • 15 respects

Components and supplies

About this project

watch the video

Code

codeC/C++
#define T_C 262
#define T_D 294
#define T_E 330
#define T_F 349
#define T_G 392
#define T_A 440
#define T_B 493

const int C = 10;
const int D = 9;
const int E = 8;
const int F = 7;
const int G = 6;
const int A = 5;
const int B = 4;

const int Buzz = 11;
const int LED = 13;

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(C, INPUT);
  digitalWrite(C,HIGH);
  
  pinMode(D, INPUT);
  digitalWrite(D,HIGH);
  
  pinMode(E, INPUT);
  digitalWrite(E,HIGH);
  
  pinMode(F, INPUT);
  digitalWrite(F,HIGH);
  
  pinMode(G, INPUT);
  digitalWrite(G,HIGH);
  
  pinMode(A, INPUT);
  digitalWrite(A,HIGH);
  
  pinMode(B, INPUT);
  digitalWrite(B,HIGH);

   digitalWrite(LED,LOW);
}

void loop()
{
  while(digitalRead(C) == LOW)
  {
    tone(Buzz,T_C);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(D) == LOW)
  {
    tone(Buzz,T_D);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(E) == LOW)
  {
    tone(Buzz,T_E);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(F) == LOW)
  {
    tone(Buzz,T_F);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(G) == LOW)
  {
    tone(Buzz,T_G);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(A) == LOW)
  {
    tone(Buzz,T_A);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(B) == LOW)
  {
    tone(Buzz,T_B);
    digitalWrite(LED,HIGH);
  }

  noTone(Buzz);
  digitalWrite(LED,LOW);

}

Schematics

Comments

Similar projects you might like

Simple and Smart Air Purifier System

Project tutorial by Aaron Kow

  • 11,858 views
  • 4 comments
  • 38 respects

Arduino Simple Simon Says

Project tutorial by Metonymy

  • 5,832 views
  • 2 comments
  • 10 respects

Electronic Piano Keyboard With Preset Songs

Project tutorial by Lindsay Fox

  • 82,266 views
  • 65 comments
  • 163 respects

Simple multi-mode 4wd Rover JR-001

Project tutorial by Scott Beasley

  • 14,497 views
  • 3 comments
  • 38 respects

Simple Rubens' Tube

Project tutorial by Monica Houston

  • 3,528 views
  • 1 comment
  • 19 respects

PIANO

Project tutorial by يمنى السيد ندا

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