Arduino Mega 2560

What is buzzer?

A buzzer is an audio signaling device which is mostly used as an alarming device or a user input feedback in devices. Buzzers can make beeping sounds in different frequencies and durations. Typical applications including siren, alarm devices, fire alarm. It is widely used in household appliances, electronic toys game machine and many more industries. The big advantage of a buzzer is the wide spectrum of volume. For example it is used in high volume as an alarm system and on low volume as a children’s toy. By appending sounds you can generate music with it. Sounds are generated in different frequencies by sending PWM signals from the microcontroller. PWM is a square shaped signal. The frequency of the PWM is determined by the number of squares generated in a second. You can learn more about PWM on the internet. The duration of the PWM signal determines the duration of the beep.

arduino with a buzzer
Figure 1 - Arduino Mega 2560 with a buzzer

Required hardware

  • Arduino Mega 2560
  • Buzzer
  • Resistor 100Ω

Source code to install on controller


Before you upload this code to your Arduino, please format the EEPROM...
#include <OzIDManager.h>
#include <OzBuzzerController.h>

// global pointers
OzIDManager *manager;
OzBuzzerController *buzzer;

int buzzerPin = 10;

void setup()
{
  Serial.begin(115200);

  manager = new OzIDManager;
  manager->_sendACK = true;
  manager->_checksum = true;
  
  OzCommunication::setIDManager(manager);
  
  buzzer = new OzBuzzerController(buzzerPin);

  int x = 1;
  manager->sendLinkSetup();
  manager->PrintWelcomeLine(buzzer, x++, "MyBuzzer");
}

void loop()
{
    buzzer->ownLoop();
    OzCommunication::communicate();
}