element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
microbit
  • Learn
  • Learning Center
  • STEM Academy
  • microbit
  • More
  • Cancel
microbit
micro:bit Blog 10 BBC micro:bit Projects in 10 Days: Day Nine - Musical Light Box
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join microbit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jlucas
  • Date Created: 3 Jun 2016 11:46 AM Date Created
  • Views 4211 views
  • Likes 20 likes
  • Comments 11 comments
  • intermediate micro:bit projects
  • micro:bit
  • bbc micro:bit
  • microbit
  • intermediate_microbit_projects
  • bbc microbit
  • ten bbc micro:bit projects
  • bbc_micro:bit
  • 10projects10days
Related
Recommended

10 BBC micro:bit Projects in 10 Days: Day Nine - Musical Light Box

jlucas
jlucas
3 Jun 2016

https://www.microbit.co.uk/blocks/lessons/hack-your-headphones/activity

About this project

 

In this project, students learn how to program the light sensor on the BBC micro:bit, telling the device to react to different intensities of light. By attaching the micro:bit to a speaker or a pair of headphones, students can also tell the device to play different sounds when exposed to different light intensities.

 

What you'll need

 

1 x BBC micro:bit

1 x Micro USB

1 x Computer or tablet

2 x AAA Batteries & Battery Holder

1 x mini speaker or set of general purpose headphones

2 x Crocodile clips

 

Project walkthrough

 

  • Go to the BBC micro:bit website, click 'create code' and begin a new Microsoft Block Editor project.

 

  • Create a new variable called 'light' and set it to the input 'light level'

 

image

  • In the first instance, we're going to write a code that makes the LED array increase or decrease in brightness in relation to the intensity of light the sensor is exposed to.

 

  • Attach an if/do tile and create 4 x else/if and 1 x else options by clicking the blue cog icon in the tile.

 

image

  • Each of these options will be used to tell the LED array to display a different brightness depending on the intensity of the light.

 

  • To tell the device how to do this, connect a [0] < [0] block next to 'if' and place a 'light' variable in the left-hand dialog box. In the first instance, set the right dialog box to 25, so that the code reads if [light] < [25].

 

  • For 'do' attach a 'set brightness' tile from the LED commands menu, and a 'show leds' tile from the Basic commands menu. Set the brightness to 25, and check all of the individual LED boxes on the 'show leds' tile, telling the device to light up at a very dim illumination when the detected light level is lower than 25.

 

image

 

  • Duplicate all of these blocks for the four else/if options, and set the light levels to 50, 100, 150 and 180 respectively.

 

  • Set the brightness levels to 50, 100, 150 and 200 respectively.

 

  • Under the 'else' option, attach another 'set brightness' tile and set it to 250, telling the device to display the highest brightness when it detects any light intensity over 180.

 

  • Finally, wrap your code in an 'on Button A pressed' tile to create a function that switches on the light sensor.

 

image

image

  • You now have a basic code that can should tell your BBC micro:bit to get brighter or darker depending on the light intensity. You can compile this right away and test it out on your device.

 

  • However, if you want to make things a little more interesting, you can also expand the code so that your device also emits a different note depending on the light intensity detected by the sensor.

 

  • To do this, simply add a 'ring tone (hz) [c]' tile for every brightness level, and set each to a different ascending note. (i.e. C, D. E. F. G, A)

 

image

  • Compile your code and transfer it to your BBC micro:bit device. To take advantage of the musical element, you'll need to attach the device to a general purpose mini speaker or a set of headphones. Take two separate pairs of crocodile clips, attach the end of one to the 0 pin on your BBC micro:bit, and the end of the other to the GND pin.

 

  • Attach the other ends to the positive and negative inputs for your speaker, or attach the other end of the GND crocodile clip to the base of your headphone jack, and the other end of the 0 pin crocodile clip to the tip. You should now be able to hear the notes being played on the BBC micro:bit through your audio device. Try it out by moving your BBC micro:bit into lighter and darker areas.

 

Once your pupils have mastered the light box challenge, encourage them to see what else they can do to make the BBC micro:bit respond to its surroundings. They might want to experiment with other input settings such as temperature and acceleration. Let us know how they get on in the comments section below.

  • Sign in to reply

Top Comments

  • jlucas
    jlucas over 9 years ago in reply to zenandy +5
    balearicdynamics zenandy - The LEDs on the device act as light sensors as well as light emitters. So if you press 'A' in darker or brighter environments, you should see the brightness change accordingly…
  • Workshopshed
    Workshopshed over 8 years ago in reply to jlucas +4
    Wow, I did not know that... https://lancaster-university.github.io/microbit-docs/extras/light-sensing/
  • balearicdynamics
    balearicdynamics over 9 years ago +3
    Second project that needs mini speakers that seems extremely rare here ... Should provide absolutely one!
Parents
  • zenandy
    zenandy over 9 years ago

    Light sensor?  An accessory not mentioned in requirements?

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 9 years ago in reply to zenandy

    Sounds no light sensor but light intensity. Changes the brightness of the LED pattern on the mico

     

    Where did you read about reading the light intensity ?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • balearicdynamics
    balearicdynamics over 9 years ago in reply to zenandy

    Sounds no light sensor but light intensity. Changes the brightness of the LED pattern on the mico

     

    Where did you read about reading the light intensity ?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube