Accelerometer Data Logger


Create a portable accelerometer data logger. Store the accelerometer data into a microSD memory card which will allow the user to visualize the data by graphing the information using Matlab or any other data graphing program.


The hardware that will be required to create a sensor that will store data is:

  •  Microcontroller
  • 3-axis Accelerometer (A Wii nun chuck controller will be used)
  • MicroSD card adapter

Once all the required hardware was obtained it was wired to the micro-controller. A total of six I/O were used all being powered by 3.3V. Here is a picture of the prototyping stage:

Each device must be bench tested before a complete algorithm is created. To bench test the microSD card adapter data must be written to it manually. To do so the following code was used:

  “mount := \sdfat.mount_explicit(DO, CLK, DI, CS)
if mount < 0
pst.str(string( 13, “Failed to mount”, 13 ) )

pst.str(string(13,”Enter your favorite color and press [ENTER]”,13))

pst.str(string(13, “SD card was found and mounted.”,13))

pst.str(string(13,”Data written to: INPUT.TXT”,13))

The code above checks if a microSD is in the adapter, if so the card is mounted and ready to receive information and if not the program exits. When the SD card is found and mounted it will prompt the user to enter a string that will be stored and read as a text file.

Now that the SD card is ready the bench testing of the 3-axis accelerometer can begin. The goal is to have the sensor output data on a terminal in real-time.  The following code accomplished this:

Nun.readNunchuck ‘read data from Nunchuck
‘output data read to serial port
pst.str(string(pst#NL, “Wii Nun X = “))
sdfat.pputs(string(” “))
waitcnt(clkfreq/64 + cnt)”

The accelerometer and microSD are ready to be combined into a data gathering sensor. Before it is placed in a semi-permanent project box it is ideal to do some black box testing. The software above was combined and executed; the following data was gathered and graphed using MATLAB:


Now that the software is functional the hardware can now be placed in a project box:

An extra necessary piece of hardware was added to this project, a push button. The purpose of the push button was to stop the code and finalize the data storage. In other words if the push button is pressed the micro-controller receives the input and makes the decision to stop sampling data from the accelerometer and also stops the data storage process:

” if ina[14] == 1
‘pst.str(string(13,”Data written to txt file”,13))

The accelerometers x-axis, y-axis, z-axis, pitch and roll are graphed on the same chart. To calculate the max acceleration of a 3-axis accelerometer:  squareroot(x^2+y^2+z^2).

Thank You Parallax Obex!

Leave a Reply

Protected with IP Blacklist CloudIP Blacklist Cloud