กลับไปหน้ารวมไฟล์
3-note-piano-box-whidden-speaker-8f483c-en.md

The 3 Note Piano Box lets you play 3 natural notes (F,G and A), along with 3 sharp notes, (F#, G#, and A#).

The natural and sharp notes are both played by pressing the 3 buttons along the top. By default, the natural notes play; to play the sharp notes, you cover the photoresistor at the front of the piano box with your palm.

The 3 Note Piano Box introduces the concept of polyphony and interactive state machines. While earlier buzzer projects focus on playing pre-programmed songs automatically, this project turns the Arduino into a playable musical instrument.

Multi-Button Input Reading

The challenge here lies in constantly monitoring multiple inputs without the code getting stuck.

  1. The Setup: You wire three push buttons to digital pins 2, 3, 4. By utilizing the Arduino's internal pull-up resistors (pinMode(2, INPUT_PULLUP)), you can eliminate all messy external 10k resistors on your breadboard—wiring the buttons directly to Ground.
  2. The Main Loop: The Arduino checks all three buttons in rapid succession (millions of times a second).
  3. The Frequency Trigger:
    • if (digitalRead(button1) == LOW) { tone(buzzerPin, 261); } (Plays Middle C: 261 Hz)
    • ... (button2) -> Plays E (329 Hz)
    • ... (button3) -> Plays G (392 Hz)
  4. The Silence: Critically, you must include an else { noTone(buzzerPin); } statement at the very end. Otherwise, if you let go of the button, the buzzer will scream Middle C forever!

Required Hardware

  • Arduino Uno/Nano: The synthesizer core.
  • Three Tactile Push Buttons.
  • Active or Passive Piezo Buzzer.
  • A Small Enclosure: (Optional) To mount the buttons and hide the messy wiring, creating a neat "Piano Box".

This project is the perfect stepping stone to building full 8-key octave synthesizers and learning to use the Mozzi audio generation library.

How to Build:

1: 3D print the enclosure .stl file. Make sure you put one breadboard on the top of the box, and keep the second one on a flat surface (like your table) to begin with.

2: Wire the photoresistor and the buzzer from the Arduino Uno (pinout also works for Arduino MEGA) to the breadboard that's not on the box.

3: Plug wires for breadboard on box into Arduino, but do not connect them to breadboard yet.

____

4: Tape or glue second breadboard and arduino uno inside of the box (see reference images below)

5: Bring photoresistor out through the front of the box.

6: Finally, bring the wires that for breadboard on top through the hole on the top of the box and wire them to their respective locations on the breadboard.

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x Arduino IDE 2.3.7"
author: "nolanayodeji"
category: "Audio & Sound"
components:
  - "1x 3D Printer (generic)"
  - "1x Photoresistor sensor module"
  - "1x Ardunio Uno R3"
  - "1x 3D printer filament (PLA)"
  - "1x Piezo buzzer"
  - "2x Breadboard 100x50"
description: "Play a quick tune! Build a minimalist digital piano using three push buttons to trigger distinct musical frequencies from a hidden buzzer."
difficulty: "Easy"
documentationLinks: []
downloadableFiles:
  - "https://projects.arduinocontent.cc/92486cfa-5930-407e-ba21-e65dbc662f40.ino"
encryptedPayload: "U2FsdGVkX18F1Bo7AMDWFY9/EfZwPsR7Jw37H7T7+y/8CQDXPVLeJ9GrSjtg+jTON0ahhQh0k9BfhCF77cnfUjEh/XFWFz5WeNk1cCcOVf4="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/3-note-piano-box-whidden-speaker-8f483c_cover.png"
lang: "en"
likes: 0
passwordHash: "adff8b585c5586f173e9446e0c2e1d520a0ad94b6121abd201e775682058811f"
price: 870
seoDescription: "Build a 3 Note Piano Box with a hidden Speaker. Play F, G, A, F#, G#, A# using a 3D printed box. Great DIY Arduino project."
tags:
  - "Audio"
  - "Music"
title: "3 Note Piano Box (w/hidden Speaker)"
tools: []
videoLinks: []
views: 14