Sketches: Small Passive Buzzer Module

HCMODU0009_800
Small Passive Buzzer Module

Items you will need:

Arduino development board such as this one

Male to female dupont cables

Passive Buzzer Module

100R Resistor

 

Pinout:

PIN 1: Speaker input (Connect this via a 100R resistor)
PIN 2: NA
PIN 3: GND

What does it do?

This is a very simple module that requires only one DIO pin (defined as an output) to operate. This program will repeatedly play a set of musical notes using the standard Arduino Tone function.

Code:
[cpp]
/* FILE: ARD_Speaker_Module_Example
DATE: 05/06/13
VERSION: 0.1

You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd’s own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.

*/

/* The digital pin that the speaker module ‘S’ input is connected to */
#define SPEAKERPIN 2

/* Frequencies for musical scale notes */
#define NoteC1 262
#define NoteD1 294
#define NoteE1 330
#define NoteF1 349
#define NoteG1 392
#define NoteA1 440
#define NoteB1 494
#define NoteC2 523

/* Store a set of notes to play */
static int Song[] = {NoteC1,NoteD1,NoteE1,NoteF1,NoteG1,NoteA1,NoteB1,NoteC2,NoteC2};

/* Indexes the next note to play */
byte Index;

void setup()
{
/* Set the DIO pin that the speaker is connected to as an output and then set it
low so that it isn’t driving the speaker */
pinMode(SPEAKERPIN, OUTPUT);
digitalWrite(SPEAKERPIN, LOW);
}

/* Main program */
void loop()
{
/* Play each note in sequence */
for(Index = 0; Index < 9; Index++)
{
/* Output the current note to the speaker for 500ms*/
tone(SPEAKERPIN, Song[Index]) ;
delay(500);
}
/* Stop playing the last note */
noTone(SPEAKERPIN);
/* Wait a second before starting again */
delay(1000);
}
[/cpp]

Leave a Reply

Your email address will not be published. Required fields are marked *