Module buzzer passif Arduino Ce buzzer passif émet un son d'environ 85 dB lorsqu'il est alimenté entre 4 V et 8 V. Ce buzzer passif nécessite un microcontrôleur pour produire un son à l'aide d'un signal PWM. Le buzzer consomme environ 30 mA. Tension : 5 V. Convient entre autres à Arduino.
| Broche | Signal | Description |
|---|---|---|
PWM |
PWM | PWM control input from the microcontroller to generate the buzzer tone. |
VCC |
power | Positive supply for the passive buzzer module, typically 5V. |
GND |
ground | Ground return for the buzzer module and control signal. |
| De | Vers | Fil |
|---|---|---|
board:D9 |
x1:PWM |
green |
board:5V |
x1:VCC |
red |
board:GND |
x1:GND |
black |
Cet exemple a été écrit et vérifié à la compilation pour le arduino-uno. Codey Online l'adapte pour vous à toute autre carte prise en charge.
// Passive buzzer module example for Arduino Uno
// Plays a simple melody using the module's PWM input.
const int buzzerPin = 9; // Connected to x1:PWM
void setup() {
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
Serial.println("Passive buzzer module demo starting...");
}
void playTone(int frequency, int durationMs) {
if (frequency > 0) {
tone(buzzerPin, frequency, durationMs);
}
delay(durationMs * 1.30);
noTone(buzzerPin);
}
void loop() {
Serial.println("Playing C major scale...");
int melody[] = {262, 294, 330, 349, 392, 440, 494, 523};
int noteDuration = 180;
for (int i = 0; i < 8; i++) {
Serial.print("Note frequency: ");
Serial.println(melody[i]);
playTone(melody[i], noteDuration);
}
Serial.println("Pausing...");
delay(1000);
}
Décrivez ce que vous voulez créer. Codey Online écrit le code, dessine le schéma de câblage, le compile et flashe votre carte directement depuis le navigateur.
Commencez gratuitement