Hand Position Detection

The basic idea for detecting hand position is to check if the accelerometer values of each of the three axis exceed a preset level. This level is called a threshold. We will use three separate threshold values for the three separate axis values. This idea is shown in the image below.

Note that for the left turn, the value is negative.

Here is a program to demonstrates this. The threshold checks are done using if statements. Note that the if statements for the left turn/right turn checks are nested within the if statement for the hand down check. This is because the only time it makes sense to check for left/right is if the hand is up. We don't want the turn signal lights to go off while the hand is down on the handle bars.

Download: file
///////////////////////////////////////////////////////////////////////////////
// Circuit Playground Bike Glove - Hand Position Detection
//
// Author: Carter Nelson
// MIT License (https://opensource.org/licenses/MIT)

#include <Adafruit_CircuitPlayground.h>

#define THRESHOLD_UP        5   // threshold for hand up test
#define THRESHOLD_RIGHT     5   // threshold for right turn
#define THRESHOLD_LEFT     -5   // threshold for left turn

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

///////////////////////////////////////////////////////////////////////////////
void loop() {
  // check for hand up or down
  if (CircuitPlayground.motionZ() > THRESHOLD_UP) {

    Serial.println("HAND DOWN");
    
  } else {
  
    // check for right turn
    if (CircuitPlayground.motionX() > THRESHOLD_RIGHT) {
      Serial.println("RIGHT TURN");
  
    // check for left turn
    } else if (CircuitPlayground.motionY() < THRESHOLD_LEFT) {
      Serial.println("LEFT TURN");       
  
    }
  } 

  delay(500);
}

With this sketch loaded and running on the Circuit Playground, open up the Serial Monitor.

Tools -> Serial Monitor

You should see the current hand position printed out twice a second.

Try moving to the various hand positions and see how they are printed out as shown below.

Pretty simple, but it works.

This guide was first published on Jun 05, 2017. It was last updated on Jun 05, 2017. This page (Hand Position Detection) was last updated on Dec 02, 2019.