Software apps and online services
This article is all about connecting Piezo Buzzer and playing the sound on the buzzer using micro: bit.So let us have a quick introduction of a buzzer.
Piezo buzzer is a device or we can say that it is an electronic device which produces sound based on the reverse of the piezoelectric effect. The generation of pressure variation or strain by the application of an electric potential across a piezoelectric material is underlying principle.Basically, buzzers are used in the alert system corresponding to switching action, counter signal or sensor input and also used in the alarm circuit.
It produces a same noisy sound based on the voltage applied to it.Most buzzers produce sound in the range of 2 to 4khz.
And this is how a buzzer looks like.
And the connection of the buzzer is like thisRed to InputBlack to GND So now let us see How we can connect this buzzer to micro:bit and play some sound.So let's dive into it. Tools you need :
- micro:bit (1 pcs)
- USB (1 pcs)
- AA battery (2 pcs)
- Battery Box(1 pcs)
- Piezo Buzzer(1 pcs)
- Crocodile connector(jumpers) (2 pcs)
Let's have a look at the connection of micro:bit and buzzer.
As I have discussed above Red terminal is connected to PIN 0 and the black terminal 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
I hope there is no confusion in connection part if you have any question you can ask me in the comment section.
Let us see the coding part of this tutorial. So go to makecode.microbit.org and create a new project.
After this just go to Input and choose on Button A pressed.
so why we're using this because if we will use start or forever then it will play the sound on the buzzer start once and forever respectively.
that's why we're using this so that we will play this whenever we want.
Now next what we need to do is
Go to music block and grab Start melody block and leave it to default.
Now go to basic and choose pause just to provide some delay to play another melody.Ans after that place one more melody and chance the melody to another type.
That's all now your final code should look like this