A new homebrew DIY breakout board PCB for the ADXL345 accelerometer

Last updated on Sat, 2010-12-04 16:12. Originally submitted by fabio on 2010-11-22 16:12.

Some time ago I created my first homebrew breakout board PCB for an ADXL345 accelerometer. After getting more experienced and testing the whole procedure some times I created a new and improved version.

In the attachments below you find all the Kicad sources needed to edit the design or printing the design by yourself.

All the designs are released under the Creative Commons — Attribution-ShareAlike 3.0 Unported Licence.

To show you how this works I created a video description:

The programs run in the video are available on this page attachments and are an adaptation of this great introduction to the ADXL345 accelerometer on http://codeyoung.blogspot.com/.

This is a screenshot of the kicad PCB design:

Kicad PCB design screenshot

Below two pictures of the top and bottom of the breakout board PCB:

Top of the homebrew breakout board PCB for the ADXL345 accelerometer

Bottom of the homebrew breakout board PCB for the ADXL345 accelerometer

These picture of the ADXL345 to Arduino connection might also be useful:

Picture of the connections from the ADXL345 accelerometer to Arduino

Schematics of the connections (image from http://codeyoung.blogspot.com/):

Schematics of the connections from the ADXL345 accelerometer to Arduino

AttachmentSize
ADXL345 breakout board kicad sources174.71 KB
Arduino Code for the ADXL345 example in the video1.57 KB
Processing Code for the ADXL345 example in the video995 bytes
ADXL345 breakout board Schematics9.95 KB

error while compiling

Submitted by sekhar (not verified) on Wed, 2015-06-10 01:36.

Hi Fabio, I am currently working with ADXL345 didgital output accelerometer as part of my project which involves the fall detection of a patient.. I am using arduino uno board with a pulse sensor, temperature sensor and a GPS sensor along with ADXL345... my other two sensors i.e. pulse and GPS are using two timers of arduino board left me with blank space to use this ADXL345 as it needs interrupts to work.. so I thought of using this ADXL345 with other arduino board and hen communicate these readings with each other.. I am using your code to implement the free fall detection but I am getting lot of errors like..I am really new to arduino so please spare me for this.. I am just learning..
_11_accelerometer_adxl345_interrupts.pde: In function 'void loop()':
_11_accelerometer_adxl345_interrupts.pde:184:20: error: 'BYTE' was not declared in this scope
_11_accelerometer_adxl345_interrupts.pde: In function 'void writeTo(int, byte, byte)':
_11_accelerometer_adxl345_interrupts.pde:208:9: error: 'class TwoWire' has no member named 'send'
_11_accelerometer_adxl345_interrupts.pde:209:9: error: 'class TwoWire' has no member named 'send'
_11_accelerometer_adxl345_interrupts.pde: In function 'void readFrom(int, byte, int, byte*)':
_11_accelerometer_adxl345_interrupts.pde:217:8: error: 'class TwoWire' has no member named 'send'
_11_accelerometer_adxl345_interrupts.pde:226:20: error: 'class TwoWire' has no member named 'receive'
_11_accelerometer_adxl345_interrupts.pde: In function 'byte readByte(int, byte)':
_11_accelerometer_adxl345_interrupts.pde:236:8: error: 'class TwoWire' has no member named 'send'
_11_accelerometer_adxl345_interrupts.pde:245:19: error: 'class TwoWire' has no member named 'receive'
Error compiling.
If you could just tell me where I went wrong..it would be a great help...and I did connections as you mentioned as well...thanks..Sekhar

measure vibration in rc helicopter

Submitted by andy (not verified) on Mon, 2014-07-21 08:04.

Hi thanks for your great info. I am new to arduino, i would like to have two sensors, 3 axis accelerometers, to measure vibration on a model helicopter. Do you think it will work. Are you able to advise which accelerometer i should use? Would i be correct in saying one with a low g rating

very good tutorial how to use

Submitted by Anonymous (not verified) on Tue, 2013-07-16 19:47.

very good tutorial how to use accelerometer sensors. I add this tutorial on my article where a long list with sensors and tutorials about how to interface and programming accelerometer, gyro and IMU sensors

Several ADXL345

Submitted by Roger Dahlmans (not verified) on Tue, 2011-12-13 15:29.

Hello Fabio,

I'm a student from the Netherlands and this year I am doing my internship where I came in touch with Arduino. I need for my project to connect 4 accelerometers to an Arduino. I have bought one ADXL345 accelerometer form www.dfrobot.com and it works just fine. The next step is to implement 4 ADXL345 accelerometers. Therefore I need to change the ID Address of the accelerometers, otherwise they don't listen. I'm using I2C to communicate to the accelerometers. Do you know how I can achieve this? It would help a lot.

With kind regards,

Roger Dahlmans

Hi Roger, the ADXL345 can

Submitted by fabio on Tue, 2011-12-13 15:55.

Hi Roger, the ADXL345 can be accessed using 2 I2C address.. the address used by the accelerometer is set using the value on the SDO pin. Depending if this pin is connected to ground or Vcc you'll have different I2C addresses. You'll have to adjust your code to access different addresses. Check out the ADXL345 datasheet for all the details.

Unfortunately you can only connect 2 accelerometer per each I2C bus as the accelerometer only supports 2 addresses, so if you put more than 2 accelerometers you would surely have conflicts in the bus (two accelerometers with the same address).

So, I can think about 3 different approaches to read 4 accelerometers.

  • Use 2 Arduinos each of them connected to two accelerometers. The 2 Arduinos may exchange readings using the Serial port.
  • Use a single Arduino and an I2C multiplexer which let you multiplex your I2C bus in two sides. Checkout document AN10216 (page 43) from NXP for an introduction on I2C multiplexing.
  • Use a single Arduino and the A4 and A5 I2C bus for 2 accelerometers, and use other two pins to create another I2C bus which is implemented in software. This library let you do so.

A completely different approach (which is even better), is no more using I2C but use SPI, the other kind of bus Arduino supports. As in SPI the chip selection is made using an additional wire, insted of a fixed device address as in I2C, you can connect 4 ADXL345 to a single Arduino. This is somehow more difficult to implement as you won't find much examples of this online, but it's surely the most elegant solution.

Good luck!

several ADXL345

Submitted by Roger Dahlmans (not verified) on Tue, 2011-12-13 17:21.

Hello Fabio,

I trying to get it up and running using SPI.
I'll let you know if it worked out.

Grtz

How to

Submitted by Nicolas (not verified) on Fri, 2011-04-15 22:10.

Hi, I want to do a breakout board for this accelerometer, but before I start I wanted to be sure how difficult it is. What do I have to do to avoid damaging the sensor while I solder it? Also how do you stick it to the board?,it has no "legs".
Thanks

You can solder it with this

Submitted by fabio on Fri, 2011-04-15 22:27.

You can solder it with this technique. The chip is quite robust, just avoid to overheat it.

Thanks a lot great video!

Submitted by Nicolas (not verified) on Sat, 2011-04-16 04:14.

Thanks a lot great video!

Something's not quite right

Submitted by Nat (not verified) on Fri, 2011-03-11 07:40.

Hi there, Im using the arduino code from this post directly for my digital combo board ADXL345/ITG3200. It's able to run but the values I get is off. Without moving the board i get values like:
-14 9 198
-8 11 200
-11 10 203
-12 9 206
I've compared the pin values of my board with the program and there's nothing noticeably different to me. Do I have to change some codes to get the program running properly with this board? Thank you.

That's actually good.

Submitted by fabio on Fri, 2011-03-11 08:21.

That's actually good. Theoretical values should be 0 0 256 when the ADXL345 lies flat (0g 0g 1g). The problem is that values present chip specific offsets which you'll have to compensate to get the expected values.

For example the line -8 11 200 would be compensated by the offsets +8 -11 +56.

A more sophisticated calibration procedure is presented in http://www.st.com/stonline/products/literature/an/17353.pdf

Link Not working

Submitted by abhimanyu (not verified) on Sun, 2012-04-22 19:07.

Hi Fabio,
Is this the correct link that you have pasted above.
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/...
may have changed.

Yes, that's the correct

Submitted by fabio on Mon, 2012-04-23 18:08.

Yes, that's the correct link.. No clue why ST keeps changing their documentation URLs..

I read the link and it said

Submitted by Nat (not verified) on Mon, 2011-03-14 03:00.

I read the link and it said to use matrix to calibrate. Im not sure of how to put the matrix formula and all that into programming language. For the offsets part, do I have to type in every line to make sure that the results are always 0 0 256, or is this covered in the matrix side? I've tried simpler programs (just reading and writing) and the results are always the same (jumping numbers) and I guess it's caused by the calibration procedure you mentioned and I have no idea how to calibrate the ADXL345 at all. Thanks!

It's perfectly normal that

Submitted by fabio on Mon, 2011-03-14 10:20.

It's perfectly normal that values jumps between near values. Even if the ADXL345 is a digital accelerometer it is affected by noise so you won't ever get very fixed values.

If you don't understand the math in the document above you can simply use the simple offset calibration I suggested. Basically, you sample a big number of outputs while keeping the acc steady, you average them and use the result as offset between the expected value of 0 0 256.

Example: if you average the numbers and you get 5 13 240, your offsets would be -5 -13 16 and you would sum them on each reading you will make after the calibration.

I've got the numbers more or

Submitted by Nat (not verified) on Tue, 2011-03-15 03:15.

I've got the numbers more or less stable now and finally understand the offset part but now I have a problem getting the processing to run too.

Great, good to hear about

Submitted by fabio on Tue, 2011-03-15 11:08.

Great, good to hear about your progresses.

What problems are you having with the Processing code?

Remember that you have to run it using the Processing IDE (download it from Processing.org) and you have to adjust the serial port definition to match your system (eg: replacing "/dev/ttyUSB0" with "COM1" or something like that if you are under windows).

Hope this helps,

Fabio

It turned out to be some

Submitted by Nat (not verified) on Wed, 2011-03-16 02:03.

It turned out to be some programming error where the order of some codes were placed wrongly. Thanks so much for your help!! =D

OK I got it Working but..

Submitted by Anonymous (not verified) on Wed, 2010-12-15 06:15.

Ok so It works great!!! thank you so much
I actually ended up having to change a lot from the original code on the other web site but it works !! THX!!

Great news! Keep on hacking!

Submitted by fabio on Wed, 2010-12-15 09:59.

Great news! Keep on hacking!

Question!

Submitted by Anonymous (not verified) on Thu, 2010-12-09 18:55.

I have a ADXL203/ADXRS610 Combo Board and I have read you code over and over and i Still cant get my processing to run I have tried to change the analog imputs but nothing works.
So My question is is it possible to run your program with this combo board?
and if so would i have to change something in you code ?

Hi there, it is possible to

Submitted by fabio on Thu, 2010-12-09 23:57.

Hi there, it is possible to apply the same theory behind my code for the sensors you have. They both are analogical sensors, so you won't be able to use Wire (I2C) to connect to your sensors. Instead you will have to use the Analog inputs of your Arduino.

You accelerometer will output a voltage which will be proportional to the acceleration detected on one axis. You will have to convert this voltage to a G acceleration using some math..

Once you have an acceleration you will be able to adapt my code to your accelerometer.

You can read a good introduction to this topics here: http://www.starlino.com/imu_guide.html

Feel free to ask if you need for help.

half-way there!

Submitted by Anonymous (not verified) on Fri, 2010-12-10 03:16.

All right so i got all my conversion formulas together 2 for the gravitational forces X and Y and the rotation of the plane XZ also i got the angles of the vectors of Rx and Ry!

the question now is how do I integrate this with your code ?
plz help

Thanks!

If you want to use the code

Submitted by fabio on Fri, 2010-12-10 10:04.

If you want to use the code in this page you simply have to send the x & y G values over serial to the PC running the processing code.

If they are integers you can simply send them as they are, instead if they are floats you can use this: http://www.varesano.net/blog/fabio/sending-float-variables-over-serial-w...

Once you have your values expressed in G in your processing app you can simply do:

rotateZ(GaccX * HALF_PI);
rotateX(GaccY * HALF_PI);

Instead if you need pitch and roll angles:

float pitch = asin(GaccX); 
float roll = asin(-GaccY / cos(pitch));

Does this helps?

Well...

Submitted by Anonymous (not verified) on Tue, 2010-12-14 06:09.

For some Reason Im Sending my X & Y G-values replacing some variables from your code & changing your serial port to mine (all this from your code "_12_ADXL345_titlt.tar)

Here is my Modified Code
But Im Getting the errors: Unexpected char0x0 or unexpected token: void...??
byte[] buff;
int SIZE = 600, SIZEX = 800;
int OFFSET_X = -28, OFFSET_Y = 9; //These offsets are chip specific, and vary. Play with them to get the best ones for you
void setup() {
size(SIZEX, SIZE, P3D);
println(Serial.list());
Serial port = new Serial(this, Serial.list()[0], 9600);
buff = new byte[128];
r = new float[3];
}
float protz, protx;
void draw() {
//delay(1000);
//perspective( 45, 4.0/3.0, 1, 5000 );
//print("ciao");
translate(SIZEX/2, SIZE/2, -400);
background(0);
buildShape(protz, protx);
String Xaccl = port.readStringUntil(10); //Modefied input from Serial.
//String Yaccl = port.readStringUntil('\n');
if (Xaccl != null){
//print(Xaccl);
float[] Accl = float(split(Xaccl, ' '));
float Y = Accl[0], X= Accl[1], Z=Accl[2];
print(Y); // print("Y ");
print(X); // print("X");
print(Z); // println("Z");
float z = Accl[0], x = Accl[1]; //Modefied line
if(abs(protz - Accl[0]) < 0.05) //Modefied line
z = protz;
if(abs(protx - Accl[1]) < 0.05) //Modefied line
x = protx;
background(0);
buildShape(z, x);
protz = z;
protx = x;
}
void buildShape(float rotz, float rotx) {
pushMatrix();
scale(12,12,14);
rotateZ(rotz);
rotateX(rotx);
//rotate(rotx, PI/2, rotz);
fill(255);
stroke(0);
box(20, 5, 60);
//fill(0, 255, 0);
//box(10, 9, 40);
//translate(0, -10, 20);
//fill(255, 0, 0);
//box(5, 12, 10);
popMatrix();
}

Is my Idea right or am I completely wrong ?

You code doesn't look bad.

Submitted by fabio on Tue, 2010-12-14 08:59.

You code doesn't look bad. The only thing I see is Z=Accl[2];.. I don't think you have a Z value so that's probably useless.

The error you get, is it at compile time or at runtime?

At Compile time.

Submitted by Anonymous (not verified) on Tue, 2010-12-14 18:45.

My Z value comes from the Gyro's Z rotation value. then when I try to run the code this line becomes highlighted but I cant seem to understand why?

void buildShape(float rotz, float rotx) {

With the error "unexpected token : void."

You have an unclosed } before

Submitted by fabio on Wed, 2010-12-15 01:03.

You have an unclosed } before the void buildShape(float rotz, float rotx) {

You really should indent your code to see that.

Ok!

Submitted by Anonymous (not verified) on Wed, 2010-12-15 22:55.

Finally Got it working I ended up using the code from the original web site modified it a little bit and got it to work real nicely!

Thanks so much for the help!!!