Rexhep Mustafovski
Published © MIT

Build an Arduino Keyboard that Plays Real Notes

This project creates a simple digital keyboard that uses push buttons to play musical notes through a piezo buzzer with Arduino.

BeginnerFull instructions provided1 hour138
Build an Arduino Keyboard that Plays Real Notes

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1
USB-A to B Cable
USB-A to B Cable
×1
Amazon Web Services Push Button
×4
Resistor 10k ohm
Resistor 10k ohm
×2
Resistor 1M ohm
Resistor 1M ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Buzzer, Piezo
Buzzer, Piezo
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fritzing

Hand tools and fabrication machines

Amazon Web Services Arduino Starter Kit

Story

Read more

Custom parts and enclosures

Digital Keyboard with Sound Output using Arduino

Downloadable files.

Schematics

Fritzing Circuit Diagram – Digital Keyboard with Arduino

Code

Code for Digital Keyboard with Sound Output

C/C++
Use this code in Arduino IDE.
int notes[] = {262, 294, 330, 349};

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

void loop() {
  int keyVal = analogRead(A0);
  Serial.println(keyVal);

  if (keyVal == 1023) {
    tone(8, notes[0]);
  } else if (keyVal >= 990 && keyVal <= 1010) {
    tone(8, notes[1]);
  } else if (keyVal >= 505 && keyVal <= 515) {
    tone(8, notes[2]);
  } else if (keyVal >= 5 && keyVal <= 10) {
    tone(8, notes[3]);
  } else {
    noTone(8);
  }
}

Credits

Rexhep Mustafovski
2 projects • 3 followers
An Officer and a Teaching and Research Assistant at the Military Academy "General Mihailo Apostolski" - Skopje.

Comments