Connecting ADXL345 Pins to Arduino Uno

I have got the accelerometer breakout ADXL345 as shown in the attached photo and want to connect to Arduino Uno/Mega with the following codes. However, the pins in the code have diferent name to the one on the board. Does anyone know what would be my x, y and z acceleration output from board?
Can I do this using digital pins or has to be done through analog one?

/*
  ADXL3xx

  Reads an Analog Devices ADXL3xx accelerometer and communicates the
  acceleration to the computer. The pins used are designed to be easily
  compatible with the breakout boards from SparkFun, available from:
  http://www.sparkfun.com/commerce/categories.php?c=80

  The circuit:
  - analog 0: accelerometer self test
  - analog 1: z-axis
  - analog 2: y-axis
  - analog 3: x-axis
  - analog 4: ground
  - analog 5: vcc

  created 2 Jul 2008
  by David A. Mellis
  modified 30 Aug 2011
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/ADXL3xx
*/

// these constants describe the pins. They won't change:
const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis (only on 3-axis models)

void setup() {
  // initialize the serial communications:
  Serial.begin(9600);

  // Provide ground and power by using the analog inputs as normal digital pins.
  // This makes it possible to directly connect the breakout board to the
  // Arduino. If you use the normal 5V and GND pins on the Arduino,
  // you can remove these lines.
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW);
  digitalWrite(powerpin, HIGH);
}

void loop() {
  // print the sensor values:
  Serial.print(analogRead(xpin));
  // print a tab between values:
  Serial.print("\t");
  Serial.print(analogRead(ypin));
  // print a tab between values:
  Serial.print("\t");
  Serial.print(analogRead(zpin));
  Serial.println();
  // delay before next reading:
  delay(100);
}

That code is for an analog output sensor. The ADXL345 is interfaced using I2C or SPI. See the data sheet.

Here is a tutorial covering interfacing, sample code, calibration and link to a library for its use.

I connected them as shown in the later photos as described below.

5V from accel to 5V Arduino Mega
GND from accel to GND Arduino Mega
SCL from accel to A1 Arduino Mega
SDA from accel to A2 Arduino Mega
SD0 from accel to A3 Arduino Mega

But the problem I get fixed numbers output like this and they dont change when I move the accelerometer board:
663 0 663
663 0 663
663 0 663
663 0 663
663 0 663
663 0 662
663 0 663
663 0 663
663 0 663
663 0 663

Look at your Mega, and find the SDA and SCL pins.
It's clearly written on the board.
Hint: it's not A1 or A2 or A4 or A5.
Leo..

I saw the SDA and SCL pins and connected with correspondign pins on ADXL345. Now the SD0 from ADXL345 is not connected while I have GND and V5 also connected.

I have also modified the code as below:

// these constants describe the pins. They won't change:
const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
const int xpin = 21;                  // x-axis of the accelerometer which is also SDA from ADXL345
const int ypin = 20;                  // y-axis which is also SCL from ADXL345
const int zpin = A1;                  // z-axis (only on 3-axis models) -Not connected

but I still get this output:

367 359 363
366 359 362
365 358 361
365 358 361
365 358 361
365 359 362
365 358 361
365 358 361
365 359 361
364 358 361
365 358 361
365 358 361
365 358 361
365 359 361
364 357 360
364 358 361

Did you read the chip's datasheet.
You must be able to if you buy a product without support.

Did you tie the CS pin to 3.3volt, to force the chip in I2C mode (page 10 of the datasheet).

Did you run an I2C scanner sketch, to see if the Arduino can talk to the chip.
Leo..

I am actually getting results when uploading "SparkFun_ADXL345_Example" from the library. The connection is
5V-->5V
GND-->GND
SDA-->SDA (D2 on WiFi board)
SCL-->SCL (D1 on WiFi board)

The output is below when I change direction of board and I also get "tap"/"double tap" events.

58, 223
57, 222
*** INACTIVITY ***
57, 223
101, 170
-6, 40
6, -39
-34, -70
-49, -92
-46, -82
-51, -114
*** TAP ***
-51, -102
-58, -112
*** ACTIVITY ***
*** TAP ***
-36, -123
*** DOUBLE TAP ***
*** TAP ***
-50, -126
-55, -112
-53, -107

This is the code just in case anyone needs.

/* *********************************************

  • SparkFun_ADXL345_Example
  • Triple Axis Accelerometer Breakout - ADXL345
  • Hook Up Guide Example
  • Utilizing Sparkfun's ADXL345 Library
  • Bildr ADXL345 source file modified to support
  • both I2C and SPI Communication
  • E.Robert @ SparkFun Electronics
  • Created: Jul 13, 2016
  • Updated: Sep 06, 2016
  • Development Environment Specifics:
  • Arduino 1.6.11
  • Hardware Specifications:
  • SparkFun ADXL345
  • Arduino Uno
  • *********************************************/

#include <SparkFun_ADXL345.h> // SparkFun ADXL345 Library

/*********** COMMUNICATION SELECTION **********/
/
Comment Out The One You Are Not Using */
//ADXL345 adxl = ADXL345(10); // USE FOR SPI COMMUNICATION, ADXL345(CS_PIN);
ADXL345 adxl = ADXL345(); // USE FOR I2C COMMUNICATION

/****************** INTERRUPT *****************/
/
Uncomment If Attaching Interrupt */
//int interruptPin = 2; // Setup pin 2 to be the interrupt pin (for most Arduino Boards)

/******************** SETUP *******************/
/
Configure ADXL345 Settings */
void setup(){

Serial.begin(9600); // Start the serial terminal
Serial.println("SparkFun ADXL345 Accelerometer Hook Up Guide Example");
Serial.println();

adxl.powerOn(); // Power on the ADXL345

adxl.setRangeSetting(2); // Give the range settings
// Accepted values are 2g, 4g, 8g or 16g
// Higher Values = Wider Measurement Range
// Lower Values = Greater Sensitivity

adxl.setSpiBit(0); // Configure the device to be in 4 wire SPI mode when set to '0' or 3 wire SPI mode when set to 1
// Default: Set to 1
// SPI pins on the ATMega328: 11, 12 and 13 as reference in SPI Library

adxl.setActivityXYZ(1, 0, 0); // Set to activate movement detection in the axes "adxl.setActivityXYZ(X, Y, Z);" (1 == ON, 0 == OFF)
adxl.setActivityThreshold(75); // 62.5mg per increment // Set activity // Inactivity thresholds (0-255)

adxl.setInactivityXYZ(1, 0, 0); // Set to detect inactivity in all the axes "adxl.setInactivityXYZ(X, Y, Z);" (1 == ON, 0 == OFF)
adxl.setInactivityThreshold(75); // 62.5mg per increment // Set inactivity // Inactivity thresholds (0-255)
adxl.setTimeInactivity(10); // How many seconds of no activity is inactive?

adxl.setTapDetectionOnXYZ(0, 0, 1); // Detect taps in the directions turned ON "adxl.setTapDetectionOnX(X, Y, Z);" (1 == ON, 0 == OFF)

// Set values for what is considered a TAP and what is a DOUBLE TAP (0-255)
adxl.setTapThreshold(50); // 62.5 mg per increment
adxl.setTapDuration(15); // 625 μs per increment
adxl.setDoubleTapLatency(80); // 1.25 ms per increment
adxl.setDoubleTapWindow(200); // 1.25 ms per increment

// Set values for what is considered FREE FALL (0-255)
adxl.setFreeFallThreshold(7); // (5 - 9) recommended - 62.5mg per increment
adxl.setFreeFallDuration(30); // (20 - 70) recommended - 5ms per increment

// Setting all interupts to take place on INT1 pin
//adxl.setImportantInterruptMapping(1, 1, 1, 1, 1); // Sets "adxl.setEveryInterruptMapping(single tap, double tap, free fall, activity, inactivity);"
// Accepts only 1 or 2 values for pins INT1 and INT2. This chooses the pin on the ADXL345 to use for Interrupts.
// This library may have a problem using INT2 pin. Default to INT1 pin.

// Turn on Interrupts for each mode (1 == ON, 0 == OFF)
adxl.InactivityINT(1);
adxl.ActivityINT(1);
adxl.FreeFallINT(1);
adxl.doubleTapINT(1);
adxl.singleTapINT(1);

//attachInterrupt(digitalPinToInterrupt(interruptPin), ADXL_ISR, RISING); // Attach Interrupt

}

/****************** MAIN CODE *****************/
/
Accelerometer Readings and Interrupt */
void loop(){

// Accelerometer Readings
int x,y,z;
adxl.readAccel(&x, &y, &z); // Read the accelerometer values and store them in variables declared above x,y,z

// Output Results to Serial
/* UNCOMMENT TO VIEW X Y Z ACCELEROMETER VALUES */
Serial.print(x);
Serial.print(", ");
Serial.println(y);
// Serial.print(", ");
//Serial.println(z);

ADXL_ISR();
// You may also choose to avoid using interrupts and simply run the functions within ADXL_ISR();
// and place it within the loop instead.
// This may come in handy when it doesn't matter when the action occurs.
delay(400);
}

/********************* ISR ********************/
/
Look for Interrupts and Triggered Action */
void ADXL_ISR() {

// getInterruptSource clears all triggered actions after returning value
// Do not call again until you need to recheck for triggered actions
byte interrupts = adxl.getInterruptSource();

// Free Fall Detection
if(adxl.triggered(interrupts, ADXL345_FREE_FALL)){
Serial.println("*** FREE FALL ***");
//add code here to do when free fall is sensed
}

// Inactivity
if(adxl.triggered(interrupts, ADXL345_INACTIVITY)){
Serial.println("*** INACTIVITY ***");
//add code here to do when inactivity is sensed
}

// Activity
if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){
Serial.println("*** ACTIVITY ***");
//add code here to do when activity is sensed
}

// Double Tap Detection
if(adxl.triggered(interrupts, ADXL345_DOUBLE_TAP)){
Serial.println("*** DOUBLE TAP ***");
//add code here to do when a 2X tap is sensed
}

// Tap Detection
if(adxl.triggered(interrupts, ADXL345_SINGLE_TAP)){
Serial.println("*** TAP ***");
//add code here to do when a tap is sensed
}
}