Arduino Color-Based Musical Instrument with 8 Push Buttons & Buzzer (Mini Piano Project)

ColorChord: Arduino Mini Piano with 8 Color Buttons & Buzzer | MakeMindz
🎵 Arduino Music Project · Free Simulation

ColorChord
Interactive Musical Color Sequencer

Build a color-coded mini piano with Arduino Uno — 8 glowing buttons, each playing a different musical note. No hardware needed!

▶  Open Free Simulation
1C4Do
2D4Re
3E4Mi
4F4Fa
5G4Sol
6A4La
7B4Ti
8C5Do

What Is ColorChord?

ColorChord is a color-based musical instrument built with Arduino Uno and 8 LED push buttons. Each button is a different colour and plays a unique musical note from the C4 to C5 scale when pressed — exactly like a mini piano or a Simon Says game.

The project uses the Arduino tone() function with pitches.h to generate accurate PWM-based musical frequencies, and supports both physical buttons and keyboard keys 1–8 in Wokwi.

Button → Note Reference

BTN 1 · PIN 12
🔴 Red
C4
262 Hz
Do
BTN 2 · PIN 11
🟠 Orange
D4
294 Hz
Re
BTN 3 · PIN 10
🟡 Yellow
E4
330 Hz
Mi
BTN 4 · PIN 9
🟢 Green
F4
349 Hz
Fa
BTN 5 · PIN 7
🔵 Cyan
G4
392 Hz
Sol
BTN 6 · PIN 6
🔵 Blue
A4
440 Hz
La
BTN 7 · PIN 5
🟣 Purple
B4
494 Hz
Ti
BTN 8 · PIN 4
🔴 Red
C5
523 Hz
High Do
Wokwi Keyboard: 12345678 — Click the diagram first, then press keys to play!

Components Required

🔵
Arduino Uno
Main microcontroller
🔘
8 LED Push Buttons
Colored, with built-in LEDs
🔔
Passive Buzzer
Pin 8, volume 0.2
🔌
Jumper Wires
Male-to-male
Resistors
If not using INPUT_PULLUP
💻
Wokwi Simulator
Free, browser-based

How It Works

😴

Idle State

The system continuously scans all 8 button pins inside the loop() function. All LEDs stay OFF and no sound is produced.

👆

Button Pressed

The Arduino detects a LOW signal (INPUT_PULLUP logic). The built-in LED on that button illuminates, and the mapped frequency is stored as pitch.

🎵

Sound Plays

tone(SPEAKER_PIN, pitch) drives the passive buzzer at the note's frequency using PWM. Multiple buttons can be held — the last detected wins.

🔇

Button Released

noTone(SPEAKER_PIN) is called. The LED turns OFF and the buzzer goes silent immediately.

Step-by-Step Instructions

1

Open Wokwi Simulator

Go to wokwi.com. Click New Project and select Arduino Uno as your board. No account needed.

2

Paste the diagram.json

Click the diagram.json tab in Wokwi. Replace the contents with the JSON below. This adds your Arduino Uno, 8 colored LED push buttons, and a passive buzzer — all pre-wired.

3

Create the pitches.h File

In Wokwi, click the + icon to add a new file. Name it pitches.h and paste the pitches header code below. This defines all musical note frequencies.

4

Paste the Main Arduino Code

Click sketch.ino. Paste the main code below. It includes pitches.h, defines pin arrays, and runs the button-scan loop to play notes.

5

Run the Simulation

Click ▶ Play. Click anywhere on the circuit to focus it, then press keyboard keys 1–8 to play musical notes — or click the colored buttons directly!

6

Play & Experiment

Try pressing multiple buttons. Modify the frequencies in buttonTones[] to create different scales. Add an LCD display to show the note name as you play!

Pin Connections

ComponentArduino PinConnectionWire
Red Button (btn1)D12Signal + GNDRed / Black
Orange Button (btn2)D11Signal + GNDOrange / Black
Yellow Button (btn3)D10Signal + GNDYellow / Black
Green Button (btn4)D9Signal + GNDGreen / Black
Cyan Button (btn5)D7Signal + GNDCyan / Black
Blue Button (btn6)D6Signal + GNDBlue / Black
Purple Button (btn7)D5Signal + GNDPurple / Black
Red Button (btn8)D4Signal + GNDRed / Black
🔔 Passive Buzzer (+)D8SignalGold
🔔 Passive Buzzer (−)GNDGroundBlack
ARDUINO UNO D12 D11 D10 D9 D7 D6 D5 D4 D8 GND 1 2 3 4 5 6 7 8 GND BUZZER Passive D8 (Signal) GND LEGEND Colored signal wires (per button) GND rail (shared) Buzzer signal (D8)

Wiring diagram: Arduino Uno → 8 LED push buttons + passive buzzer on D8

Run the Free Simulation

🎹 Open ColorChord in Wokwi

Everything is pre-built. Click Play, then press keys 1–8 on your keyboard to play musical notes instantly — no hardware needed.

▶  Open Free Simulation
FREE · No signup · Works on mobile

diagram.json

Paste this into the diagram.json tab in Wokwi to set up all components and wiring:

📋 diagram.json
{
  "version": 1,
  "author": "Uri Shaked",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-uno", "id": "uno", "top": 185, "left": 71, "attrs": {} },
    {
      "type": "wokwi-buzzer", "id": "buzzer",
      "top": 220, "left": 380, "rotate": 90,
      "attrs": { "volume": "0.2" }
    },
    { "type": "wokwi-pushbutton", "id": "btn1", "top": 70, "left": 0,   "rotate": 90, "attrs": { "color": "red",    "key": "1" } },
    { "type": "wokwi-pushbutton", "id": "btn2", "top": 70, "left": 50,  "rotate": 90, "attrs": { "color": "orange", "key": "2" } },
    { "type": "wokwi-pushbutton", "id": "btn3", "top": 70, "left": 100, "rotate": 90, "attrs": { "color": "yellow", "key": "3" } },
    { "type": "wokwi-pushbutton", "id": "btn4", "top": 70, "left": 150, "rotate": 90, "attrs": { "color": "green",  "key": "4" } },
    { "type": "wokwi-pushbutton", "id": "btn5", "top": 70, "left": 200, "rotate": 90, "attrs": { "color": "cyan",   "key": "5" } },
    { "type": "wokwi-pushbutton", "id": "btn6", "top": 70, "left": 250, "rotate": 90, "attrs": { "color": "blue",   "key": "6" } },
    { "type": "wokwi-pushbutton", "id": "btn7", "top": 70, "left": 300, "rotate": 90, "attrs": { "color": "purple", "key": "7" } },
    { "type": "wokwi-pushbutton", "id": "btn8", "top": 70, "left": 350, "rotate": 90, "attrs": { "color": "red",    "key": "8" } }
  ],
  "connections": [
    [ "uno:GND.1", "buzzer:1", "black",  [ "v-16", "*", "h-18" ] ],
    [ "uno:8",     "buzzer:2", "gold",   [ "v-24", "*", "h-10" ] ],
    [ "uno:12", "btn1:1.r", "red",    [ "v-24", "h0" ] ],
    [ "uno:GND.1", "btn1:2.r", "black", [ "v-16", "h0" ] ],
    [ "uno:11", "btn2:1.r", "orange", [ "v-32", "h0" ] ],
    [ "uno:GND.1", "btn2:2.r", "black", [ "v-16", "h0" ] ],
    [ "uno:10", "btn3:1.r", "yellow", [ "v-38", "h0" ] ],
    [ "uno:GND.1", "btn3:2.r", "black", [ "v-16", "h0" ] ],
    [ "uno:9",  "btn4:1.r", "green",  [ "v-46", "h20" ] ],
    [ "uno:GND.1", "btn4:2.r", "black", [ "v-16", "h0" ] ],
    [ "uno:7",  "btn5:1.r", "cyan",   [ "v-56", "h0" ] ],
    [ "uno:GND.1", "btn5:2.r", "black", [ "v-16", "h0" ] ],
    [ "uno:6",  "btn6:1.r", "blue",   [ "v-48", "h0" ] ],
    [ "uno:GND.1", "btn6:2.r", "black", [ "v-16", "h0" ] ],
    [ "uno:5",  "btn7:1.r", "purple", [ "v-40", "h0" ] ],
    [ "uno:GND.1", "btn7:2.r", "black", [ "v-16", "h0" ] ],
    [ "uno:4",  "btn8:1.r", "red",    [ "v-32", "h0" ] ],
    [ "uno:GND.1", "btn8:2.r", "black", [ "v-16", "h0" ] ]
  ]
}

pitches.h

Create a new file named pitches.h in Wokwi (click the + tab button) and paste this content:

🎵 pitches.h — Musical Note Frequencies
/***************************************************
  Musical note frequency definitions for Arduino.
  Used with tone() to generate accurate pitches.
 ***************************************************/

#define NOTE_B0  31
#define NOTE_C1  33   // ... (octaves 1-3 omitted for brevity)
#define NOTE_C4  262  // Middle C — Red button (Do)
#define NOTE_CS4 277
#define NOTE_D4  294  // Orange button (Re)
#define NOTE_DS4 311
#define NOTE_E4  330  // Yellow button (Mi)
#define NOTE_F4  349  // Green button (Fa)
#define NOTE_FS4 370
#define NOTE_G4  392  // Cyan button (Sol)
#define NOTE_GS4 415
#define NOTE_A4  440  // Blue button (La) — Concert pitch
#define NOTE_AS4 466
#define NOTE_B4  494  // Purple button (Ti)
#define NOTE_C5  523  // Red button (High Do)
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
💡
Tip: The full pitches.h file covers notes from B0 (31 Hz) to DS8 (4978 Hz). For this project you only need C4–C5, but including the full file lets you easily extend to other octaves later.

sketch.ino — Main Program

Paste this into the sketch.ino tab. It handles button scanning, LED activation, and tone generation:

⚡ sketch.ino — Arduino C++
/**
  ColorChord — Mini Piano for Arduino Uno
  MakeMindz.com | makemindz.com/colorchord

  Controls:
  - In Wokwi: click anywhere on the diagram to focus,
    then press keyboard keys 1–8 to play notes.
  - Keys: 1 = lowest (C4), 8 = highest (C5)
*/

#include "pitches.h"

// Buzzer connected to digital pin 8
#define SPEAKER_PIN 8

// GPIO pins for each button (order: btn1 to btn8)
const uint8_t buttonPins[] = { 12, 11, 10, 9, 7, 6, 5, 4 };

// Musical notes mapped to each button
const int buttonTones[] = {
  NOTE_C4,  // btn1 — Red    — Do  — 262 Hz
  NOTE_D4,  // btn2 — Orange — Re  — 294 Hz
  NOTE_E4,  // btn3 — Yellow — Mi  — 330 Hz
  NOTE_F4,  // btn4 — Green  — Fa  — 349 Hz
  NOTE_G4,  // btn5 — Cyan   — Sol — 392 Hz
  NOTE_A4,  // btn6 — Blue   — La  — 440 Hz
  NOTE_B4,  // btn7 — Purple — Ti  — 494 Hz
  NOTE_C5   // btn8 — Red    — Do  — 523 Hz
};

// Calculate number of buttons automatically
const int numTones = sizeof(buttonPins) / sizeof(buttonPins[0]);

void setup() {
  // Configure all button pins as inputs with internal pull-up resistors
  for (uint8_t i = 0; i < numTones; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  // Configure buzzer pin as output
  pinMode(SPEAKER_PIN, OUTPUT);
}

void loop() {
  int pitch = 0;  // 0 means no button pressed

  // Scan all buttons — last pressed wins
  for (uint8_t i = 0; i < numTones; i++) {
    if (digitalRead(buttonPins[i]) == LOW) {
      pitch = buttonTones[i];
    }
  }

  // Play tone if a button is pressed, otherwise silence
  if (pitch) {
    tone(SPEAKER_PIN, pitch);
  } else {
    noTone(SPEAKER_PIN);
  }
}

Programming Concepts Used

Digital Input Reading INPUT_PULLUP Configuration PWM Sound Generation tone() / noTone() Musical Frequency Mapping Arrays in C++ sizeof() Operator Loop-based Button Scanning Active-LOW Logic #include Header Files

Applications

🎹
Mini Arduino Piano
🎮
Simon Says Game
🎼
Melody Composer
🔊
Sound Effects Board
🎓
STEM Music Tool
🧒
Kids Educational Toy
🎵
DIY Musical Keyboard
🏫
School Exhibition

© 2026 MakeMindz.com — Arduino Tutorials & STEM Projects

Built for students, makers, musicians & robotics enthusiasts 🎵

Comments

try for free