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 Music API lets you set the desired pin for the output of the sound  eg pin_speaker or pin0. If you do not specify the  pin, the sound will be output on both speaker and pin0.


For example, this script will play the BLUES music only on the speaker and then only on Pin0. 


from microbit import *

import music

music.play(music.BLUES, pin=pin_speaker)

music.play(music.BLUES, pin=pin0)


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