Skip to content
Learnearn.uk » Microbit Unit Home » Microbit Analogue Inputs

Microbit Analogue Inputs

Microbit Analogue Inputs

In the previous topic we looked at digital inputs ( any inputs that have have only 2 states on/off – buttons / shake input). In this topic we have look at analogue inputs – any inputs /sensors that can have a range of values.

The Microbit has a number of in-built analogue sensors, such as:

  • Compass
  • Temperature sensor
  • Light sensor
  • Tilt sensor

Different sensors return different value ranges.

 

Compass Bearing Sensor

  • The compass bearing sensor detects which direction the Microbit is facing and returns the angle in degrees.
  • Returns a value between 0 and 360

Temperature Sensor

  • The temperature sensor detects what the current temperature is in degrees Centigrade.
  • Return an integer (whole number)

 

Tilt Sensor

  • Detects the tilt angle for the microbit on either the X axis(left / right) or Y Axis (forward/backwards)
  • Return a positive or negative integer (whole number)

Forward / Backward Tilt

Left / Right Tilt

Light Level Sensor

  • The light level sensor detects how much light the Microbit is being exposed to
  • Returns a positive integer between 0 and 255.

Challenge 1 – What’s the temperature?

Create a script that every time you press the A button, it tells you the temperature.

Bronze

  • The program displays the temperature

Silver

  • The program says ‘The temperature is 30 C”

Gold

  • If the temperature is greater than 30 degrees it then displays a sunny symbol
  • If the temperature is less than 20 degrees it displays a snowman.

Hint Blocks

Challenge 2 – Tilting Microbit

Bronze

When the A+B buttons are press the microbit should:

  • display the left/right tilt.
  • wait 2 seconds
  • Display the forward/backward tilt

Silver

The microbit should finally say

‘I’m tilting Forward & Right’ (or whatever way it is tilting)

Gold

Get the Microbit to display a dot on the screen that indicates which direction the Microbit is tilting left / right / forward / back.

Gold Hint blocks

Challenge 3 – Microbit Compass

Bronze

Get the Microbit to say the bearing.

Silver

If the Microbit is facing exactly north / east / south / west it should display N E S W instead.

Gold

The Microbit should always display a letter bearing, even if the bearing is not exact. E.g.  if the bearing

The code below will probably help you out!

Challenge 4 – Microlight!

Bronze

Whenever you shake the microbit:

Get your program to tell you the light level

Silver

If the light level is below half, your program should turn on all the LEDs for 10 seconds.

Gold

Your program should keep repeating the above code until the B button is pressed and then the microbit shut stop checking the light level.