Accelerometer Using Arduino 101 © MIT

Learn how to read Accelerometer Sensor on Arduino 101 and show tilt status on LED.

  • 4,170 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

Introduction

Learn how to read Accelerometer Sensor on Arduino 101 and show tilt status on LED.

Arduino 101 is good for IOT starters. Having the Intel® Curie™ Module, designed to integrate the core's low power-consumption and high performance with the Arduino's ease-of-use, Bluetooth Low Energy capabilities and on-board 6-axis accelerometer/gyroscope, this board will provide exciting opportunities for building creative projects in the connected world.

More information about the technical specifications and documentation can be found on the Arduino/Genuino 101 main page.

Build Circuit

Lets build our circuit!

  • Connect Arduino 101 pin GND (ground) to one of the bread board pins. I picked the upper left pin.
  • Connect 3 resistor on the same column of the GND jumper wire
  • Add 3 LEDs each negative pin is connected to the other end of its resistor
  • Grab 3 jumper wire
  • Connect 1st LED's positive pin to Digita Pin ~9
  • Connect 2nd LED's positive pin to Digita Pin ~6
  • Connect 3d LED's positive pin to Digita Pin ~5

Our circuit must be look like the images below.

Program our Board

Plug in your Arduino 101.

Download ReadSensorsLed source code and upload it.

Testing our accelerometer

  • Tilt Sideways - The yellow LED will light up if we are in positive X axis
  • Tilt Upside down - The Orange LED will light up if we are in positive Y axis
  • Tilt - The Red LED will light up if we are in positive Z axis.

The brightness of the LED corresponds to the value of the positive axis.

The maximum readings for each axis is 17000.

So we calculated the brightness (0-255) of the analogWrite by brightness = axis/66.66 ;

About the Code

Arduino 101 has Intel Curie Module that uses Arduino api CurieIMU.h

We can read the accelerometer and gyroscope using this function.

CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);

The axis variables are used as parameter and will be referenced by the api to update the values.

Finally get the brightness of led using the formula and update the LED

if(ax>0)
    axBrightness = ax/66.66;  
 else     axBrightness=0;   analogWrite(axLed,axBrightness);
 if(ay>0)     
    ayBrightness = ay/66.66;   
else     
    ayBrightness=0;   
analogWrite(ayLed,ayBrightness);      
if(az>0)
     azBrightness = az/66.66;
else
     azBrightness=0;   
analogWrite(azLed,azBrightness);

Code

ReadSensorsLed.inoC/C++
Reads accelerometer and gyro sensor
#include "CurieIMU.h"
int ax, ay, az;         // accelerometer values
int gx, gy, gz;         // gyrometer values

int axBrightness = 0;
int axLed = 9;

int ayBrightness = 0;
int ayLed = 6;


int azBrightness = 0;
int azLed = 5;

void setup(){
  
  pinMode(axLed, OUTPUT); 
  pinMode(ayLed, OUTPUT); 
  Serial.begin(9600); // initialize Serial communication
  CurieIMU.begin();
  delay(5000); // Allow the user to set everything down
  CurieIMU.autoCalibrateGyroOffset();
  CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0);
  CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0);
  CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 0);
}

String jsonEncodeValue(String key, float keyVal){
  return "\"" + key + "\":" + String(keyVal) + "";
}

String assembleJson(String keysAndVals){
  return "{" + keysAndVals + "}";
}

void loop(){
  // read raw accel/gyro measurements from device
  CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);

  // display JSON formatted accel/gyro x/y/z values
  String keyVals = jsonEncodeValue("ax", ax) + ",";
  keyVals += jsonEncodeValue("ay", ay) + ",";
  keyVals += jsonEncodeValue("az", az) + ",";
  keyVals += jsonEncodeValue("gx", gx) + ",";
  keyVals += jsonEncodeValue("gy", gy) + ",";
  keyVals += jsonEncodeValue("gz", gz);
  
  if(Serial){
    Serial.println(keyVals);
  }
  delay(100);

  if(ax>0)
    axBrightness = ax/66.66;
  else
    axBrightness=0;
  analogWrite(axLed,axBrightness);

  if(ay>0)
    ayBrightness = ay/66.66;
  else
    ayBrightness=0;
  analogWrite(ayLed,ayBrightness);
  
  if(az>0)
    azBrightness = az/66.66;
  else
    azBrightness=0;
  analogWrite(azLed,azBrightness);
}

Schematics

Create 3 LED in Arduino Circuit
Create 3 LED in Arduino Circuit
Untitled 1 03 56 pm rjovu0pxo9

Comments

Similar projects you might like

Gyroscope With Arduino 101

by Jefferson Paredes

  • 2,615 views
  • 0 comments
  • 4 respects

Getting Started with Arduino/Genuino 101

Project showcase by Muhammad Afzal

  • 3,093 views
  • 2 comments
  • 13 respects

Arduino 101 BLE App

Project in progress by Alexis Santiago Allende

  • 10,794 views
  • 26 comments
  • 51 respects

Arduino 101 Home BLE System

Project tutorial by Alexis Santiago Allende

  • 2,424 views
  • 0 comments
  • 11 respects

Arduino/Genuino 101 BLE Thermometer With TMP102 and Blynk

Project tutorial by Konstantin Dimitrov

  • 7,878 views
  • 1 comment
  • 26 respects
Add projectSign up / Login