Home LearningBasics Arduino and speaker example

Arduino and speaker example

by shedboy71

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

 

Schematic

arduino speaker schematic

arduino speaker schematic

Layout

 

arduino speaker

arduino speaker

 

Code

A simple example.

 

[c]
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);
noTone(pin);
}
delay(200);
//wait 3 seconds
delay(3000);
}
[/c]

Parts List

 

Amount	Part Type
1	Arduino Uno (Rev3)
1	100 Ω Resistor
1	Loudspeaker
Share

You may also like