ACCELEROMETER
In this project, we will add a new component -- an accelerometer.
Accelerometer RaspberrySTEM Cell
Having issues? Check out the Troubleshooting Guide.

Do you have smart phone or an iPad that switches the screen orientation when you rotate it? Ever wonder how that works? It's done using a component called an accelerometer, and there are lots of cool applications for them when designing and building electronics.

The RaspberrySTEM CREATOR Kit includes its own accelerometer -- it's in the bag marked Accelerometer RaspberrySTEM Cell. Feel free to pull it out now...

By plugging in the accelerometer to the RaspberrySTEM and then writing code to get input from it, we can turn our RaspberrySTEM into a controller that can detect magnitude of movement (acceleration) along all three axes -- left/right, front/back and up/down. From this information, we can determine the orientation of the kit and/or the vector (speed and direction) of movement at a given time. We know that might sound a little confusing, but follow along and you'll see what we mean.

Your Accelerometer RaspberrySTEM Cell contains a single part -- the accelerometer circuit board -- that looks like this (from the top):




Wiring Your Accelerometer

Let's wire up your accelerometer and write some code to get it working...


Step #1: Place the accelerometer on the breadboard

The accelerometer has six pins. It should be inserted into the breadboard such that each pin sits in a different connect strip, and you should ensure that at least one other hole is usable in each connect strip where the accelerometer sits. When inserting the accelerometer into the breadboard, don't be afraid to apply some pressure from the top -- the bottom of the black plastic connectors should touch the breadboard.


Step #2: Connect the accelerometer

WARNING: ACCELEROMETER HOOK-UP

It is very important to note that the power and the ground of the accelerometer must be connected appropriately, otherwise there is a good chance that you will destroy the accelerometer chip (it will likely get warm and start to smoke). So, be very careful that you hook up the chip as shown below.


With four wires, wire up the accelerometer as show below. Specifically:

Here is what your breadboard should look like once the accelerometer is properly wired (the LED Matrix in this picture can be ignored):

Testing Your Accelerometer

Let's write some code to test your accelerometer and see how it works:



Now, let's take a look at what our code is doing:

Running Your Code

If you run your test code, what you should immediately see is that your Output Window starts filling up with numbers. These numbers -- three per line -- indicate the relative movement of the RaspberrySTEM (specifically, the accelerometer we wired on the breadboard), as follows:

Based on that, if you sit your RaspberrySTEM down on a flat surface, you should expect the first number to be 0, the second number to be 0 and the third number to be 1. In reality, the accelerometer is very sensitive, and it's unlikely that your surface is 100% flat, so you'll probably see readings that are very slightly off from those numbers.

Play around with the RaspberrySTEM and try to get a feel for how different movements and rotations affect the numbers on the screen. In future projects, we'll be using this functionality to turn the RaspberrySTEM into a game controller.


home | prev | next