Using the TinyZero Accelerometer

by Laverena Wienclaw November 21, 2018

Using the TinyZero Accelerometer

This tutorial will guide you through reading values from the Accelerometer Sensor that can be populated on the TinyZero processor, you can also use this tutorial for the TinyZero and the Accelerometer TinyShield. The code included in this tutorial shows you how to display the accelerometer sensor values to the Serial Plotter, and the Serial Monitor.

If you want more info on the BMA250 sensor itself, checkout the datasheet for all the specs!


Materials 

Hardware: 

or
  • Arduino IDE
  • BMA250 Files (Included later in the tutorial!)

Some important things:

  • 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. (ie. if(accReadings < 500 or accReadings > 400){ // Do something } )
  • This accelerometer has the extra feature of a temperature reading, so you don't need to buy a separate temperature sensor if you need temperature readings in your project.
  • You probably hold a sensor like this everyday, it's the reason your smart phone screen knows when to rotate the display!
  • 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.)

Step 1: Assembly 

All you need to do here is plug your USB cable from TinyZero to computer. 


Step 2: Software

Now you just need to open up your Arduino IDE and make sure you're hooking up the board correctly!

  • Board -> TinyZero
  • Port -> COM##  (If you're not sure which Port your Arduino is connected to, check this out for Windows/Mac help)
  • Programmer: "Arduino as ISP"

TinyZero Tools selections for the program in this tutorial. 


Step 3: The Code!

In this program, the BMA250 has the four available sensor readings output to a Serial Monitor, and the Serial Plotter, you can find these options under the Tools tab. Both of these output methods has it's 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, and the sensor can read out the temperature in degrees Celsius. 

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

Note: you need the two BMA250 supporting files (the .cpp and .h) for the .ino to work.

When downloading these files or copying and pasting them into new files, make sure the folder they're in has the same name as the .ino program so that everything compiles correctly in Arduino. Often, window errors will pop up immediately to let you know you need to fix this.

If you've never used the Serial Plotter, now's a good time! There is a function in the .ino program above that will print the accelerometer sensor data to the Serial Plotter. This tool makes a good visualization of the range of sensor readings! Here's an example of my data when I was waving the sensor around every couple of seconds: 

The constant, turquoise-colored value is the temperature reading. You can find out which color corresponds to the axes by moving the sensor in different directions and keeping track of which value is changing when you do.


    Contact Us

    As always, if you have any questions or feedback, feel free to email us at info@tinycircuits.com.

    Show us what you make by tagging @TinyCircuits on instagram, twitter, or facebook so we can feature it!

    Thanks for making with us!



    Laverena Wienclaw
    Laverena Wienclaw

    Author



    Also in Learn

    TinyZero Accelerometer BMA250 Internet of Things Project with Cayenne
    TinyZero Accelerometer BMA250 Internet of Things Project with Cayenne

    by Laverena Wienclaw November 21, 2018

    In this tutorial, we will use Cayenne to capture some accelerometer readings on their nice Internet of Things dashboard

    View full article →

    TinyZero Setup Tutorial
    TinyZero Setup Tutorial

    by Laverena Wienclaw November 21, 2018

    Ready to get started with your new TinyCircuits product? This tutorial will cover basic setup of the TinyZero.

    View full article →

    SRAM TinyShield Tutorial
    SRAM TinyShield Tutorial

    by Nick DiVitto July 02, 2018

    The SRAM Tinyshield allows you to add memory to your TinyDuino projects that can read and write at a virtually instant rate. Here's...

    View full article →