Buzzer En: 두 판 사이의 차이
(Created page with "{{#seo:|title=아두위키 : 아두이노 수동 부저 가이드|title_mode=append|keywords=아두이노, 정보과학, 메이커학습, 수행평가, 수동 부저, 아두이노 작품, 캡스톤작품, 아두이노 예제코드|description=아두이노로 수동 부저를 제어하는 방법(기본정보, 회로, 예제 코드)을 소개합니다. 정보과학과 메이커수업에 활용가능합니다.}} center|class=coders100 A component...") |
잔글편집 요약 없음 |
||
151번째 줄: | 151번째 줄: | ||
}else | }else | ||
{ | { | ||
} | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> |
2024년 3월 24일 (일) 14:16 판
A component that emits sound when a specific frequency value is applied.
It operates between 3.3V to 5V.
Required Hardware
- Buzzer
- Arduino Board
- Jumper Cables
Connection
Since it has polarity, make sure to check the + and - terminals.
It is okay to connect to a digital pin other than D11.
buzzer | Arduino UNO |
+ | D11(changeable) |
- | GND |
Example Code
Reference Material: Standard Frequencies for Octaves and Scales
Example 1. Scale Test
#define buzzer 11
int numTones = 8;
// In order (C4, D4, E4, F4, G4, A4, B4, C5)
double tones[] = { 261.6256, 293.6648, 329.6276, 349.2282, 391.9954, 440, 493.8833, 523.2511 };
int cnt = 0;
void setup()
{
}
void loop()
{
if (cnt == 0)
{
for (int i = 0; i < numTones; i++)
{
// Use the tone(pin, frequency) function.
tone(buzzer, tones[i]);
delay(500);
}
// If you do not use the noTone function, the previously inputted tone function will continue,
// so turn off the sound with the noTone function.
noTone(buzzer);
delay(500);
cnt++;
}
}
Example 2. Simple Melody
#define buzzer 11
int numTones = 8;
double g_tones[] = { 195.9977, 220, 246.9417, 261.6256, 293.6648, 329.6276, 349.2282, 391.9954 };
//G0, A1, B2, C3, D4, E5, F6, G7
int cnt = 0;
void setup()
{
}
void loop()
{
if (cnt == 0)
{
tone(buzzer, g_tones[0]);
delay(250 * 2);
noTone(buzzer);
tone(buzzer, g_tones[3]);
delay(250 * 2);
noTone(buzzer);
tone(buzzer, g_tones[2]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[3]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[4]);
delay(250 * 2);
noTone(buzzer);
tone(buzzer, g_tones[3]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[4]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[5]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[5]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[6]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[5]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[1]);
delay(250 * 2);
noTone(buzzer);
tone(buzzer, g_tones[4]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[4]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[3]);
delay(250 * 2);
noTone(buzzer);
tone(buzzer, g_tones[3]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[3]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[2]);
delay(250 * 2);
noTone(buzzer);
tone(buzzer, g_tones[1]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[2]);
delay(125 * 2);
noTone(buzzer);
tone(buzzer, g_tones[3]);
delay(250 * 4);
noTone(buzzer);
cnt++;
}else
{
}
}