Add motion and direction sensing to your wearable Flora project with this high precision 3-axis Accelerometer+Compass sensor. Inside are two sensors, one is a classic 3-axis accelerometer, which can tell you which direction is down towards the Earth (by measuring gravity) or how fast the board is accelerating in 3D space. The other is a magnetometer that can sense where the strongest magnetic force is coming from, generally used to detect magnetic north. By combining this data you can then orient yourself.

We based this sensor on the latest version of this popular sensor, the LSM303DLHC. The sensor has a digital (I2C) interface. Attaching it to the Flora is simple: line up the sensor so its adjacent to the SDA/SCL pins and sew conductive thread from the 3V, SDA, SCL and GND pins. They line up perfectly so you will not have any crossed lines. You can only connect one of these sensors to your Flora, but you can connect other I2C sensors/outputs by using the set of SCL/SDA pins on the opposite side.
To get started making a soft accelerometer circuit on fabric you will need:
Bring your needle through the back of the fabric to the front next to the GND pad on your Flora. Leave a the last few inches as a tail on the back side of the fabric.
Stitch a few times around the GND pad and end on the back side of the fabric. Tie the tail and the working thread into a square knot, tight against the fabric.
Dab a little Fray Check or clear nail polish on the knot while holding it tight. This will prevent the knot from coming undone and creating unwanted shorts in your circuit. Trim the tail very close to the knot.
Stitch a path over to the gnd pad on the Flora accelerometer. When you get there, stitch a few times around the sensor's gnd pad.
On the back side of the fabric, slip the needle through the previous stitches and then back through the resulting loop to tie a knot tight to the fabric. Dab on your sealant and trim closely.
Repeat this process to make the other three required connections to the accelerometer - 3.3v, SCL, and SDA. This is the i2c bus on the Flora, and you can chain more sensors (or LED matrix backpacks) to this first one by connecting to the as-of-now unconnected SDA and SCL pins. i2c is great for this application because you can connect many devices to each other without using up all the pins on the Flora.
Plug in a USB cable connecting your Flora to your computer.

Download the Adafruit_LSM303 library from the Arduino Library Manager.

Open up the Arduino Library Manager:

Search for the Adafruit LSM303 library and install it

Open the special Adafruit version of the Arduino IDE and naviate to File-->Examples-->Adafruit_LSM303-->Test to open the accelerometer test sketch. For more information on programming the Flora, check out the Getting Started with FLORA guide.

Be sure you have the correct serial port and board type selected under the Tools menu, then upload the sketch to your Flora.
Open the serial monitor and watch the accelerometer values pour in!
Modify this sample sketch to integrate this sensor into your project. Debugging over USB is helpful to see the ranges of numbers your sensor provides, but once your code is solid, you can disconnect from the computer and power your project with a 3xAAA battery holder.

This guide was first published on Feb 05, 2013. It was last updated on Feb 05, 2013.