Setup and procedure

Setup

  1. Plan and design the experiments.
  2. Plan and design data collection documents.
  3. Program the micro:bits.
  4. Experiment with different data collections scenarios.

Code

This project will use to micro:bits to collect and record data using the Windows 10 MakeCode app as described in Data Collection - Option 3.

Sender micro:bit code

  1. Code the first micro:bit using MakeCode for Microbits.
  2. Name the project, “Gravity Sender”.
  3. The ||basic:on start|| event will display the title and function of the micro:bit in all caps, "GRAVITY SENDER".
  4. Set up a radio group using the “radio set group”. Both micro:bits need the same radio group.
basic.showString("GRAVITY SENDER")
radio.setGroup(99)

Send the data

  1. The ||basic:forever|| event will constantly monitor the “strength” of the acceleration and send the value to any other micro:bits that might be receiving radio signals in the same radio group.
  2. Open the pull down menu in the acceleration block and and change the x value to the strength value. This maximizes the x, y, and z dimensions of the acceleration into 1 value.
  3. Add a ||led:toggle|| block to indicate that data is being sent.
basic.showString("GRAVITY SENDER")
radio.setGroup(99)
basic.forever(() => {
    radio.sendNumber(input.acceleration(Dimension.Strength))
    led.toggle(0, 0)
})

Receiver micro:bit code

  1. Using the Windows 10 MakeCode app setup and code the second micro:bit.
  2. This micro:bit will remain connected to the computer through the USB cable and the Windows 10 MakeCode app to monitor the data being received.
  3. Name the project, “Gravity Receiver”.
  4. The ||basic:on start|| event will display the title and function of the micro:bit in all caps, "GRAVITY RECEIVER".
  5. Set up a radio group using the ||radio:radio set group||. Both micro:bits need the same radio group.
basic.showString("GRAVITY RECEIVER")
radio.setGroup(99)

Code the receive event

  1. The ||radio:on received number|| event will constantly monitor radio signals from the radio group.
  2. When a value is received from the group it is stored in the gravity variable.
  3. The ||serial:serial write Value|| sends 2 pieces of data back to the MakeCode app through the USB cable. First it sends a label "gravity" and then the value received as gravity from the acceleration method from the first micro:bit.
  4. Add a ||led:toggle|| to indicate that it’s receiving data. Change x to 1 so that another LED blinks.
basic.showString("GRAVITY RECEIVER")
radio.setGroup(99)
radio.onReceivedNumber(function (receivedNumber) {
    serial.writeValue("gravity", receivedNumber)
    led.toggle(1, 0)
})

Monitoring the data

  1. With the micro:bit code downloaded from the MakeCode app to the micro:bit and the USB cable connected it will start receiving data from the first micro:bit.
  2. Under the simulator in the app a purple outlined button shows up “Show data Device”.

  3. By clicking on the Show data Device button a window opens up to the right showing values and graph of the gravity data being received (the dips in the graph are 3 tosses of the micro:bit in the air).

  4. The Download button in the red highlighted box allows the downloading of about the last 20 seconds of recorded data as a CSV file.

Toss sensor data

When the data recorded is downloaded as a CSV spreadsheet file. It is named data.csv (it will usually open in a spreadsheet but sometimes doesn’t and it can be hard to find. A search of the C:\ drive might be necessary to find it).

Toss sensor data

Additional analysis and graphing can be done in a spreadsheet.

Data Collection

There are several ways to collect data from an experiment. The simplest is having the data display on the LED screen and manually record the data on a paper. Data can also be collected using the Window’s 10 MakeCode app. The third way is using 2 micro:bits with one observing the data and then radioing the results to a second micro:bit can allow the remote collection of data.

For additional information on data collection, see the Data Collection lesson.

Extensions

Sound Wave Sensor

Sound causes vibrations which can be detected with the Microbit accelerator. Connect 2 micro:bits using radio signals (see Data Collection - Option 3). The “Gravity Sender” micro:bit can be placed on or near a speaker. It will send a signal to the “Gravity Receiver” micro:bit which can be connected to the Windows 10 MakeCode app. When the “Gravity Receiver” micro:bit receives a gravity number it is sent to the monitoring data collection using the method serial.writeValue("gravity", gravity). The sound can be observed in the Show data Device.

Sound vibrations

Earthquake Detector

Earthquakes cause vibrations which can be detected with the Microbit accelerator. By placing the “Gravity Sender” micro:bit on a flat surface and having it “feel” minor changes in acceleration it can detect earthquakes or other vibrations in the earth. Connect 2 micro:bits using radio signals (see Data Collection - Option 3). The “Gravity Sender” micro:bit can be placed on or near a speaker. It will send a signal to the “Gravity Receiver” micro:bit which can be connected to the Windows 10 MakeCode app. When the “Gravity Receiver” micro:bit receives a gravity number it is sent to the monitoring data collection using the method serial.writeValue("gravity", gravity). The movement of the object connected to the Earth can be observed in the Show data Device. Using a conditional statement that detects changes in the received gravity could be implemented to play “music” sound as an alarm when changes in movement are detected.

Earthquake vibrations

Skate Park Data or Pinewood Derby.

Use the micro:bits to record data from a skater at a skate park or acceleration down a ramp like a Pinewood Derby car.


Adapted from “Gravity, Motion, and Waves“ by C Lyman CC BY-NC-SA
radio