Introduction to Programming

Week 1: Light sensor - Intermediate

FundamentalBefore you start doing the classwork

Click on this link

Click on Get Started

Click on I'm Student

Select Sign in with Google

You will have your account display here (this is my account that is why it shows my name).

Select your account and enter your username and password for your Google accounts.

What is it?

Turn the LED display into a sensor to make your micro:bit react to light.

ExtraVideo explaining the task

ReminderOpen the Microbit editor

You will need to visit this website to the work: Microbit Makecode

Once you are there, click on New Project.

You have done this already many times !!

MethodHow it works

  1. As well as working as an output, the LEDs on your micro:bit can also work as an input device light sensor, measuring the amount of light falling on them.

  2. This means that micro:bit programs can make different things happen depending on how light or dark it is.

  3. The program uses an ‘if... else' statement to show the sun image only if the light level is greater than (>) a certain level. This is known as selection – selecting when different things happen.

  4. Flash this program onto your micro:bit and shine a light source, like a torch, daylight or bright ceiling light on to the micro:bit, and you should see the sun appear.

  5. Cover the micro:bit with your hand and the sun icon should vanish.

  6. If it doesn't work, try making the 100 number smaller to suit the lighting where you are.

  7. You can read more background information about how the micro:bit light sensor works here.

ExampleCode

WarningTask 1. Improve it

  1. Show a different picture, like a moon or star, when it's dark.

  2. Show an animated sun when light falls on your micro:bit.

  3. Turn this project into a night-light by making it light up the micro:bit's display when it goes dark.

ReminderUpload your work on your google classroom

Watch these two videos to remind you on how to do this.

PreviousPreviousNextNext
HomepageHomepagePrintPrintCreated with Scenari (new window)