We will use the accelerometer to determine the hand position. For a good overview of the basics of how an accelerometer works, check out the How Tall Is It? guide. You can also read some technical details in the Lesson #0 Guide.

With the Circuit Playground sewn on the bike glove as in the previous section, the three main axis line up as shown in the image below.

The coordinate system for the accelerometer on the Circuit Playground Express is slightly different - it's rotated 90 degrees clockwise, we'll account for it in our code later!

Let's start by looking at the accelerometer output in the various hand positions. You can use the simple sketch below which will send the three accelerometer values to the serial port.

```#include <Adafruit_CircuitPlayground.h>

float X, Y, Z;

void setup() {
Serial.begin(9600);
CircuitPlayground.begin();
}

void loop() {
X = CircuitPlayground.motionX();
Y = CircuitPlayground.motionY();
Z = CircuitPlayground.motionZ();

Serial.print(X);
Serial.print(",");
Serial.print(Y);
Serial.print(",");
Serial.println(Z);

delay(100);
}```

With this sketch loaded and running on the Circuit Playground, open the Serial Plotter:

Tools -> Serial Plotter

You should see three lines being drawn, one for each axis of the accelerometer. Now move the glove into the three main positions:

• HAND DOWN (on bike grip)
• RIGHT TURN
• LEFT TURN

Note how in each position there is one reading that stands out. For the hand down position it is the Z axis as reported by `motionZ()`. For the right turn position it is the X axis as reported by `motionX()`. For the left turn position it is the Y axis as reported by `motionY()`. So we can see a strong correlation between the hand positions of interest and the main axis of the accelerometer as:

• HAND DOWN  --> `motionZ()`
• RIGHT TURN --> `motionX()`
• LEFT TURN --> `motionY()`

So by simply checking the values of the various accelerometer readings, we can determine hand position. Let's see how next.

This guide was first published on Jun 05, 2017. It was last updated on Jun 05, 2017.

This page (Hand Position and Accelerometer) was last updated on Nov 23, 2021.