Skip to content

Accelerometer TinyShield Tutorial

This tutorial will teach you how to take advantage of a BMA250 Accelerometer sensor in your next project!

Accelerometers are already everywhere -- you may even have one in your pocket. Smartphones use accelerometers to help decide if your display should be in landscape or portrait mode. They also protect you in car accidents by detecting when to deploy airbags!

(They're also used to make Virtual Reality devices)

To learn more about the TinyDuino Platform, click here


Description

This TinyShield features the high performance and low power Bosch BMA250 3-axis accelerometer.  The BMA250 allows measurement of accelerations in three perpendicular axes and thus senses tilt, motion, shock, and vibration in your projects. There is also an integrated temperature sensor built in.

Even though the BMA250 is designed to run at 1.8V – the Accelerometer TinyShield incorporates level shifters and a local power supply to ensure proper and safe operation over the entire TinyDuino operating voltage range up to 5V.

To see what other TinyShields are compatible with this TinyShield, see the TinyShield Compatibility Matrix

Technical Details Bosch BMA250 Accelerometer Specs
  • 3-axis (X, Y, & Z)
  • Digital resolution: 10bit
  • Resolution: 3.9mg
  • Measurement ranges: +-2g, +-4g, +-8g, +-16g
  • Sensitivity: 2g: 256LSB/g, 4g: 128LSB/g, 8g: 64LSB/g, 16g: 32LSB/g
  • Zero-g offset (over lifetime): +-80mg
  • Bandwidths: 1000Hz… 8Hz
  • Low Power: 139uA @2kHz data rate
TinyDuino Power Requirements
  • Voltage: 3.0V - 5.5V
  • Current: 139uA (Normal Mode). Due to the low current, this board can be run using the TinyDuino coin cell option
Pins Used
  • A5/SCL - I2C Serial Clock line
  • A4/SDA - I2C Serial Data line
Dimensions
  • 20mm x 20mm (.787 inches x .787 inches)
  • Max Height (from lower bottom TinyShield Connector to upper top TinyShield Connector): 5.11mm (0.201 inches)
  • Weight: 1 gram (.04 ounces)

Notes

  • The BMA250 sensor is sensitive, with a wide range of values, so you probably need to establish value limits for functionality in future projects using the sensor. For example:
if(accReadings < 500 or accReadings > 400)
{ 
    // Do something 
} 
  • This accelerometer has the extra feature of temperature sensing, so you don't need to buy a separate temperature sensor if you need temperature readings in your project.
  • Accelerometer sensors measure acceleration, so you can do projects that measure how fast something can accelerate or IoT applications that involve a sudden movement you need to detect. Common hobby projects include pedometers, robot behaviors, or you can trigger events based on movement (like raising an alarm on an unwanted predator reaching into your cookie jar.)
  • You can also use this shield without the TinyDuino – there are 0.1″ spaced connections for power, ground, and the two I2C signals along the side of the TinyShield to allow you to connect a different system.  WARNING: Revision 4 boards have a mistake on the silkscreen, the pin marked VCC is actually SCL, the pin marked SCL is actually SDA, and the pin marked SDA is actually VCC. If you connect this up the way it is marked (which would be wrong) you will not damage the board.
  • Previous versions of this board will look a bit different and have the board number ASD2611-R, however they are functionally equivalent to this updated version and the accelerometer circuitry is identical. Earlier versions had two interrupt pins broken out to solder points, these are not present on the current version of this board.  

Materials

TinyZero, and Accelerometer TinyShield

Hardware

Software


Hardware Assembly

Stack the Accelerometer TinyShield onto the processor board of your choice using the tan 32-pin connector.

Easy, breezy, beautiful -- TinyDuino Stack.


Upload Program

The BMA250 library that is necessary for interfacing with the sensor is included with the zipped folder of the program. This can be found under the Materials\Software section.

Download the zipped folder, unzip it, and open the .ino file in the Arduino IDE.

In this program, the BMA250 has the four available sensor readings (x, y, z, and temperature) which can be output to either the Serial Monitor or the Serial Plotter. You can find these output options under the Tools tab in the Arduino IDE. The Serial Monitor will output the data readings of the sensor, which may not be very easy to read long term. The Serial Plotter, however, graphs the sensor data, which is nice to look at when you want to see data over time. Each of these output methods has its own function found after the loop() section of the program. The four variables being output are three axes of perpendicular acceleration that are measured and output by the sensor as x, y, and z, as well as the temperature in degrees Celsius.

You cannot use the Serial Plotter and Serial Monitor at the same time in Arduino.

Tools Selections for a TinyZero

Code
/*************************************************************************
 * BMA250 Tutorial:
 * This example program will show the basic method of printing out the 
 * accelerometer values from the BMA250 to the Serial Monitor, and the
 * Serial Plotter
 * 
 * Hardware by: TinyCircuits
 * Code by: Laverena Wienclaw for TinyCircuits
 *
 * Initiated: Mon. 11/1/2018
 * Updated: Tue. 11/2/2018
 ************************************************************************/

#include <Wire.h>         // For I2C communication with sensor
#include "BMA250.h"       // For interfacing with the accel. sensor

// Accelerometer sensor variables for the sensor and its values
BMA250 accel_sensor;
int x, y, z;
double temp;

#if defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#else
#define SerialMonitorInterface Serial
#endif

void setup() {
  SerialMonitorInterface.begin(115200);
  Wire.begin();

  SerialMonitorInterface.print("Initializing BMA...");
  // Set up the BMA250 acccelerometer sensor
  accel_sensor.begin(BMA250_range_2g, BMA250_update_time_64ms); 
}

void loop() {
  accel_sensor.read();//This function gets new data from the acccelerometer

  // Get the acceleration values from the sensor and store them into global variables
  // (Makes reading the rest of the program easier)
  x = accel_sensor.X;
  y = accel_sensor.Y;
  z = accel_sensor.Z;
  temp = ((accel_sensor.rawTemp * 0.5) + 24.0);

  // If the BMA250 is not found, nor connected correctly, these values will be produced
  // by the sensor 
  if (x == -1 && y == -1 && z == -1) {
    // Print error message to Serial Monitor
    SerialMonitorInterface.print("ERROR! NO BMA250 DETECTED!");
  }

  else { // if we have correct sensor readings: 
    showSerial();                 //Print to Serial Monitor or Plotter
  }

  // The BMA250 can only poll new sensor values every 64ms, so this delay
  // will ensure that we can continue to read values
  delay(250);
  // ***Without the delay, there would not be any sensor output*** 
}

// Prints the sensor values to the Serial Monitor, or Serial Plotter (found under 'Tools')
void showSerial() {
  SerialMonitorInterface.print("X = ");
  SerialMonitorInterface.print(x);

  SerialMonitorInterface.print("  Y = ");
  SerialMonitorInterface.print(y);

  SerialMonitorInterface.print("  Z = ");
  SerialMonitorInterface.print(z);

  SerialMonitorInterface.print("  Temperature(C) = ");
  SerialMonitorInterface.println(temp);
}

Make sure when you're using the Serial Monitor, or the Serial Plotter that the baud rate matches what is in the program (which is 115200), otherwise you may get an output that looks like garbage. Here's an example of what you may see on the Serial Monitor if you open it up and wiggle the Accelerometer TinyShield around:

Serial Monitor example data

To juxtapose that beautiful data, here's what some similar waving and rotating of the TinyShield Accelerometer may look like on the Serial Plotter:

Serial Plotter example data

Notice the light colored (turquoise?) line that stays pretty constant, this is the temperature!

Use this TinyShield in a project that needs to detect rotation or sudden movement. Share your motion-sensitive projects with us!


Contact Us

If you have any questions or feedback, feel free to email us at info@tinycircuits.com or make a post on the forum.

Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

Thanks for making with us!


Downloads