Introduction: Using 9 Axes Motion Shield With Arduino

Picture of Using 9 Axes Motion Shield With Arduino

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

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:

  1. Quaternion
  2. Euler angles
  3. Rotation vector
  4. Linear acceleration
  5. 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.

Step 1: Things in the Project

Hardware components:

  1. Arduino UNO & Genuino UNO × 1
  2. Arduino 9 Axes Motion Shield × 1

Software apps and online services:

  1. Arduino IDE

Step 2: Accelerometer Using 9 AXES MOTION SHIELD

Picture of 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.

Step 3: Sketch for Accelerometer Using 9 AXES MOTION SHIELD

#include "NAxisMotion.h"

#include NAxisMotion mySensor;	//Object that for the sensor//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

About This Instructable

651views

5favorites

Bio: Doing Computer Science and Engineering in SRM University. Expert in making projects on Arduino platform.
More by chauhannaman98:Micro:bit Selfie RemoteSunflower - Arduino Solar TrackerHeart Rate Monitor on Thingspeak IoT Platform
Add instructable to: