📊 micro:bit Data and Climate Change
  • Introduction
  • Data
  • Climate Change
  • Our Tools
    • 01- micro:bit
    • 02 - MakeCode
      • A - Events
      • B - Animations
      • C - Counting
      • D - If Hot
    • 03 - Servo Motor
      • Coding your first servo motor on MakeCode
    • 04 - Neopixel
      • Coding your first neopixel on MakeCode
  • Activities
    • Tools and Data Together
      • 01 - micro:bit and Data
      • 02 - Servo Motor and Data
      • 03 - Neopixel and Data
  • Showcase Projects
    • 01 - Air Pollution
      • A - Servo Motor
      • B - Neopixel Grid
    • 02 - Green Energy Forecast
    • 03 - Temperature Change
      • A - Neopixel Grid
      • B - Neopixel Ring
    • 04 - Heavy Precipitation Days
      • A - Neopixel Grid
      • B -Servo Motor
      • C-Neopixel Fairy Lights
    • 05 - Greenhouse Gas Emission
      • A - Neopixel Grid
      • B - Neopixel Fairy Lights
  • 🚀Extra Missions
  • Support Material
    • Data on the Run
    • Data Visualization Examples
    • Data Science of Climate Change by Lucie Luneau
    • Ideas from the Canadian Space Agency - CSA
    • CASC + Science Spotlight
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Activities
  2. Tools and Data Together

02 - Servo Motor and Data

Previous01 - micro:bit and DataNext03 - Neopixel and Data

Last updated 2 years ago

Was this helpful?

In the previous activity, we saw how can we manually collect and display data using the micro:bit. In this section, we will introduce two new different concepts:

  • Collect data continuously and automatically.

  • Display the data results using the Servo Motor.

The code for the activity is quite simple but useful and informative. We will create a thermometer and using the same code, a light meter!

Requirements

Use the micro:bit to continuously read the current temperature and point the servo motor arm accordingly. The micro:bit temperature sensor can read temperatures from -40 C° to 105 C°. Represent that temperature range with the servo motor.

Data Collection The data will be collected as soon as and for as long as the micro:bit is powered.

Data Visualization

The servo motor will move its arm to a point representing the current temperature.

Display it!

Cut and draw different temperatures on a piece of cardboard for the servo motor to point to.

Follow the same instructions as above, but instead of reading temperature, create a light-reading device

Read the requirements and try to code the activity. Once you are done or you give it your best, take a look at the way we solved it, below.

Set Up the Servo Motor

Add the servo motor extension following the steps from our previous section, Coding your first servo motor on MakeCode

Once you have the Servos set of blocks on MakeCode, set up the servo to have a range from 0° to 180° and listen to instructions provided by the micro:bit from Pin 0 (P0).

Nothing to test at this point.

Forever Read and Display the Current Temperature

As we want to continuously read and display the temperature, we will use the forever block. In it, we need to add a block that moves the servo as the temperature changes.

As you test with the emulator, you'll see that the servo arm moves very little, as you change the temperature.

We want to use the full range of motion that the servo has (180°) to express the current temperature. To do so we need to find a way to convert our desired temperature range (-20 C to 40 C° *) to be equivalent to the servo motor arm range (0° to 180°). We can do this by replacing the temperature block above with the code below.

* See the Teacher's Corners below to explore more about temperature ranges and mapping

Now the changes in temperature are easier to see as the servo motor uses the whole 180° of motion.

Light Level

The instructions for the light level sensor are the same as per the thermometer, with some exceptions:

  • We use the light level sensor on the micro:bit instead of the temperature sensor.

  • The range of light sensitivity that the micro:bit reads ranges from 0 to 255.

The code for the full light application is as follows:

In the next section, we are utilizing the sensors on the micro: bit to collect data and display it using a Neopixel grid. See you at Neopixel and Data.

Thermometer

Light level

You can see our solved version

Teacher's Corner - Temperature range

The temperature range you choose depends on when and where you plan on using the thermometer.

Consider the following scenarios and think about what temperature range would you need:

  1. In Halifax.

  2. Where you live.

  3. In the Sahara

  4. North Pole

  5. At different times of the year:

    1. In the summer?

    2. In the winter?

    3. Year-round?

As you can see there is a lot to consider, but each decision will help you create the right thermometer for each situation.

Teacher's Corner - map function

The map function in MakeCode takes two ranges of numbers, in this case, the temperature range we want to display (-20°C to 40°C) and adjusts it to the range of the servo-motor (0° to 180°).

Since we have a range of 60°C for temperature and 180° degrees for the servo-motor what the map function is doing is using a proportion. For example, if you want to find the angle for 20°C you would do the following calculation:

Temperature = 20°C
servo motor angle = x
degrees above -20°C = 20°C - (-20°C) = 40°C

Proportion:
x/180° = 40°C/60°C
x/180° = 2/3
x = 180°(2)/3
x = 120°
​

Teacher's Corner - Expaning on the learned concepts

To help reinforce the concepts learned, invite the students to share with the class their thought processes after completing the activity. The class can explore concepts such as:

  • What did you visualize?

  • Why did you choose to visualize that data?

  • What were your Data/Inputs?

  • Did you have to manipulate the data to match the constraints of the servo motor? For example, did you have to translate, calculate or change the input data to match the range of motion of the servo motor

  • What reaction or interpretation do you expect from your work?

🌡️
💡
🍎
🍎
🍎
here
micro:bit with servo motor