Tilt Sensor

Simple Levels

A toy in which the tilt can force a ball to roll in a given direction. image credit Wikimedia
Bubbles rise against gravity, both in the cylinder of the level and in a glass of carbonated water.image credit Mariya Krastanova
A bubble level. image credit Public Lab

In Two Dimensions

A bubble level with separate sensors for each axis of tilt. image credit Public Lab
X component: 0
Y component: 0
Magnitude: 0
X component: Y component: Tilt back and forth:Tilt left and right:Rotate face:
These are the three axes that the SpinWheel can detect acceleration and gravity along. In the interactive 3D diagram you can see how the vector of gravitational acceleration (in grey) is decomposed along these three axes. You can drag, ctrl+drag, or scroll on the 3D image to rotate, pan, or zoom the camera.image credit Mariya Krastanova

Programming your own Tilt Sensor

#include "SpinWearables.h"
using namespace SpinWearables;

void setup() {
  // Connect to the computer, so we can read status messages.
  Serial.begin(115200);
  // Ensure the special SpinWheel hardware is working.
  SpinWheel.begin();  
}

void loop() {
  // Send a confirmation message over and over.
  Serial.println("I am working!"); 
}

Measuring Tilt

#include "SpinWearables.h"
using namespace SpinWearables; 

void setup() {
  // Ensure all of the SpinWheel hardware is on.
  SpinWheel.begin();
}

void loop() {
  // Read all sensor data.
  SpinWheel.readIMU();

  // Save the x-axis measurement in a variable.
  int x = SpinWheel.ax*255;
}

Responding to Tilt Along the X-axis

#include "SpinWearables.h"
using namespace SpinWearables; 

void setup() {
  // Ensure all of the SpinWheel hardware is on.
  SpinWheel.begin();
}

void loop() {
  // Read all sensor data.
  SpinWheel.readIMU();

  // Save the x-axis measurement in a variable.
  int x = SpinWheel.ax*255;

  // Turn off all LEDs.
  SpinWheel.clearAllLEDs();

  // If the tilt is in a given direction,
  // turn on the corresponding LED.
  // We only want the SpinWheel to register
  // if the tilt is sufficiently large.
  if (x > 10) {
    SpinWheel.setLargeLED(5, x, x, x);
  }
  else if (x < -10) {
    SpinWheel.setLargeLED(7,-x,-x,-x);
  }

  SpinWheel.drawFrame();
}
  if (x > 10) {
    SpinWheel.setLargeLED(5, x, x, x);
  }
  else if (x < -10) {
    SpinWheel.setLargeLED(7,-x,-x,-x);
  }
// reveal.js plugins