c
c
cavedu
Search…
CAVEDU教育團隊
BOSON電子積木套件
LinkIt 7697 BlocklyDuino 使用指南
LinkIt 7697 - Arduino IDE 開發指南
洞洞么教學材料包
洞洞兩教學材料包(貓咪盃硬體組材料包)
模組使用教學
LED模組
繼電器
大顆LED紅綠燈整合模組
旋轉可變電阻
光線模組
土壤溼度模組
避障紅外線模組
按鈕模組
滾珠開關模組
霍爾磁性模組
RGB LED共陰模組
電晶體MOS模組
兩路L9110S馬達模組
無源蜂鳴器
SR-04P超音波
DHT11溫溼度模組
舵機
LCD1602液晶模組
Max7219 8X8 矩陣LED模組
WS2812 RGB12燈燈環模組
Arduino首次接觸就上手
其他感測器模組
MCS Lite 介紹及感測器網頁遠端監控
初學Jetson Nano不說No-CAVEDU教你一次懂
Powered By
GitBook
無源蜂鳴器
專案說明
使用「科易KEYES Arduino UNO R3 開發板」連接「無源蜂鳴器」, 每一秒控制無源蜂鳴器模組發出各種音階的聲音。
此
無源蜂鳴器
包含於「
洞洞兩教學材料包 Education Kit 002
」內。
電路圖
KEYES Arduino UNO R3
通用型彩色Sensor shield v5.0感測器擴充板
無源蜂鳴器
無源蜂鳴器
是
脈衝寬度調變(Pulse Width Modulation)訊號
輸出,可以接「D3、D5、D6、D9、D10」的 KEYES Arduino UNO R3訊號端上。 本範例連接到「
D3
」
蜂鳴器分為「有源蜂鳴器」及「無源蜂鳴器」,「有源蜂鳴器」僅能發出單一頻率的聲音;「無源蜂鳴器」可依據不同的頻率發出不同聲調的聲音。
Arduino 程式
每一秒控制無源蜂鳴器發出兩隻老虎音調的聲音。
tone()函數說明:
tone(pin, frequency, duration)
pin=訊號接口,frequency=頻率,duration=間距
範例使用到的音階有Do(523Hz), Re (587Hz), Mi(659Hz), Fa(698Hz), So(784Hz), La(880Hz), Si(988Hz) 到高音 Do (1047Hz)
產生出的 Arduino 程式如下
1
//兩隻老虎
2
int
buzzer
=
3
;
//設定蜂鳴器接腳為第3孔
3
int
duration
=
500
;
4
int
aSo
=
392
;
5
int
bDo
=
523
;
6
int
bRe
=
587
;
7
int
bMi
=
659
;
8
int
bFa
=
698
;
9
int
bSo
=
784
;
10
int
bLa
=
880
;
11
int
bSi
=
988
;
12
int
bDDo
=
1047
;
13
14
void
setup
()
15
{
16
pinMode
(
buzzer
,
OUTPUT
);
//設定蜂鳴器為輸出
17
}
18
void
loop
()
19
{
20
tone
(
3
,
bDo
,
duration
);
21
delay
(
600
);
22
tone
(
3
,
bRe
,
duration
);
23
delay
(
600
);
24
tone
(
3
,
bMi
,
duration
);
25
delay
(
600
);
26
tone
(
3
,
bDo
,
duration
);
27
delay
(
800
);
28
29
tone
(
3
,
bDo
,
duration
);
30
delay
(
600
);
31
tone
(
3
,
bRe
,
duration
);
32
delay
(
600
);
33
tone
(
3
,
bMi
,
duration
);
34
delay
(
600
);
35
tone
(
3
,
bDo
,
duration
);
36
delay
(
800
);
37
38
tone
(
3
,
bMi
,
duration
);
39
delay
(
600
);
40
tone
(
3
,
bFa
,
duration
);
41
delay
(
600
);
42
tone
(
3
,
bSo
,
duration
);
43
delay
(
800
);
44
45
tone
(
3
,
bMi
,
duration
);
46
delay
(
600
);
47
tone
(
3
,
bFa
,
duration
);
48
delay
(
600
);
49
tone
(
3
,
bSo
,
duration
);
50
delay
(
800
);
51
52
tone
(
3
,
bSo
,
duration
);
53
delay
(
600
);
54
tone
(
3
,
bLa
,
duration
);
55
delay
(
600
);
56
tone
(
3
,
bSo
,
duration
);
57
delay
(
600
);
58
tone
(
3
,
bFa
,
duration
);
59
delay
(
600
);
60
tone
(
3
,
bMi
,
duration
);
61
delay
(
700
);
62
tone
(
3
,
bDo
,
duration
);
63
delay
(
800
);
64
65
tone
(
3
,
bSo
,
duration
);
66
delay
(
600
);
67
tone
(
3
,
bLa
,
duration
);
68
delay
(
600
);
69
tone
(
3
,
bSo
,
duration
);
70
delay
(
600
);
71
tone
(
3
,
bFa
,
duration
);
72
delay
(
600
);
73
tone
(
3
,
bMi
,
duration
);
74
delay
(
700
);
75
tone
(
3
,
bDo
,
duration
);
76
delay
(
800
);
77
78
tone
(
3
,
bDo
,
duration
);
79
delay
(
700
);
80
tone
(
3
,
aSo
,
duration
);
81
delay
(
700
);
82
tone
(
3
,
bDo
,
duration
);
83
delay
(
800
);
84
85
tone
(
3
,
bDo
,
duration
);
86
delay
(
700
);
87
tone
(
3
,
aSo
,
duration
);
88
delay
(
700
);
89
tone
(
3
,
bDo
,
duration
);
90
delay
(
800
);
91
delay
(
2000
);
92
}
93
94
Copied!
Previous
兩路L9110S馬達模組
Next
SR-04P超音波
Last modified
2yr ago
Copy link
Contents
專案說明
電路圖
Arduino 程式