Make the buzzer sound by sending an oscillating signal to it.

The Grove Beginner Kit For Arduino includes an Arduino Uno board with preconnected devices. The Grove lessons supporting this present coding using the Arduino IDE. These pages present the same lessons using the Codecraft IDE that uses the Block style of coding with specific Grove Arduino blocks.


The buzzer can be made to sound using the system's PWM capability.

A Buzzer makes a high pitched sound when activated. Somed buzzers are active. You send an on or off signal to it like the LED. You turn them on or off. Others are passive. You send a “square wave” or oscillating signal to it. Such a signal rapidly switches between on and off (hi and lo), 100s or 1000s of times a second. This rate is the pitch of the buzzer.


The buzzer in this kit is passive. A digital oscillating signal over time looks like:

digital signal

An alternative oscillating signal is called a “sine wave”:

analog signal

Both can be used with a buzzer but a square wave is what is normally used with a buzzer, and simpler to produce in a digital situation. In this lesson we use a Pulse Width Modulation (PWM) capabilty of the Arduino microprocessor to generate the square wave.

PWM will be covered in detail in the next lesson. For now, it is simple way to produce an oscullating signal without having to continuously toggle it in code hi-lo-hi-lo … etc.

Grove Beginners Kit

The board lesson 4

Components this lesson
  1. Grove LED
  2. Grove Buzzer
  3. Grove Button

Component Interface Type Pins or Address
LED Digital output D4
Buzzer Digital output D5
OLEDDisplay0.96" I2C display I2C 0x78(default)
Button Digital input D6
RotaryPotentiometer Analog input A0
Light Analog sensor A6
Sound Analog sensor A2
Temperature&HumiditySensor DHT22 Digital sensor D3
AirPressureSensor BMP280 I2C sensor I2C 0x77(default)/0x76(optional)
3-AxisAccelerometer I2C sensor I2C 0x19(default)

When an analog value is written to pin D5 using the PWM component, that pin continuously sends a square wave to that pin until there is a digital write to it. That way the buzzer can be turned on and off by button presses and releases. The 128 value used could be a range of values but doesn’t impact the pitch, but the tone changes a little.

The lesson code block.

Lesson 4

PWM can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady rectangular wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite()) on the same pin.

How to create this ...

Watch the video on Youtube:

For this lesson, the buzzer sounds when the button is pressed. The LED lights when the button is not pressed.


  Next: > Jekyll
 This Category Links 
Category:Arduino Beginners Index:Arduino Beginners
<  Prev:   Grove Beginners kit