This Lesson is all about detecting changes in water level height, how that relates to Tsunamis and Flooding events, and most importantly how to use our micro-bits and code to detect these events.
Flooding generally occurs when incredibly heavy rain occurs, or say an accident occurs at a dam such as a breach and the water flows out, or in some cases a river may overflow. In 2010, Victoria received extreme flooding, with rainfall up to 180mm, this flooding caused millions of dollars in damage and loss of over 250 homes.
Tsunamis are triggered by earthquakes or volcanic eruptions beneath the ocean floor. These sudden jolts of earth shift the water and create waves of initially incredible length, without much height. But as this wave travels closer to shallower water, the waves’ length becomes shorter and the height taller. Before reaching the shore, the wave will draw back the water in-front of it to increase the height of the wave to maintain its enormous energy before finally collapsing on whatever may be in-front of it.
This drawing back of the water is what we will be detecting today.
To detect changes of water height on our floating platform we can make use of the micro-bits in-built accelerometer.
Our microbit measures movement (or acceleration) using the unit of milli-g-force (mg), so if our microbit was free-falling towards the earth, it would detect 1000mg of acceleration.
Our micro-bit can detect not only at which speed it is travelling, but also the direction. It can detect motion in 3 directions.
If our microbit was laying flat with the LED’s facing up:
This pink acceleration block is located under input on our make-code for micro:bit platform.
When the micro:bit is laying flat with the LED’s facing up. The Acceleration values that the micro:bit will show read as:
That Z as -1023 is very strange for it being stationary, think of it as the micro-bit is being pulled towards the ground in a “negative” direction.
Values LOWER than -1023 will indicate that the micro:bit is falling on the Z axis, values ABOVE -1023 will indicate that the micro:bit is rising on the Z axis.
In the event of a flood, our floating platform that our micro:bit is set on will begin to rise with the water level.
We will need to check continuously if there is a change in the Z-axis for our micro:bit experiencing a change in height. To do this we will use the Forever loop and one of our conditional IF-THEN blocks. Our Forever loop is located in basic, and our Conditional IF-then block is located in Logic.
Note how in our if block we have the comparison “>” GREATER THAN block, also located in Logic. We compare our Z-axis acceleration value with -500 (A number GREATER THAN -1023, so we know our micro:bit is rising).
Then inside the IF-THEN block we can choose do to any number of things to show to us that the micro:bit has risen. For now we will use the LED’s displaying an arrow up.
For detecting a tsunami, or rather the sudden drop in water height before one occurs, a simple modification of the code can be made.
Here you can see that we have changed the GREATER THAN sign to a LESS THAN sign, and are now comparing it to -1500 (Which is LESS THAN -1023), so if our micro:bit is decreasing in height, a down arrow will be displayed on screen.
Put the code onto your micro:bit and see how it runs. How do I put code onto micro:bit?
How may we make this system more sensitive to changes in height? If we change the values of -500 and -1500 to values closer to -1023 (Say -700 and -1300 respectively) the micro:bit will detect smaller changes in speed.
What values would make our micro:bit LESS sensitive?
THINK: Which ones are further from -1023. (Just because the numbers are “longer” doesn’t mean they are larger, we are looking for bigger distance from -1023).
Answer:
For more information about micro:bit acceleration click here.