Using 9 Axes Motion Shield with Arduino

Using 9 Axes Motion Shield with Arduino © GPL3+

The Arduino 9 Axes Motion Shield allows your Arduino to measure movement: orientation, acceleration and magnetic field.

  • 5,977 views
  • 3 comments
  • 19 respects

Components and supplies

Apps and online services

About this project

The Arduino 9 Axes Motion Shield is based on the BNO055 absolute orientation se nsor from Bosch Sensortec GmbH which integrates a triaxial 14-bit accelerometer, a triaxial 16-bit gyroscope with a range of ±2000 degrees per second and a triaxial geomagnetic sensor with a 32-bit microcontroller running the BSX3.0 FusionLib software.

You can get it from Rhydolabz.com for the lowest price. You can even tell them if you get a better price somewhere, they make it less!

The sensor features three-dimensional acceleration, yaw rate and magnetic field strength data each in 3 perpendicular axes.

It also provides the sensor fusion signals such as:

  • Quaternion
  • Euler angles
  • Rotation vector
  • Linear acceleration
  • Gravity vector

In addition, it incorporates an intelligent interrupt engine, which allows for triggering interrupts based on:

  • slow or no motion recognition
  • any motion (slope) detection
  • high-g-detection.

Accelerometer using 9 AXES MOTION SHIELD

This shield contains: Accelerometer, Gyroscope and Magnetometer. The Library provided allows you to easily setup and use its sensors. The following tutorial is a little game made to demonstrate the Any motion and No motion Interrupt features of the shield.

Hookup

Simply attach the 9 Axes Motion Shield to your Arduino Board, being careful to match all PINs. You are ready to go!

Sketch

The code starts by doing the Shield setup and creating a Serial connection. Interrupt setups are also done in this function. The setup functions are commented inside the code. The loop function updates over and over Accelerometer datas and it prints them to the Serial Monitor.

You can use it in several projects like the one which require you to keep a track on the orientation of a robot or machine, etc.

Code

Accelerometer using 9 AXES MOTION SHIELDC/C++
#include "NAxisMotion.h"
#include <Wire.h>
 
//Object that for the sensor
NAxisMotion mySensor;
 
//Flag to indicate if an interrupt was detected
bool intDetected = false;
 
//At a Range of 4g, the threshold
//is set at 39.05mg or 0.3830m/s2.
//This Range is the default for NDOF Mode
int threshold = 5;
 
//At a filter Bandwidth of 62.5Hz,
//the duration is 8ms.
//This Bandwidth is the default for NDOF Mode
int duration = 1;
 
//To know which interrupt was triggered
bool anyMotion = true;
 
//This code is executed once
void setup() {
  //Peripheral Initialization
 
  //Initialize the Serial Port to view information on the Serial Monitor
  Serial.begin(115200);
 
  //Initialize I2C communication to the let the library communicate with the sensor.
  I2C.begin();
 
  //Sensor Initialization
  Serial.println("Please wait. Initialization in process.");
 
  //The I2C Address can be changed here inside this function in the library
  mySensor.initSensor();
  mySensor.setOperationMode(OPERATION_MODE_NDOF);
 
  //Can be configured to other operation modes as desired
  mySensor.setUpdateMode(MANUAL);
  //The default is AUTO. Changing to manual requires
  //calling the relevant update functions prior to calling the read functions
 
  //Setting to MANUAL  requires lesser reads to the sensor
 
  //Attach the interrupt to the Interrupt Service Routine
  //for a Rising Edge. Change the interrupt pin depending on the board
  attachInterrupt(INT_PIN, motionISR, RISING);
 
  //Setup the initial interrupt to trigger at No Motion
  mySensor.resetInterrupt();
  mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION);
  anyMotion = false;
 
  //Accelerometer interrupts can be triggered from all 3 axes
  mySensor.accelInterrupts(ENABLE, ENABLE, ENABLE);
 
  Serial.println("This is a game to test how steady you can move an object with one hand. \n
                            Keep the device on a table and mark 2 points.");
 
  Serial.println("Move the Device from one place to another
                            without triggering the Any Motion Interrupt.\n\n");
 
  delay(1000); //Delay for the player(s) to read
  Serial.println("Move the device around and then place it at one position.\n
                            Change the threshold and duration to increase the difficulty level.");
 
  Serial.println("Have fun!\n\n"); 
}
 
void loop() //This code is looped forever
{
  if (intDetected)
  {
    if (anyMotion)
    {
      Serial.println("You moved!! Try again. Keep the Device at one place.\n");
      intDetected = false;
      
      //Reset the interrupt line
      mySensor.resetInterrupt();
      
      //Disable the Any motion interrupt
      mySensor.disableAnyMotion();
      
      //Enable the No motion interrupt
      //(can also use the Slow motion instead)
      mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION);
      anyMotion = false;
    }
    else
    {
      Serial.println("Device is not moving. You may start again.\n\n\n");
      intDetected = false;
      
      //Reset the interrupt line
      mySensor.resetInterrupt();
      
      //Disable the Slow or No motion interrupt
      mySensor.disableSlowNoMotion();
      
      //Enable the Any motion interrupt
      mySensor.enableAnyMotion(threshold, duration);
      anyMotion = true;
    }
  }
}
 
//Interrupt Service Routine
//when the sensor triggers an Interrupt
void motionISR() {
  intDetected = true;
}

Comments

Similar projects you might like

DFRobot's 2.8" TFT Touch Shield for Arduino

by Techmirtz

  • 2,889 views
  • 1 comment
  • 22 respects

Arduino Motion Controlled Electronics!

Project tutorial by Arduino “having11” Guy

  • 3,788 views
  • 0 comments
  • 14 respects

OSEPP LCD and keypad shield

Project tutorial by Joe

  • 38,393 views
  • 26 comments
  • 48 respects

Motion Controlled Color Changer!

Project tutorial by Arduino “having11” Guy

  • 9,433 views
  • 17 comments
  • 14 respects

Motion Activated Night Light

Project tutorial by Haziq Afandi

  • 3,113 views
  • 0 comments
  • 4 respects
Add projectSign up / Login