Earthquakes are caused by tectonic movements of the Earth’s crust. The tectonic plates on the surface of the Earth collide and scrape against one another and cause shock waves or vibrations.
To detect an earthquake we will once again use our accelerometer built into our micro:bits.
But for this task we are looking not for just the Z-axis movement, but the X/Y movement. We can do this in one of two ways. The easiest is using the input block that shows “On shake”
However, this on shake method can only detect very strong shakes of the micro bits, and generally earthquakes are a lot more discrete. If an earthquake was as powerful as the “on shake” detects, we would already know by the time it occurred!
So instead, similar to last time with the Water level rising, we will use the “Acceleration (mg)” block, but this time instead of measuring the Z axis, we will measure all directions at once, labeled as strength.
We can use this block to determine exactly how fast to the left/right/forward/backwards that our micro:bit moves. We will again use the Forever loop located in input, IF-THEN located in Logic, The GREATER THAN block located also in Logic. The show string is just a placeholder for something to occur.
But also this task we will be using our micro:bit’s radio feature. This short distance Radio will act as a simulation for the real long distance radio transmissions that are sent when an earthquake is detected anywhere around the globe from one of many detection stations.
To set up the Radio, we need to agree on a Radio group for all of our micro:bits to be on, so they can all speak to each other. We collect the “On Start” block from Basic, and the “Radio Set Group” block from Radio.
All of our micro:bits in this “detection network” must have the same radio group set like this.
There are two roles here. Right now we have coded most of the Sending role, which will be run by one of our two (or more) micro:bits.
To set this up, we can modify that prior code made to turn the Show string placeholder to a “radio send number” block from the Radio. We can lower the 300 to a smaller number to allow our sending micro:bit to be more sensitive.
For the micro:bit that receives the number from the sender we will have to do something a bit different. We will again use this code to set the radio group.
In addition to that, we will need code that receives the number that will be sent by the sending micro:bit.
We will collect the “on radio received” block from radio, the IF-THEN block from Logic, the GREATER THAN block from Logic as well, and the received number block will appear in Variables AFTER you drag out the “on radio received”.
YOU DO NOT NEED TO CREATE THIS VARIABLE.
To add more options for our receiving block to do you can simply add more if statements.
Code your project and apply it to your micro:bit. How do I put code onto micro:bit?