Ein passives Summermodul erzeugt Ton, indem es ein digitales Rechtecksignal (oft per PWM) an den S-Steuerpin in hörbare Töne umwandelt. Verbinde VCC mit der Versorgung und GND mit Masse und variiere dann das PWM-Signal bzw. das Schalten an S, um die wahrgenommene Tonhöhe oder Muster zu ändern.
| Pin | Signal | Beschreibung |
|---|---|---|
S |
PWM | Buzzer drive input — apply a PWM/square wave tone signal from the controller |
VCC |
power | Positive supply for the buzzer module, typically connected to 5V |
GND |
ground | Ground reference for the buzzer module and control signal |
| Von | Nach | Kabel |
|---|---|---|
board:D9 |
x1:S |
green |
board:5V |
x1:VCC |
red |
board:GND |
x1:GND |
black |
Dieses Beispiel wurde für das arduino-uno geschrieben und kompiliergeprüft. Codey Online passt es für jedes andere unterstützte Board an.
// Passive Buzzer Module example for Arduino Uno
// Plays a short melody using a PWM/square wave output on D9.
const int BUZZER_PIN = 9;
// Note frequencies in Hz
const int NOTE_C4 = 262;
const int NOTE_D4 = 294;
const int NOTE_E4 = 330;
const int NOTE_G4 = 392;
const int NOTE_C5 = 523;
void playTone(int frequency, int duration) {
tone(BUZZER_PIN, frequency);
delay(duration);
noTone(BUZZER_PIN);
delay(50);
}
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Passive Buzzer Module demo starting...");
}
void loop() {
Serial.println("Playing melody...");
playTone(NOTE_C4, 300);
playTone(NOTE_D4, 300);
playTone(NOTE_E4, 300);
playTone(NOTE_G4, 300);
playTone(NOTE_C5, 600);
delay(1000);
}
Beschreib einfach, was du bauen willst. Codey Online schreibt den Code, zeichnet den Schaltplan, kompiliert alles und flasht dein Board direkt aus dem Browser.
Kostenlos starten