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 SimulationWhat 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
Components Required
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
Open Wokwi Simulator
Go to wokwi.com. Click New Project and select Arduino Uno as your board. No account needed.
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.
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.
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.
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!
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
| Component | Arduino Pin | Connection | Wire |
|---|---|---|---|
| Red Button (btn1) | D12 | Signal + GND | Red / Black |
| Orange Button (btn2) | D11 | Signal + GND | Orange / Black |
| Yellow Button (btn3) | D10 | Signal + GND | Yellow / Black |
| Green Button (btn4) | D9 | Signal + GND | Green / Black |
| Cyan Button (btn5) | D7 | Signal + GND | Cyan / Black |
| Blue Button (btn6) | D6 | Signal + GND | Blue / Black |
| Purple Button (btn7) | D5 | Signal + GND | Purple / Black |
| Red Button (btn8) | D4 | Signal + GND | Red / Black |
| 🔔 Passive Buzzer (+) | D8 | Signal | Gold |
| 🔔 Passive Buzzer (−) | GND | Ground | Black |
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 Simulationdiagram.json
Paste this into the diagram.json tab in Wokwi to set up all components and wiring:
{
"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:
/*************************************************** 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
sketch.ino — Main Program
Paste this into the sketch.ino tab. It handles button scanning, LED activation, and tone generation:
/** 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); } }
Comments
Post a Comment