micro:bit Workshop Level 2

  • micro:bit Built-in Sensors
  • Applications with Built-in Sensors

What are the built-in sensors?

MakeCode Block Temperature

Thermometer

Returns a number representing the temperature of CPU, measured in degree Celcius.

Thermometer at Work

Putting heavy workload on micro:bit may result in large difference between the CPU and the ambient.

MakeCode Example Temperature
MakeCode Block Compass Heading

Compass

Senses the direction the micro:bit is facing.

Compass at Work

  1. When compass is ready:
    • Returns a number between 0~360, measured in degrees.
    • Number 0 representing North.
  2. When compass is not ready:
    • Returns the number -1003.
  3. Calibration available as block "calibrate compass."
  4. Calibration should be performed away from metals.
MakeCode Example Compass Heading
MakeCode Block Acceleration

Accelerometer

Measure acceleration as a scale from -1023 (backward direction) to 1023 (forward direction).

Accelerometer at Work

Acceleration data can be used to implement the shake event.

MakeCode Example Acceleration
MakeCode Block Light Level

Light Meter

Measure light level as a scale from 0 (dark) to 255 (bright).

Light Meter at Work

  1. First time using "light level":
    • Returns "" (empty response).
    • Activates the light sensing feature.
  2. After that:
    • Returns a number between 0~255.
MakeCode Example Light Level
MakeCode Block Magnetic Force

Magnetometer

Measure magnetic force in a specific direction in microteslas.

Magnetometer at Work

The stronger the magnetic force, the brighter the LED.

MakeCode Example Magnetic Force

See you in micro:bit Workshop Level 3 ...

  • micro:bit Radio Transimission
  • micro:bit and External Modules (Part 1)
  • micro:bit MakeCode Packages