Вы находитесь на странице: 1из 3

Arduino and speaker example

Another simple example is to hook up a speaker to your Arduino.

Schematic

arduino speaker schematic


Layout

arduino speaker

Code
A simple example.

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

int pin = 8;
int note = 988;
void setup()
{
}
void loop()
{
//3 dots for the S
for (int i=0; i<3; i++)
{
tone(pin, note, 100);
delay(200);
noTone(pin);
}
delay(200);
//3 dashes for the O
for (int i=0; i<3; i++)
{
tone(pin, note, 300);
delay(400);
noTone(pin);
}
delay(200);
//3 dots for the S again
for (int i=0; i<3; i++)
{
tone(pin, note, 100);
delay(200);

31
32
33
34
35
36

noTone(pin);
}
delay(200);
//wait 3 seconds
delay(3000);
}

Parts List

Amount
1
1
1

Part Type
Arduino Uno (Rev3)
100 Resistor
Loudspeaker

Вам также может понравиться