Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

For more information on how Google's third-party cookies operate and handle your data, see: Google Privacy Policy

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

No cookies to display.

David PerksCreate Music with Light!

About the Author

David is an artist maker who has added electronic junk and microprocessors to his palette.

@pdbperks http://dperks.co.uk/

You will need:

  • micro:bit.

  • Earphones.

  • Paper.

  • Thin wire.

There are already guides to attaching headphones to the micro:bit and using the light sensor to create sound.  This article will show you how to achieve impressive results with the minimum of code and a rather neat hardware solution.

Software:

  1. Use MakeCode.

  2. Start a new file.  ‘on start’ and ‘forever’ blocks are automatically created.

  3. Drag the ‘on start’ block onto the menu; it becomes a bin; let go and delete it.

  4. Click on the Music menu; select ‘ring tone (Hz)’; drag it into the ‘forever’ block.

  5. Select the Input menu; scroll to the bottom and select the ‘light level’ block; place this block in ‘ring tone (Hz)’ block in the slot that currently reads ‘Middle C’.

  6. Save the project, open the save folder, and copy the file to the micro:bit.

Hardware:

One of the prime features of the micro:bit is its 5 x 5 array of light emitting diodes. This allows low resolution but effective visual communication to be delivered without additional hardware.  The designers have taken advantage of an interesting property of the LED; it will generate an electric current if a light is shone on it.  It is the LED array that provides MakeCode’ ‘light level’ reading: there is no need for an additional light sensor.

With the code in place, the virtual micro:bit on the MakeCode editor page shows Pin 0 and GND connected to the jack plug of a headphone.  If you have crocodile clip leads then this is the quickest way to test the circuit but it would be a shame to miss out on hardware projects due to a lack of crocodile clips.  A quick headphone socket can easily be improvised: indeed, it could be seen as a better option.

Headphones attached to micro:bit

The large pin sockets are slightly larger than a headphone plug: so use a thin strip of paper, the width of the socket, and fold it back on itself two or three times. Use this strip to wedge the plug firmly into the GND socket.  The paper will insulate part of the plug but there will still be enough contact for the circuit.

Connect a thin wire from Pin 0 to the tip of the headphone plug.  If you do not have thin wire, try using a coated food tie.  This is actually a good option; the wire is just the right gauge for the job.  Strip 15mm of insulation from each end of the wire to allow a good connection.

Drawing of wiring the ground Pin

Start by attaching the wire to Pin 0.  Put the wire through the hole to the side and twist it tightly: it should sit safely just above the small Pin 3 but you could cover that with tape if you wanted to be extra careful.

Drawing of wiring the headphone jack

Wrap the other end of the wire around the tip of the headphone plug: the tip has a notch that makes this task easy.

Action:

Power up the micro:bit and expose it to light to generate sound. The stronger the light, the higher the pitch.   Use your hand over the LEDs to play the instrument.

Torches with strobe effects are great fun.  If you want louder noise then you can use the same method to connect the micro:bit to an amplifier using a suitable phono cable.