In this project, we will wire up the accelerometer that we introduced in the previous concept and we'll write some code to allow it to measure the orientation of the kit.

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

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. Like this:

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.

Wire 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. If you wire VCC (which is Power) to ground on the breadboard, or if you wire GND to Power on the breadboard, there is a good chance that you will destroy the accelerometer chip (it will likely get warm and start to smoke). So, be extra careful that you hook up the chip as shown below.

With four wires, wire up the accelerometer like this:

Here is what your breadboard should look like once the accelerometer is properly wired:

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 Program Output window starts filling up with numbers. There are three numbers on each line, and those numbers correspond to the values of the X, Y and Z forces.

If you sit your CREATOR Kit down on a flat surface, you should expect the first number to be very close to 0, the second number to be very close to 0 and the third number to be very close to 1. While you might expect the numbers to be exactly 0, 0 and 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 CREATOR Kit 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 CREATOR Kit into a game controller.

  1. Instead of printing the X, Y, and Z forces, can you print (just for the X forces) a single "*" for each tenth greater than zero? For example, if the force is .4xxxx, you would print "****". If the force is .7xxxx, you would print "*******". This should give you a good visualization of how the values change as the kit is moved.

  2. Can you do the same as above for the Y and Z forces as well?