Pages: [1]   Go Down
Author Topic: Arduino UNO and ADXL 345 Accelerometer  (Read 12385 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello to community,

I was bought this accelerometer in DX.com

http://dx.com/p/adxl345-digital-3-axis-gravity-acceleration-sensor-module-blue-149476

But I don't know how connect it correctly with Ardino UNO board...

This is a shot of my protoboard with all elements:





Red cables are 3.3v
Blue cable are ground
Yellow cables are A4 and A5 connections

I got this design from http://bildr.org/2011/03/adxl345-arduino/  and http://arduino.cc/forum/index.php?topic=97486.0 (the connections are from latest web)



And.. this is my code...

Code:
void setup()
{
  Serial.begin(9600);    
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);
}

void loop()
{
  Serial.println(analogRead(A4));
  Serial.println(analogRead(A5));

  delay(1000);
}

(Evidently, this code is very simple but i think is correct)

Every second, I receive the same numbers from A4 and A5 pin (although I move the accelerometer)



What is wrong?

Thanks in advance for you help (I'm very very begginer)
« Last Edit: November 17, 2012, 12:05:37 pm by sergioclick » Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I don't know how connect it correctly with Ardino UNO board...

Reading the adxl345 datasheet would help you greatly.
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 39
...noob...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,a few days back i've had the same problem,
though i have arduino mega 2560,
there are two things that I would change.
solder pins to the accelerometer,

and in your code,
before void setup()
seems that I'm missing
library declaration for ADXL345

and this is how it is looking on my setup (i've dumped serial for LCD)

http://youtu.be/I8XQqrAWE_E

and this is how my code looks like (pin setting is for mega, with SDA, SCL @ 21 and 22)

Code:
#include <Wire.h>
// include the library code for ADXL345:
#include <ADXL345.h>
// include the library code for LCD:
#include <LiquidCrystal.h>

// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);


ADXL345 adxl; //variable adxl is an instance of the ADXL345 library



void setup(){
  
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  // Print a message to the LCD.
  lcd.print("Czas od resetu:");

  adxl.powerOn();
  
  
  
//code from old sample code attached to the library.
  //set activity/ inactivity thresholds (0-255)
  adxl.setActivityThreshold(75); //62.5mg per increment
  adxl.setInactivityThreshold(75); //62.5mg per increment
  adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
 
  //look of activity movement on this axes - 1 == on; 0 == off
  adxl.setActivityX(1);
  adxl.setActivityY(1);
  adxl.setActivityZ(1);
 
  //look of inactivity movement on this axes - 1 == on; 0 == off
  adxl.setInactivityX(1);
  adxl.setInactivityY(1);
  adxl.setInactivityZ(1);
 
  //look of tap movement on this axes - 1 == on; 0 == off
  adxl.setTapDetectionOnX(0);
  adxl.setTapDetectionOnY(0);
  adxl.setTapDetectionOnZ(1);
 
  //set values for what is a tap, and what is a double tap (0-255)
  adxl.setTapThreshold(50); //62.5mg per increment
  adxl.setTapDuration(15); //625μs per increment
  adxl.setDoubleTapLatency(80); //1.25ms per increment
  adxl.setDoubleTapWindow(200); //1.25ms per increment
 
  //set values for what is considered freefall (0-255)
  adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
  adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
 
  //setting all interupts to take place on int pin 1
  //I had issues with int pin 2, was unable to reset it
  adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT,    ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT,     ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT,   ADXL345_INT1_PIN );
 
  //register interupt actions - 1 == on; 0 == off  
  adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT,  1);
  adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT,   1);
  adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}

void loop(){
  
  //Boring accelerometer stuff  
  int x,y,z;  
  adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them in variables  x,y,z

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
  lcd.print(" sek");
  lcd.setCursor(0, 2);
  //prints X, Y, Z values on to LCD
  lcd.print("x:");
  lcd.print(x);
  lcd.print(" ");
  lcd.print("y:");
  lcd.print(y);
  lcd.print(" ");  
  lcd.print("z:");
  lcd.print(z);
  lcd.print(" ");  
  delay(150);

}



and the one website with great writeup I've used to get my thing to run.
http://bildr.org/2011/03/adxl345-arduino/

« Last Edit: December 09, 2012, 02:50:12 pm by he3r0 » Logged

--
HE3r0
d(R)ive safe

Offline Offline
Newbie
*
Karma: 2
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And... don't forget to solder the header pins to the break out board if you want to get meaningful readings.
Logged

Pages: [1]   Go Up
Jump to: