Note: ALL OSOYOO Products for Arduino are Third Party Board which is fully compatitable with Arduino

                                                          

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES ここでご購入を!

Content

  1. Introduction
  2. Preparations
  3. About the button
  4. Connection
  5. Upload Sketch
  6. Program Running Result

Introduction

The buzzer is a small component with a piece of metal in it that moves when you apply a voltage across it. This motion causes a small sound, or “click.”

If you turn the voltage on and off fast enough, you get different beeps, squeals, chirps and buzzes. You will use PWM to control the speed of turning the piezo on and off — and, in turn, the audio frequency coming out of the buzzer. Adjusting the PWM enables you to get legitimate notes out of the buzzer.

If you flip the buzzer over and look at the bottom, you will see that one pin has a (+) next to it. That pin gets connected to a signal from the P0 pin. The other pin should be connected to ground.

Note: We use the buzzer module in this project.

Preparations

Hardware

Software

Arduino IDE (version 1.6.4+)

Connection

First, please plug Osoyoo Magic I/O shield into OSOYOO basic  Board:

Then connect the Passive Buzzer module to the D8 port of the Magic I/O shield with a 3-pin PNP cable as below:

Upload Sketch

After above operations are completed, connect the OSOYOO basic  Board to your computer using the USB cable. The green power LED (labelled PWR) should go on.

Code Program

You can download the sketch from this link or copy below code to your Arduino IDE window:

int buzzer = 8;//the pin of the passive buzzer
void setup() {
pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output
}
void loop() {
unsigned char i;
while(1)
{ //output an frequency
for(i=0;i<80;i++) {
digitalWrite(buzzer,HIGH);
delay(1);//wait for 1ms
digitalWrite(buzzer,LOW);
delay(1);//wait for 1ms
} //output another frequency
for(i=0;i<100;i++) {
digitalWrite(buzzer,HIGH);
delay(2);//wait for 2ms
digitalWrite(buzzer,LOW);
delay(2);//wait for 2ms
}
}
}

Compile and upload

Open the Arduino IDE and select corresponding board type and port type for your OSOYOO basic  Board.

After compile this sketch, simply click the “Upload” button in the environment. Wait a few seconds – you should see the RX and TX leds on the board flashing. If the upload is successful, the message “Done uploading.” will appear in the status bar.

Running Result

A few seconds after the upload finishes, you should hear the buzzer beep.

Note again:

The active buzzer has built-in oscillating source, so it will beep as long as it is electrified, but it can only beep with a fixed frequency.