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, check out the datasheet for all the specs!


Materials 

Hardware: 

Software:

  • 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 every day, 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 the Serial Monitor, OR the Serial Plotter, you can find these options under the Tools tab. 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, and is nice to look at when you want to see data over time. 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.

Zip File of Program

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

    Solar Tracker
    Solar Tracker

    by Zachary Lee June 20, 2019

    Are you interested in maximizing the energy generated by your solar panels? In this tutorial, we will show you how...

    View full article →

    TinyLily Firework Wearable
    TinyLily Firework Wearable

    by Laverena Wienclaw June 20, 2019

    It's almost the time of year to barbecue and watch some fireworks with friends and family. Dazzle all your loved...

    View full article →

    Command Servo Motors from your Phone using Bluetooth
    Command Servo Motors from your Phone using Bluetooth

    by TinyCircuits Staff December 27, 2018

    Using a TinyZero, Bluetooth TinyShield, Servo TinyShield, and a servo along with a handy dandy iOS or Android app, you...

    View full article →