Gyroscope With Arduino 101 © MIT

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

  • 3,985 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

Learn how to read Gyroscope 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 above.

Program the Arduino 101

Plug in your Arduino 101.

Download GyroscopeSensor.ino source code and upload it.

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(gx>0)
    gxBrightness = gx/66.66;   
else
     gxBrightness=0;
analogWrite(gxLed,gxBrightness);   // show gyroscope's X Axis brightness
if(gy>0)
     gyBrightness = gy/66.66;
else
     gyBrightness=0;   
analogWrite(gyLed,gyBrightness); // show gyroscope's Y Axis brightness
if(gz>0)
     gzBrightness = gz/66.66;   
else
     gzBrightness=0;   
analogWrite(gzLed,gzBrightness); // show gyroscope's Z Axis brightness

Code

GyroscopeSensorC/C++
#include "CurieIMU.h"
int ax, ay, az;         // accelerometer values
int gx, gy, gz;         // gyrometer values

int gxBrightness = 0;
int gxLed = 9;

int gyBrightness = 0;
int gyLed = 6;


int gzBrightness = 0;
int gzLed = 5;

void setup(){
  
  pinMode(gxLed, OUTPUT); 
  pinMode(gyLed, OUTPUT); 
  pinMode(gzLed, 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(gx>0)
    gxBrightness = gx/66.66;
  else
    gxBrightness=0;
  analogWrite(gxLed,gxBrightness);

  if(gy>0)
    gyBrightness = gy/66.66;
  else
    gyBrightness=0;
  analogWrite(gyLed,gyBrightness);
  

  
  if(gz>0)
    gzBrightness = gz/66.66;
  else
    gzBrightness=0;
  analogWrite(gzLed,gzBrightness);

}

Schematics

Schematics
Fymyx6rj4iq7j3b large evtbffinhb

Comments

Similar projects you might like

Accelerometer Using Arduino 101

by Jefferson Paredes

  • 2,663 views
  • 0 comments
  • 3 respects

Arduino 101 BLE App

Project in progress by Alexis Santiago Allende

  • 10,794 views
  • 26 comments
  • 51 respects

Getting Started with Arduino/Genuino 101

Project showcase by Muhammad Afzal

  • 3,097 views
  • 2 comments
  • 13 respects

Control LED/Relay Using Arduino 101

Project tutorial by Shivansh Singh

  • 3,630 views
  • 1 comment
  • 5 respects

Smart Garbage Monitoring System Using Arduino 101

Project tutorial by Technovation

  • 21,394 views
  • 7 comments
  • 32 respects
Add projectSign up / Login