Overview

The latest micro:bit revision includes a built-in speaker and by default, all programs that use sound will output the sound over both the speaker and the edge connector. This is great for experimenting with sound and you can still connect up a speaker or headphones if you want.


If you want to mute the micro:bit speaker or control the volume of the output, there are a few ways in which you can do this.


Contents


Turn the built-in speaker off/on (latest micro:bit only)

The latest micro:bit has a built-in speaker mounted on the back of the board. 


speaker location on the micro:bit


You can enable or disable this in the micro:bit editors.


Makecode

The Music menu contains a block that you can use in your program to set the speaker off or on

set speaker block in MakeCode

MicroPython

The MicroPython API lets you set the speaker on or off in the program. For example, this program will play a melody on both the speaker and pin 0 and then turn the built-in speaker off. The melody will then only output on Pin0 before the speaker is turned on again and the loop repeats.


from microbit import *
import music

while True:
music.play(music.BLUES)
speaker.off()
music.play(music.BLUES)
speaker.on()


Mute the MakeCode simulator

You can also mute the micro:bit simulator as well as the micro:bit. To do this, click on the speaker ? icon below the simulator. This will turn red for mute and back to grey for unmute.


Control the volume of the sound

Both MakeCode and Python Editors for micro:bit let you set the volume for the micro:bit. This code applies to both the on-board speaker and the sound output on the edge connector.


MakeCode

The set volume https://makecode.microbit.org/reference/music/set-volume block can be found in the Music menu in MakeCode

By default it is set to 127 or half volume and can be set within the range 0-255. 


To mute the device, you can set volume to 0




MicroPython

The set_volume() API can be found in the micro:bit module and can be passed a value in the range 0-255


For example, to mute the device you can set the volume to 0 and you will not hear the music.


from microbit import *

set_volume(0)

music.play(music.BLUES)



Sleep or power off to mute the micro:bit (latest micro:bit only)

Another simple way to mute the micro:bit is to put it to sleep or power off.  If you press and hold the power/reset button for 5 seconds, the micro:bit will enter a sleep mode to reserve power. Once you press the power/reset button the sound will stop. 

To wake the micro:bit, press the reset button again.



Keywords for search : mute, sound, volume, speaker, music