108个传感器之-无源蜂鸣器(12)

108个传感器之-无源蜂鸣器(12)

介绍

使用此模块,您可以通过使用PWM信号来控制被动压电蜂鸣器来生成不同的声音。PWM信号是特殊的电信号,可以以不同的频率发送以产生不同的声音。蜂鸣器可以产生1.5 kHz至2.5 kHz的声音。它的电压为3.3 V至5 V,且小巧,紧凑,尺寸为18.5 x 15 mm。如果您在项目中需要声信号或警报音调并且易于集成,则此模块是理想的选择。

Technical Data
Operating voltage 3,3 V - 5 V
Tone generation range 1,5 kHz - 2,5 kHz
Dimensions 18,5 x 15 mm

引脚连接

pin 引脚连接开发板的 gpio 接口即可:

Arduino Sensor
Pin 3 Signal
- +V
GND GND

代码示例

1. 普通版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int buzzer = 8 ; // Declaration of the buzzer output pin

void setup() {
pinMode(buzzer, OUTPUT); // Initialization as output pin
}
void loop() {
unsigned char i;
while(1) {
// In this program, the buzzer is controlled alternately with two different frequencies
// The signal here consists of a square wave voltage.
// Turning the buzzer on and off then generates a tone that corresponds approximately to the frequency.
// The frequency is defined by how long the on and off phases are

// 1.frequency
for(i = 0; i <80; i++) {
digitalWrite(buzzer, HIGH);
delay(1);
digitalWrite(buzzer, LOW);
delay(1);
}

// 1 second pause
delay(1000);

// 2.frequency
for(i = 0; i <100; i++) {
digitalWrite(buzzer, HIGH);
delay(2) ;
digitalWrite(buzzer, LOW);
delay(2);
}

// 1 second pause
delay(1000);
}
}

小结

待完善…

108个传感器之-无源蜂鸣器(12)

http://blog.jzxer.cn/20241218/20241219-passive-piezo-buzzer/

作者

dev

发布于

2024-12-18

更新于

2025-01-13

许可协议

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×