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

Arduino - Web-based Joystick
Easy
  • 15
  • 4

Full instructions

This project shows how to control devices from anywhere using web-based joystick on smart phone

Distance Indicator Using Ultrasonic Sensor
Easy
  • 51
  • 3

Work in progress

This project lights a set of LED's depending upon the distance of the obstacle with respect to the ultrasonic sensor.

BluSpike - Community Driven BLE Sensor Network
Easy
  • 44
  • 2

Full instructions

Easy to build w/ off the shelf parts, BLE solar powered sensor array. Connect and share its data to the cloud and be rewarded with ethereum

NeoPixel Thermometer!
Easy
  • 201
  • 4

Full instructions

Transforms a NeoPixel ring into a cool thermometer

Arduino - Web-Based Thermometer
Easy
  • 1,077
  • 15

Full instructions

This project allows you to check temperature at home from anywhere using web browser.

Electronic Voting Machine Using Arduino
Easy
  • 222
  • 5

It is an EVM using Arduino. There are five switches in all, assigned for various activities.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login