1

Program the Buzzer

Watch this video to understand how your buzzers work and how to program them. Make sure your volume is up!

Start your code by including the Smart Inventor library before void setup():

#include <SmartInventor.h>

Are you ready? Make some noise! Enter the code below inside void loop() to have your buzzer make a low-pitched tone.

SmartInventor.Buzz(200, 8);

Your SmartInventor.Buzz() codes will typically look like this:

SmartInventor.Buzz( Frequency, Tempo);

This function will allow you to enter numbers for the frequency and tempo of the buzzers. Based on those values, you can manipulate the sound that the buzzer makes.

Frequency is the amount of vibrations that the buzzer will make within a designated time, and that will determine the pitch of your buzzer. Acceptable numbers range from 0 (looooooow pitch) to 9,223,372,036,854,775,807 (so high you won’t be able to hear it).

Tempo is the speed at which you want the frequency to occur. Acceptable numbers range from 0 (extremely long amount of time) to 2,147,483,647 (so short you won’t be able to hear it).You’ll probably want to be able to tell when one buzzer stops and another one starts. Include a delay to assign a time step for when the next noise should play:

delay(500);

Next, we will try making a higher-pitched tone, and place another delay immediately after:

SmartInventor.Buzz(500, 8);
delay(500);

This should give you a program that will make both high and low pitch sounds!Your final code should look something like this. Change it up so you can make your own song!

#include <SmartInventor.h>

void setup() {
// put your setup code here, to run once:
}

void loop() {
//put your main code here, to run repeatedly:

SmartInventor.Buzz(200, 8);
delay(500);

SmartInventor.Buzz(500, 8);
delay(500);

}