How to control evive’s buzzer in Arduino IDE

evive Peizo Buzzer
About This Tutorial
This tutorial discusses what is a piezo buzzer, evive’s inbuilt buzzer, how to control it in Arduino IDE with the help of an Arduino IDE sketch.
Tutorial Info

Components Required

ImageComponentQuantityAvailable in Kit
evive1
USB A-B Cable1

Introduction

A piezo buzzer is an electronic device that is commonly used to produce sound. The working principle behind it is the inverse effect of piezoelectricity. Piezo electricity, or the piezo electric effect is the ability of certain materials to generate electric charge when mechanical pressure is applied on them. This effect was discovered by the French scientist brothers Jacques and Pierre Curie. The word Piezoelectric is derived from the Greek piezein, which means to squeeze or press, and piezo, which is Greek for push.

One of the notable features of the piezo electric effect is that it is reversible, meaning if an electrical field is applied to the object made of piezo electric material, mechanical stress is generated, i.e. it either stretches or compresses. These deformations leads to the generation of audible sound.

evive has an inbuilt piezo buzzer. The piezo buzzer is connected to digital pin 46 of Arduino Mega and is controlled via PWM.

evive Peizo Buzzer

 Controlling Piezo Buzzer

To generate the electric signal from evive to control the buzzer, we use the tone() function. It generates a square wave of the specific frequency with a 50% duty cycle on digital pin 46. A different duty cycle can be specified otherwise. The wave continues until the noTone() function is called. 

evive Notes Icon
Only one tone can be generated at a time. If a tone is already playing on a different pin (when multiple buzzer are connected only one is played at a time), the call to tone() will have no effect. If the tone function is called on the same pin, then the call will change its frequency.

The frequency range is from 31 Hz to 65535 Hz.

Syntax

tone(pin, frequency) 

tone(pin, frequency, duration)

where

  • pin: the pin on which to generate the tone
  • frequency: the frequency of the tone in hertz – unsigned int
  • duration: the duration of the tone in milliseconds (optional) – unsigned long

Example

Below are the Arduino IDE sketch showing how to use the piezo buzzer and play specific tones on Buzzer:

First example shows how to use tone() function. In this example different frequencies are played on buzzer.

In this example song of specific length is played on evive buzzer.

This helped
This didn't help
Share this Tutorial
Share on facebook
Facebook
Share on twitter
Twitter
Share on google
Google+
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Projects & Tutorials
All articles loaded
No more articles to load
Featured Projects
Arcade-Basketball-Game
DIY Arcade Basketball Game
Introduction“We don’t stop playing because we grow old; we grow old because we stop playing.”…
All articles loaded
No more articles to load
Close Menu
×

Cart