Setup and procedure
Setup
- Plan and design the experiments.
- Plan and design data collection documents.
- Program the micro:bits.
- Experiment with different data collections scenarios.
Code
This project will use to micro:bits to collect and record data using MakeCode as described in Data Collection - Option 3.
Sender micro:bit code
- Code the first micro:bit using MakeCode for Microbits.
- Name the project, “Gravity Sender”.
- The
||basic:on start||
event will display the title and function of the micro:bit in all caps,"GRAVITY SENDER"
. - 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
- 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. - Open the pull down menu in the acceleration block and and change the
x
value to thestrength
value. This maximizes the x, y, and z dimensions of the acceleration into 1 value. - 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
- Using MakeCode setup and code the second micro:bit.
- This micro:bit will remain connected to the computer through the USB cable and MakeCode to monitor the data being received.
- Name the project, “Gravity Receiver”.
- The
||basic:on start||
event will display the title and function of the micro:bit in all caps,"GRAVITY RECEIVER"
. - 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
- The
||radio:on received number||
event will constantly monitor radio signals from the radio group. - When a value is received from the group it is stored in the
gravity
variable. - The
||serial:serial write Value||
sends 2 pieces of data back to MakeCode 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. - Add a
||led:toggle||
to indicate that it’s receiving data. Changex
to1
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
- With the micro:bit code downloaded from MakeCode to the micro:bit and the USB cable connected it will start receiving data from the first micro:bit.
Under the simulator in MakeCode a purple outlined button shows up “Show data Device”.
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).
The Download button in the red highlighted box allows the downloading of about the last 20 seconds of recorded data as a CSV file.
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).
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 MakeCode. 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 MakeCode. 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.
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 MakeCode. 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.
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.
NEXT: Resources
Adapted from “Gravity, Motion, and Waves“ by C Lyman
radio