Introduction
A buzzer is an audio signalling device. There are two types of buzzers, a passive buzzer and an active buzzer. In this guide, we will learn to differentiate between the two, then connect a passive buzzer module to the micro:bit and get it to play a song and change its bpm with a button press.Â
A light dependent resistor will also be added to the circuit, to create an alarm clock that automatically rings when it gets bright.
After completing this guide, you will understand the basics involved in using a buzzer, and can go on to make your own creations.
-
-
-
-
-
-
-
-
-
-
-
basic.forever(function () { pins.digitalWritePin(DigitalPin.P0, 0) basic.pause(1000) pins.digitalWritePin(DigitalPin.P0, 1) basic.pause(1000) })
-
music.beginMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Forever)
-
input.onButtonPressed(Button.A, function () { music.changeTempoBy(5) }) music.beginMelody(music.builtInMelody(Melodies.Nyan), MelodyOptions.Forever)
-
let lightVal = 0 basic.forever(function () { lightVal = pins.analogReadPin(AnalogPin.P1) })
-
let lightVal = 0 basic.forever(function () { lightVal = pins.analogReadPin(AnalogPin.P1) basic.showNumber(lightVal) })
-
let lightVal = 0 basic.forever(function () { lightVal = pins.analogReadPin(AnalogPin.P1) basic.showNumber(lightVal) if (lightVal < 600) { music.beginMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Once) } })
-
let lightVal = 0 let playingMusic = 0 music.onEvent(MusicEvent.MelodyEnded, function () { playingMusic = 0 }) playingMusic = 0 basic.forever(function () { lightVal = pins.analogReadPin(AnalogPin.P1) if (lightVal < 600 && playingMusic == 0) { music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once) playingMusic = 1 } basic.showNumber(lightVal) })
-
let lightVal = 0 basic.forever(function () { lightVal = pins.analogReadPin(AnalogPin.P1) basic.showNumber(lightVal) if (lightVal < 600) { pins.digitalWritePin(DigitalPin.P0, 0) basic.pause(500) pins.digitalWritePin(DigitalPin.P0, 1) basic.pause(500) } })
-