Overview
The latest micro:bit (V2) has a built-in speaker that can play sounds directly. You can also output sound from either a V1 or V2 to a pair of headphones or speaker by connecting them to the signal on Pin0.
Common ways to do this are by using a set of analogue headphones with a jack plug on the end or using an inexpensive piezo speaker. You can buy an adaptor to make this easier, or improvise with common materials.
Contents
Connection
Headphones/audio jack
Connect Pin0 to the tip and GND to the sleeve of the jack. If you have four rings on the headphones, choose the top and bottom rings.
Headphones/audio jack with extra connector
You can cheaply buy an adaptor from 3.5mm mono (or stereo) audio plug to crocodile clips. In this case, connect the crocodile clips directly to Pin0 and GND as above, using the black clip for GND. These adaptors may also be sold as an "audio cable for micro:bit".
Piezo speaker
Connect Pin0 to the red lead and GND to the black lead of the speaker.
There are lots of fun and interesting ways to connect up the headphones or speaker. If you have tried another method, let us know so we can share it in this article
This example by @kgiori shows the headphone jack inserted through the GND ring so that the sleeve of the jack is touching GND. A bent paperclip connects the tip of the jack to Pin0.
This example from Daisy shows tin foil and tape being used to connect the pins to the headphone jack:
Programming
MakeCode
Place a play melody block from the Music menu underneath the on start block to play a melody when the micro:bit is powered on or reset.
Python
Import the music module and then use music.play() to play a melody when the micro:bit is powered on or reset.
import music
music.play(music.ENTERTAINER)
Mute sound and control the volume
See our article on muting the micro:bit and controlling the volume for more information.