I’ve had an Arduino Uno for almost a year now, but seldom had the time to work with it, and when I did have time, I had too little experience to build anything interesting. Recently however, I’ve been spending a little more time with it and have become proficient enough in the language to construct fun and interesting systems. This project uses the ADXL345 3-axis accelerometer to detect single and double taps, and blink a dual color (red and green) LED depending on whether an sigle or double tap has been detected.
The Ariduino has two designated I2C bus pins (data and clock) and the Arduino IDE includes an I2C library (Wire.h, which includes other protocols as well). Also, pins 2 and 3 on the Arduino Uno can be configured as hardware interrupts. The I2C device I use is the ADXL345 3-axis accelerometer (mine is similar to this, but has SPI interface pins as well as I2C pins). Get the ADXL345 datasheet here.
Because of the large number of functions on the ADXL345, writing a library was necessary to keep everything looking clean. The library is not very well commented, but as the functions are extremely simple it should be easy to follow (if you’ve read the datasheet).
The library can be found here.
The sketch is well commented so it should be relatively easy to follow, but if you have questions about the sketch or library feel free to ask in the comments below.
The sketch can be found here (click to view, right-click and “Save as” to download).