This lesson requires multiple microbits, each of with power sources/battery packs. There will also be two roles for the microbit’s that we use, the sender and the receiver.
The Sender: The sender is the device that will be physically attached to a tree, and will send a message saying that it has fallen and specifying the coordinates where it is located. The sender will have to use the accelerometer to detect if the microbit (and the tree it is attached to) is in free fall, and it will also use the microbit’s radio functionality to warn the authorities that it has fallen.
The Receiver: The receiver in our case acts as the authorities, it will use its radio to receive the messages from the microbits attached to the falling trees.
What circumstances may we wish to know if a tree has fallen?
First of all we will need to make 4 variables.
“Longitude”
“Latitude”
“Message”
“completeMessage”
Place the set [variableName] to blocks within on start like this:
In both the longitude and latitude “set” blocks place the pick random (from the purple Math category), in both of them. Set the longitude random numbers to be between -180 and 180, and for latitude set them to pick between -90 and 90.
Next we need to go to Advanced -> Text and pick out the rounded (“ “) block, and place that within our “set [Message] to ( )” block. Type in an appropriate short message.
Next we will need to the “join ( ) ( ) (-) (+)” block also from Advanced -> Text. Place that in the “set [completeMessage] to ( )” block, and tap the small plus icon on the far right of the block to create an extra rounded space.
Then fill all 3 of the rounded spaces with the 3 other variables.
Finally we will need from Input, the “on [shake]” block, change the “on [shake]” to be “on free fall”.
Inside the on free fall block, put in from Radio the “radio send string ( )” block. Then place the rounded completeMessage variable block from it into the “radio send string” block.
Finally we will need to specify what channel/group our microbits will transmit on. Do this by dragging out the “radio set group” and place it inside the “on start” section of code. Change the number to whatever suits, BUT REMEMBER IT. We will need to use the same number for our receiving microbits code.
When you are done, send this code to all the microbits you want to act as your tree felling detectors.
Next for the code for the receiver:
We will need the set radio group block inside on start, and set this to the same number as your senders.
Next from radio, drag out the “on radio recieved (recievedString)” block.
Inside of which, from basic pull out the show string block and place it inside of it.
Next drag your finger from the (recivedString) section of the “on radio recieved (recievedString)” and drag the block that is created and place it inside the “show string ( )” block.