Project tutorial
Arduino Piano Using 4x4 Keypad

Arduino Piano Using 4x4 Keypad © CC BY-ND

Make Music using Arduino, speaker, 4x4 keypad and a couple of connecting cables. No breadboard needed

  • 6 views
  • 0 comments
  • 2 respects

Components and supplies

Necessary tools and machines

A laptop

Apps and online services

About this project

Most arduino beginners class assumes you have alot of material at your disposal and as such create tutotrials that you cannot easily practise. This tutorial explains how to make an arduino piano but instead of using a buzzer, we will be using a speaker. The fun part about using a speaker especially if you are in Africa is that not only do we like our project to get attention, we also love to use materials that are easily sourced hence the speaker.

By the end of the tutorial, you be able to create music and your tones will be louder compared to that of a buzzer.

This is my first tutorial so pardon any misgiving

Code

Piano COdeC/C++
//Arduino Keypad 4x4 Piano
//This is a remix of viral science project
// By Oseni Adewale Paul

#define c3 9
#define c2 8
#define c1 7
#define c0 6
#define r3 5
#define r2 4
#define r1 3
#define r0 2
void setup() {
  Serial.begin(9600);
 pinMode(c0,INPUT_PULLUP); 
 pinMode(c1,INPUT_PULLUP);
 pinMode(c2,INPUT_PULLUP);
 pinMode(c3,INPUT_PULLUP);
 pinMode(r0,OUTPUT);
 pinMode(r1,OUTPUT);
 pinMode(r2,OUTPUT);
 pinMode(r3,OUTPUT);
 pinMode(11,OUTPUT);
}
void loop()
{digitalWrite(r0,LOW);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=119;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c1)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=106;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c2)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=94;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c3)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=89;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
digitalWrite(r0,HIGH);
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=79;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c1)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=71;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c2)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=63;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c3)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=59;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
digitalWrite(r0,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(r3,HIGH);
if(digitalRead(c0)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=25;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c1)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=20;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if (digitalRead(c2)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=10;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c3)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
digitalWrite(r0,HIGH);
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,LOW);
if(digitalRead(c0)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c1)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c2)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
else if(digitalRead(c3)==LOW){
TCCR2A = B01000011;
TCCR2B = B00001110;
OCR2A=50;
delay(100);
TCCR2B=B00001000;
TCCR2A = B00000000;
digitalWrite(11,LOW);}
}

Schematics

Schematic
Uploads2ftmp2fc47737fd 9097 461f 9fa4 7837953d74f52ffritzing r04h6z6vj8

Comments

Similar projects you might like

Unravel Preset Piano Easy Arduino (Even a Ghoul Can Make It)

Project in progress by ExeCuteLi

  • 11,097 views
  • 8 comments
  • 24 respects

4x4 T9 Keypad

by vicente zavala

  • 1,925 views
  • 0 comments
  • 1 respect

Electronic Piano Keyboard With Preset Songs

Project tutorial by Lindsay Fox

  • 86,316 views
  • 67 comments
  • 174 respects

MEGA BREAD - 4X4 KeyPad

Project in progress by Pigeon-Kicker

  • 3,011 views
  • 1 comment
  • 4 respects

Portable Capacitive Touch Piano

Project tutorial by Sridhar Rajagopal

  • 1,128 views
  • 3 comments
  • 3 respects

OSEPP LCD and keypad shield

Project tutorial by Joe

  • 42,322 views
  • 27 comments
  • 54 respects
Add projectSign up / Login