Tuesday, December 25, 2007

Arduino with Radio Shack Parallax accelerometer

I think the theme for today will be rapid prototyping and speed. In between Christmas celebrations, and holiday movie re-runs, I've run back to my room to whip together some circuits. It's insane how easy it is to build functioning devices with the Arduino! Case in point: ~30 minutes tops to build a fully-functioning hand-held accelerometer driven device.

I started with the Parallax accelerometer, which I picked up from Radio Shack. The full name is "Memsic 2125 Dual-Axis Accelerometer".




Using the two diagrams above as the theory, and borrowing code from the Arduino community (special thanks to Marcos Yarza for the initial code, which I've cleaned up below). The first step was the wire up the chip to the board. That was easy, since the kit comes with a pinout sheet: two pins are tied to ground, one to +5V, Tout is ignored for now, which leaves Yout and Xout. Xout and Yout are PWM outputs that, according to the second schematic above, output a variable width pulse based on their reading. I wired it up, and then read the values out to the serial port:



Once I had ranges for the values, I got a little creative and threw in some condition "if" statements, tied to LEDs on the prototyping board. Now, an LED should illuminate whenever the board is tilted in that direction:



Here is the source code I pulled together. I moved around some of the original code, to make it more cut-and-paste-y into your own projects.

1 comment:

Kweku said...

Hi Matt,

Fantastic blog you have here! This post is really going to help with a project I had in mind. But I was wondering about the sample rate for the accelerometer - is is fixed at the 2 or so Hz I see it at, or is possible to modify? I'm looking to sample faster, and I'm wondering if the Parallax is something I should be looking at or not...