How to Program the Buzzer

This lesson will go over how to program the buzzer found installed in the Smart Inventor Board

First, begin the code by including the smart inventor library. Enter the following before the void setup(); method.

Learn More: What’s a library?

A library is a saved set of functions()  and variables that provide users with improved functionality when coding.

Any code that starts with SmartInventor._____  is a function in the SmartInventor library.  Any variable that highlights ORANGE, is an initialized variable from an included library.

Learn More

Next, inside   void loop(); , enter the following to use the buzzer to make noise. The following code will allow you to make a low pitched tone.

SmartInventor.Buzz( )

SmartInventor.Buzz( Frequency, Tempo);

This function will allow you to input numbers for the frequency and tempo and 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. Acceptable numbers will range from 0 to 9,223,372,036,854,775,807.

Tempo is the speed at which you want the frequency to occur. Acceptable numbers will range from 0 to 2,147,483,647.

Next, you input a  delay() to assign a time step for when the next noise should play.

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

This should provide you with a program that will make both a high and low pitch.

Activity:

Try to make your own song using the buzzer.

Final Code