The "3-Axis-Acceleration" module on the Grove Beginner Kit can be used to determine:
tilt/orientation:
A smartphone uses this type of sensor to switch from portrait to landscape mode display when you rotate the phone, for example.
motion:
steps, free-fall, crashes, taps, drops, etc.
A fitness watch use this type of sensor to measures steps and other activity.
The module uses the STMicroelectronics LIS3DH 3-axis MEMS accelerometer.
MEMS = Micro Electromechanical System, a nano-scale combination of mechanical moving parts and electronics.
This accelerometer senses the gravitational force of the earth in the x, y, and z axis.
Build this sketch ➡
Or, you can download Accelerometer.cdc and open it on your computer.
You can find the "3 Axis Digital Accelerometer-M" block in the "Grove Digital" menu
Upload the sketch
Click the Connect button and select the device for your Grove Board (same as you use to Upload)
Click the Serial Monitor button
On the lower right of the Serial Monitor window, change the Baud rate to 19200.
You should see text like:
printf(0.01,0.19,0.98,null,null)
printf(0.01,0.00,1.00,null,null)
printf(0.01,-0.01,1.00,null,null)
...
Click the Serial Plotter button
Assuming that your kit is on a level surface, note that the x acceleration value is around 1, while x and y are zero.
This means that the z axis is experiencing 1 G of force.
Turn the board upside down and notice that the z value goes to -1.
Tilt the board slowly to the left and right and notice that the y value moves between -1 and 1. It is 0 when the board is vertical.
Keeping the board level on the table, rotate it around the vertical (z) axis. Are the x, y, z values changing? Why or why not?
Tap or shake the board and notice the x, y, and z values.
Coding challenges for you:
Create a sketch that lets you know if a surface is level. (Like a bubble level tool.)
Use the OLED, buzzer, or LED to provide user feedback
Consider displaying a character on the OLED display such as * to indicate the tilt position (left, center, right, etc.)
Here's an example you can download and open: Accelerometer_tilt_display.cdc,
but you can do something more interesting!
When acceleration is detected, make a sound with the buzzer.
Different sounds for acceleration in each axis (x, y, z)
Calculate the tilt angle and display it on the OLED.
Refer to Using An Accelerometer for Inclination Sensing
You'll need to use the inverse sin() function.
The Codecraft "Operators" menu has a math function block - the default operation is abs(), but you can select trigonometry functions, including the asin(), which is the inverse sin(), arcsine(), etc -- different notations for the same function.
Codecraft bug: asin() does not compile. 😞
your ideas?
Velocity & Acceleration
Want to sense rotation?
You need a gyroscope.
There are modules available that include an accelerometer and gyroscope.
Example:
Grove - 6-Axis Accelerometer&Gyroscope
Want to sense orientation to the earth's magnetic field?
You need a magnetometer/electronic compass.
An IMU ("Inertial Measurement Unit") includes an accelerometer, gyroscope, and magnetometer.
Example:
Grove - IMU 9DOF
(connects to the Grove connectors on your Kit with a cable, but not supported by Codecraft. Need to use the Arduino IDE.)