📊 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

03 - Neopixel and Data

Previous02 - Servo Motor and DataNextShowcase Projects

Last updated 2 years ago

Was this helpful?

In this activity we are using a micro:bit to collect data from our environment, and visualize it using a neopixel matrix. Like the last challenges, it will be using the micro:bit sensors (temperature and light) to collect our data.

Besides using the neopixel matrix, we are using other two different concepts in this build:

  • We will manually trigger the data collection.

  • We are using a new concept in computer science called arrays to help us store the collected data.

Arrays are lists that hold information. These lists or containers can grow and shrink depending on the data they include.

In this project, we are visualizing different light levels within a specific environment. Think of collecting data at several points in your classroom and then displaying all the points on a grid.

Requirements

Collect and visualize light levels in a room.

Data Collection

Press the A button on the micro:bit to collect light levels in different places within the chosen room.

Data Visualization

Press the B button on the micro:bit to display the current data available on the neopixel matrix

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.

Setup the Array and Neopixel

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

Once you have the Neopixel set of blocks in MakeCode, set up the neopixel to start as soon as the micro:bit is powered (on start) and also intialize an empty array to hold the data.

Three things to keep in mind when working on this step:

  1. We are stating that the neopixel matrix has 64 LEDs, but you can change this number to represent the number of LEDs on your neopixel strip, ring or matrix.

  2. The array set of blocks is part of MakeCode, but it is housed under the Advanced tab at the bottom of the list.

  3. To create an empty array like the one on the image, click on the minus ('-') button to delete the pre-populated numbers, 0 and 1.

Collect data on Button A Pressed

In this step, we are writing code to check if we have not collected all the desired light data points, in our case, 64 and:

  • When we reach the 64 data points we get a dot on our micro:bit, to let us know that we have all the data we need.

  • If we have not reached our 64 light data points, it will keep adding them to our list (array).

Test on your emulator by pressing the A button until you see the dot light up on the micro:bit.

Display the Light Data on the Neopixel on Button B Pressed

At any point, we want to be able to visualize the light data we have collected on the neopixel. To do so, we are looping, meaning that we go over each piece of light data on the array, and use its value to power the corresponding LED on the neopixel.

Time to test collecting light data by pressing the A button and then pressing the B button to see the neopixel light up!

Clear the Neopixel, Array and Micro:bit

This step resets our light meter by emptying the array, turning off the lights on the neopixel and clearing the screen on the micro:bit.

Test your code!

We are now ready to tackle the Climate Change Activities in the next section.

You can see our solved version

Teacher's Corner - Arrays
  • An array is a list of items that are numbers, booleans, or strings. Arrays have a length which is the number of items they contain. You get and change the values of items at different places in an array. You find items in an array by knowing their positions.

Teacher's Corner - Loops
Teacher's Corner - Expaning on 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?

  • The neopixel gives you the option of visualizing by the number of lights, their intensity, colour or distribution. What strategy did you use?

  • What were your Data/Inputs?

  • Did you have to manipulate the data to match the constraints of the neopixel? For example, did you have to translate, calculate or mat the input data to match the number of LEDs on the neopixel?

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

Arrays are flexible, they can grow and shrink in size. You can add and remove items at any place in the array.

Learn more about arrays at

In computer science, a loop is a programming structure that repeats a sequence of instructions until a specific condition is met.

More information about Loops from

🍎
🍎
🍎
here
source
MDN
source
MakeCode
micro:bit with a neopixel
Diagram of 64 light points in a room