Mobile devices know where they are and, importantly, which way that they are facing. They include sensors such as accelerometer (DeviceMotion) and magnetometer (Compass - DeviceOrientation) which offer data for the reading with just a little JavaScript prompting!
This opens up wonderful classroom opportunities for student learning and deeper understanding of key concepts like acceleration and geomagnetism. In later lessons we will learn about the powerful possibilities of using Bluetooth Low Energy (BLE) devices to bring our STEM lessons to life, but first it is important to see that the simplest solution probably lies in the phone carried by every student.
Note that older laptop computers also used motion sensors to help to protect their spinning disc drives, but with the advent of solid state drives, this is no longer a priority. In general these days you will need to use mobile devices to access the features described here.
For more detailed background on this interesting and powerful feature, refer to the links above from both Google and Mozilla, who are both very active players in this new field of progressive web apps.
If you have any questions or would like to share your experience with this utility, please drop me an email!
The accelerometer is clearly a sensor associated with motion, but for mobile devices, it also offers a very simple and effective way to determine orientation or, more simply, which way is up!
While you might think that a motionless accelerometer would read 0 on all three axes, if gravity is taken into account then one of these axes should register a downwards force of 9.8 metres per second per second, and this can tell the user which way is down!
The GitHub code used here uses the y axis but, depending how you carry your mobile device when walking, this may not always be the optimal orientation. Study the calculation used to determine whether a step has occurred - when yg-10*Math.sin(event.beta*Math.PI/180) > 1 or < -1. Think about why this is used.
You can use the second button (Step Counter with Accelerometer) to investigate this.
Now we put together all those lovely sensors - orientation and motion - even our compass. This time, we use the stemjs.js JavaScript page to make ourlife easier.
The button below displays the scripts which are used in my examples for reading these sensors - take a few moments to browse through these.
The first function defined (switchSensors) is just a utility function which defines a variable (internalSensors) used to denote whether the internal sensors are read and displayed.
Subsequent functions are defined in terms of window events (window.addEventListener) which listen for results from these various sensors and deliver the readings as requested.
Once again, our wonderful GeoGebra applet proves to be the perfect complement to these features - the readings from internal sensors are readily brought to life using sliders created in a GeoGebra document.
Study the individual sensor scripts as shown in the previous examples, and then see how these occur within the stemjs.js page.
As we have seen previously, GeoGebra offers wonderful assessment opportunities in combination with some simple JavaScript to direct the learning experience. Questions, hints and feedback are just a button tap away!
If you have really been paying attention, you might have noticed that the final scripting link for this page referred to a sensortag.js JavaScript page. While it was designed initially to complement TI SensorTag functionality, it turns out to work equally well with our internal device sensor readings.
While there is a lot to take in from this extensive script, you might focus in particular upon the readData function which not only collects the data points as they are produced, but stores these into lists. These lists are stored in the GeoGebra spreadsheet, and plotted in different colours! Finally, the GeoGebra graphing window is adjusted to fit the list values as they unfold.