Things used in this project

Code

Code for Genuino 101Arduino
This is the code running on the device.
It must be flashed on the arduino/genuino device
#include <CurieBLE.h>
#include "CurieIMU.h"

int lastOrientation = - 1; // previous orientation (for comparison)

BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)
BLEService handstandService("19B10000-E8F2-537E-4F6C-D104768A1214"); // B

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEIntCharacteristic handstandChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLENotify);


void setup() {
  Serial.begin(9600); // initialize Serial communication
  //while (!Serial);    // wait for the serial port to open

  // initialize device
  Serial.println("Initializing IMU device...");
  CurieIMU.begin();

  blePeripheral.setLocalName("Handstan");
  blePeripheral.setAdvertisedServiceUuid(handstandService.uuid());

  // add service and characteristic:
  blePeripheral.addAttribute(handstandService);
  blePeripheral.addAttribute(handstandChar);

  blePeripheral.begin();

  // Set the accelerometer range to 2G
  CurieIMU.setAccelerometerRange(2);
}

void loop() {
int orientation = -1;   // the board's orientation
  String orientationString; // string for printing description of orientation
  /*
    The orientations of the board:
    0: flat, processor facing up
    1: flat, processor facing down
    2: landscape, analog pins down
    3: landscape, analog pins up
    4: portrait, USB connector up
    5: portrait, USB connector down
  */
  // read accelerometer:
  int x = CurieIMU.readAccelerometer(X_AXIS);
  int y = CurieIMU.readAccelerometer(Y_AXIS);
  int z = CurieIMU.readAccelerometer(Z_AXIS);

  // calculate the absolute values, to determine the largest
  int absX = abs(x);
  int absY = abs(y);
  int absZ = abs(z);

  if ( (absZ > absX) && (absZ > absY)) {
    // base orientation on Z
    if (z > 0) {
      orientationString = "up";
      orientation = 0;  
    } else {
      orientationString = "down";
      orientation = 1;
    }
  } else if ( (absY > absX) && (absY > absZ)) {
    // base orientation on Y
    if (y > 0) {
      orientationString = "digital pins up";
      orientation = 2;
    } else {
      orientationString = "analog pins up";
      orientation = 3;
    }
  } else {
    // base orientation on X
    if (x < 0) {
      orientationString = "connector up";
      orientation = 4;
    } else {
      orientationString = "connector down";
      orientation = 5;
    }
  }

  // if the orientation has changed, print out a description:
  if (orientation != lastOrientation) {
    Serial.println(orientationString);
    lastOrientation = orientation;
    notifyUpdate(lastOrientation);
  }
}

/*updating bluetooth listeners*/
void notifyUpdate(int newOrientation) {
  handstandChar.setValue(newOrientation);
}
Html5 CodeArduino
Unzip the archive and launch the main.html file
No preview (download only).

Credits

Photo
Andrea De Gaetano

Interested in iot, mobile and security Love hackathons This is my blog http://pestohacks.blogspot.com

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Water Softener
Easy
  • 265
  • 5

Full instructions

Sweeping frequency magnetic hard water conditioner

Know the Temp of Your Home From Anywhere with Arduino Cloud!
Easy
  • 1,246
  • 9

Full instructions

Ever wanted to know the temperature of your home from somewhere? Here's an easy way to do it with Arduino Cloud and the Yun Shield!

Simple Obstacle Senor With Arduino
Easy
  • 88
  • 2

Full instructions

I am gonna show you how to make a simple obstacle sensing system with cheap parts like IR LED and photo diode.

Safe City: A Device to Keep You Safe
Easy
  • 630
  • 6

Full instructions

The device will keep you safe. Just have to click a button and your precise location will be shared.

Arduino UNO Home Automation using Bluetooth HC05 module
Easy
  • 13
  • 1

Protip

Home Automation Attributes: Turning ON/OFF light bulb (AC 220V). Automatically Turning the Led ON/OFF depending on light intensity.

Connect Your Thinxtra Xkit Using Sigfox
Easy
  • 130
  • 2

Protip

Learn how to build an IoT application over Sigfox integrated with Ubidots - send temp readings based on motion sensors.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog