This is a color-based musical instrument where 8 push buttons with colored LEDs trigger different musical notes through a buzzer, creating an interactive sound sequencer similar to a simplified piano or Simon Says game.
Step-by-Step Description
1. Hardware Components
- Arduino Uno - Main controller
- 8 Push Buttons with Built-in LEDs - Color-coded input switches
- Red (x2)
- Orange
- Yellow
- Green
- Cyan
- Blue
- Purple
- Passive Buzzer - Sound output device
- Connecting Wires - Signal routing
- Resistors (if needed) - Pull-down resistors for buttons
2. Color-Coded Button Layout
From Left to Right:
- 🔴 Red - Note C / Do
- 🟠Orange - Note D / Re
- 🟡 Yellow - Note E / Mi
- 🟢 Green - Note F / Fa
- 🔵 Cyan - Note G / Sol
- 🔵 Blue - Note A / La
- 🟣 Purple - Note B / Ti
- 🔴 Red - Note C (High) / Do
3. Circuit Connections
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" ] ]
]
}
Button Connections (Digital Pins)
Each button has 3 pins: LED+, Common, Signal
Button 1 (Red):
- Signal wire (Red) → Arduino Pin 13
- LED+ → Arduino Pin 13 (shared with signal)
- Common/GND → Arduino GND
Button 2 (Orange):
- Signal wire (Orange) → Arduino Pin 12
- LED+ → Arduino Pin 12
- Common/GND → Arduino GND
Button 3 (Yellow):
- Signal wire (Yellow) → Arduino Pin 11
- LED+ → Arduino Pin 11
- Common/GND → Arduino GND
Button 4 (Green):
- Signal wire (Green) → Arduino Pin 10
- LED+ → Arduino Pin 10
- Common/GND → Arduino GND
Button 5 (Cyan):
- Signal wire (Cyan) → Arduino Pin 9
- LED+ → Arduino Pin 9
- Common/GND → Arduino GND
Button 6 (Blue):
- Signal wire (Blue) → Arduino Pin 8
- LED+ → Arduino Pin 8
- Common/GND → Arduino GND
Button 7 (Purple):
- Signal wire (Purple) → Arduino Pin 7
- LED+ → Arduino Pin 7
- Common/GND → Arduino GND
Button 8 (Red):
- Signal wire (Red) → Arduino Pin 6
- LED+ → Arduino Pin 6
- Common/GND → Arduino GND
Buzzer Connection
- Positive (+) → Arduino Pin 5 (or any PWM pin)
- Negative (-) → Arduino GND
PITCHES.h
/**************************************************
This file defines constants with the frequency
of different musical notes.
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#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
4. How It Works
Basic Operation:
- Idle State
- All button LEDs are OFF
- System waits for button press
- Buzzer is silent
- Button Press Event
- User presses any colored button
- Button's LED lights up
- Buzzer plays corresponding musical note
- Specific frequency matches the color/position
- Musical Notes Mapping
Red (1) → C4 (261 Hz)Orange (2) → D4 (294 Hz)Yellow (3) → E4 (330 Hz)Green (4) → F4 (349 Hz)Cyan (5) → G4 (392 Hz)Blue (6) → A4 (440 Hz)Purple (7) → B4 (494 Hz)Red (8) → C5 (523 Hz)
- Release
- When button released → LED turns OFF
- Buzzer stops playing
5. Programming Logic
/**
Mini piano for Arduino.
You can control the colorful buttons with your keyboard:
After starting the simulation, click anywhere in the diagram to focus it.
Then press any key between 1 and 8 to play the piano (1 is the lowest note,
8 is the highest).
Copyright (C) 2021, Uri Shaked. Released under the MIT License.
*/
#include "pitches.h"
#define SPEAKER_PIN 8
const uint8_t buttonPins[] = { 12, 11, 10, 9, 7, 6, 5, 4 };
const int buttonTones[] = {
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,
NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5
};
const int numTones = sizeof(buttonPins) / sizeof(buttonPins[0]);
void setup() {
for (uint8_t i = 0; i < numTones; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
pinMode(SPEAKER_PIN, OUTPUT);
}
void loop() {
int pitch = 0;
for (uint8_t i = 0; i < numTones; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
pitch = buttonTones[i];
}
}
if (pitch) {
tone(SPEAKER_PIN, pitch);
} else {
noTone(SPEAKER_PIN);
}
}
7. Step-by-Step Wokwi Setup
- Add Components
- Drag Arduino Uno to canvas
- Add 8 push buttons with LEDs
- Add 1 buzzer component
- Arrange Layout
- Place buttons in a horizontal row
- Position buzzer near Arduino
- Organize for clean wiring
- Wire Buttons (Left to Right)
- Button 1 signal → Pin 13
- Button 2 signal → Pin 12
- Button 3 signal → Pin 11
- Button 4 signal → Pin 10
- Button 5 signal → Pin 9
- Button 6 signal → Pin 8
- Button 7 signal → Pin 7
- Button 8 signal → Pin 6
- All button GND → Arduino GND
- Wire Buzzer
- Buzzer + → Pin 5
- Buzzer - → GND
- Upload Code
- Paste the code above
- Click "Start Simulation"
- Test
- Click each button
- Verify LED lights up
- Listen to corresponding note
8. Applications
- 🎹 Musical Instrument - Simple piano/keyboard
- 🎮 Simon Says Game - Memory game
- 🎵 Music Learning Tool - Teaching musical scales
- 🎨 Color-Sound Association - Educational toy
- 🎼 Melody Composer - Create simple tunes
- 🔊 Sound Effects Board - Custom sound triggers
- 👶 Kids Toy - Interactive sensory device

Comments
Post a Comment