Read the world · 09 / 16
Buzzer Piano: Keys & Note Frequencies
Play virtual piano keys and compare note frequencies. Learn the input-to-tone mapping and the limits of the single-button hardware sketch.
Combine discrete inputs with a buzzer output.
Understand it
Each virtual key selects one frequency. The displayed sketch is the minimal example for a single physical key; a full hardware keyboard needs separate input pins and a scanner.
Your experiment
Enable sound and run. Play C, E and G separately, comparing the frequencies in the monitor with the notes you hear.
Connections
- D2…D7, D12 — Illustrative keyboard inputs
- D8 — Buzzer output example
Sketch
This sketch illustrates the hardware logic. The workbench runs its corresponding teaching model, not a C++ compiler.
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(8, OUTPUT);
}
void loop() {
if (digitalRead(2) == LOW) {
tone(8, 262);
} else {
noTone(8);
}
}Quick check
Does the included sketch implement the whole virtual keyboard?
Show explanation
No. It illustrates one button triggering a tone. The virtual keyboard demonstrates several note frequencies; a physical keyboard needs additional inputs and code.