penners01
Published © GPL3+

Keypad Music Notes

Press a button. Play a note on the Piezo. Scale of D Major.

BeginnerFull instructions provided1,137
Keypad Music Notes

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
4x4 Button Pad
I used a generic, no symbol 4x4 button pad. Any keypad/button pad will work.
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Jumper wires (generic)
Jumper wires (generic)
x3 male to male wires; x8 female to male wires
×11
Resistor 220 ohm
Resistor 220 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

keypad_music_bb_ddlZnFton3.png

4x4 Keypad Music Player

Code

Keypad Music Player Code

C/C++
#include <Keypad.h>


// Defines how many rows and columns there are
const byte ROWS = 4;
const byte COLS = 4;

// Define name of keys
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', '4'},
  {'5', '6', '7', '8'},
  {'A', 'B', 'C', 'D'},
  {'E', 'F', 'G', 'H'}
};

byte colPins[ROWS] = {9, 8, 7, 6};
byte rowPins[COLS] = {5, 4, 3, 2};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), colPins, rowPins, ROWS, COLS);

// Define notes
#define NOTE_C   523
#define NOTE_CS  554
#define NOTE_D   587
#define NOTE_E   659
#define NOTE_F   698
#define NOTE_FS  740
#define NOTE_G   784
#define NOTE_A   880
#define NOTE_B   988
#define NOTE_C2  1047
#define NOTE_CS2 1109
#define NOTE_D2  1175
#define NOTE_E2  1319
#define NOTE_F2  1397
#define NOTE_FS2 1480
#define NOTE_G2  1568

// Change this depending on your pin on the Arduino
const int buzzer = 11;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int customKey = customKeypad.getKey();

  if (customKey == '1') {
    tone(buzzer, NOTE_C, 200);
  }
  if (customKey == '2') {
    tone(buzzer, NOTE_CS, 200);
  }
  if (customKey == '3') {
    tone(buzzer, NOTE_D, 200);
  }
  if (customKey == '4') {
    tone(buzzer, NOTE_E, 200);
  }
  if (customKey == '5') {
    tone(buzzer, NOTE_F, 200);
  }
  if (customKey == '6') {
    tone(buzzer, NOTE_FS, 200);
  }
  if (customKey == '7') {
    tone(buzzer, NOTE_G, 200);
  }
  if (customKey == '8') {
    tone(buzzer, NOTE_A, 200);
  }
  if (customKey == 'A') {
    tone(buzzer, NOTE_B, 200);
  }
  if (customKey == 'B') {
    tone(buzzer, NOTE_C2, 200);
  }
  if (customKey == 'C') {
    tone(buzzer, NOTE_CS2, 200);
  }
  if (customKey == 'D') {
    tone(buzzer, NOTE_D2, 200);
  }
  if (customKey == 'E') {
    tone(buzzer, NOTE_E2, 200);
  }
  if (customKey == 'F') {
    tone(buzzer, NOTE_F2, 200);
  }
  if (customKey == 'G') {
    tone(buzzer, NOTE_FS2, 200);
  }
  if (customKey == 'H') {
    tone(buzzer, NOTE_G2, 200);
  }
}

Credits

penners01
0 projects • 0 followers

Comments