Introduction

In this lesson, we will show how to use the mircro bit with the active buzzer. When we press the button”A”, the buzzer will continue to beep, and when we press the button “B”, the sound will disappear.

Parts Needed

You will need the following parts:

About Buzzer

As a type of electronic buzzer with integrated structure, buzzers, which are supplied by DC power, are widely used in computers, printers, photocopiers, alarms, electronic toys, automotive electronic devices, telephones, timers and other electronic products for voice devices. Buzzers can be categorized as active and passive ones (see the following picture). Turn the pins of two buzzers face up, and the one with a green circuit board is a passive buzzer, while the other enclosed with a black tape is an active one.

The difference between an active buzzer and a passive buzzer is:

An active buzzer has a built-in oscillating source, so it will make sounds when electrified. But a passive buzzer does not have such source, so it will not tweet if DC signals are used; instead, you need to use square waves whose frequency is between 2K and 5K to drive it. The active buzzer is often more expensive than the passive one because of multiple built-in oscillating circuits.In this lesson, we use the active buzzer.

Note:

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.

Example

As I have discussed above Red terminal is connected to PIN 0 and the blackterminal is connected to GND.

And if you don’t have a black and red terminal at the buzzer you have then simply there will be two terminal called +ve and -ve or just for generalization big and small then connect your big pin to PIN0 of micro:bit and small to GND of micro:bit.like this

Run Your Script on the Makecode

Either copy and paste, or re-create the following code into your own MakeCode editor by clicking the open icon in the upper right-hand corner of the editor window. You can also just download this example by clicking the download button in the lower right-hand corner of the code window.

MICROPYTHON

RESULT

A few seconds after the upload finishes, you should hear the buzzer beep for one second,  when we press the button”A”, the buzzer will continue to beep, and when we press the button “B”, the sound will disappear.