Introduction: Interfacing ADXL335 With ARDUINO

Picture of Interfacing ADXL335 With ARDUINO

As the datasheet says, ADXL335 is a small, thin, low power, complete 3-axis accelero-meter with signal conditioned voltage outputs. The product measures acceleration with a minimum full-scale range of ±3 g. It can measure the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration. 
ADXL335 is 3v3 compatible device, it's powered by a 3.3v source and also generates 3.3v peak outputs. It has three outputs for each axis i.e. X, Y & Z. These are analog outputs and thus require an ADC in a micro-controller. Arduino solves this problem. We will be using the analog functions of Arduino.

Step 1: Parts Required

Picture of Parts Required
  1. Arduino-Any Arduino/clone will do but I have used Freeduino v1.16
  2. ADXL335 accelerometer
  3. Connecting wires(Relimates)
  4. USB cable for connecting Arduino with your Laptop

Step 2: The Circuit

Picture of The Circuit
The accelerometer module has 5 pins, namely
  1. GND-To be connected to Arduino's GND
  2. VCC-To be connected to Arduino's 5V
  3. X-To be connected to Analog Pin A5
  4. Y-To be connected to Analog Pin A4
  5. Z-To be connected to Analog Pin A3
NOTE: We don't need to power the module from 3.3v because it already has a 5v to 3.3v converter.
Use 2-pin relimate for connecting Vcc and GND.
Use a 3-pin relimate for connecting X, Y & Z outputs.
Also connect AREF pin to the 3.3v. This is done to set the reference voltage to 3.3v because the output of ADXL335 is 3.3v compatible.

Step 3: Code

Picture of Code




//connect 3.3v to AREF


const int ap1 = A5; 
const int ap2 = A4;
const int ap3 = A3;

int sv1 = 0;        
int ov1 = 0;    
int sv2 = 0;      
int ov2= 0;      
int sv3 = 0;       
int ov3= 0;      

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
 
}

void loop() {
  analogReference(EXTERNAL);    //connect 3.3v to AREF
  // read the analog in value:
  sv1 = analogRead(ap1);            
  // map it to the range of the analog out:
  ov1 = map(sv1, 0, 1023, 0, 255);  
  // change the analog out value:
  delay(2);                     
  //
  sv2 = analogRead(ap2);            
  
  ov2 = map(sv2, 0, 1023, 0, 255); 
 // 
  delay(2);                 
  //
  sv3 = analogRead(ap3);            
  
  ov3 = map(sv3, 0, 1023, 0, 255);  
  
  // print the results to the serial monitor:
  Serial.print("Xsensor1 = " );                       
  Serial.print(sv1);      
  Serial.print("\t output1 = ");      
  Serial.println(ov1);   
 
  Serial.print("Ysensor2 = " );                       
  Serial.print(sv2);      
  Serial.print("\t output2 = ");      
  Serial.println(ov2);   

  Serial.print("Zsensor3 = " );                       
  Serial.print(sv3);      
  Serial.print("\t output3 = ");      
  Serial.println(ov3);   

  delay(3000);                     
  
}

Step 4: Serial Monitor

Picture of Serial Monitor

We will be displaying two different values for one analog value read. The first value is the ADC converted value in 10-bit resolution(0 to 1023) while the second one is mapped for PWM and it is in 8-bit resolution(0 to 255).
Three values for X, Y & Z axes are displayed together are repeated after an interval of 3 seconds.

Comments

HrithuO (author)2017-07-23

Hello, is there a reason you are mapping the 10bit analog input to an 8 bit value( 0 -255)? What can I use the converted value for that is not possible with the 10 but value?

I am really need to this and dont understand why the conversion is made and over all how to use it in other projects as well. Please help me

Hassan Imam (author)2017-06-12

Hello, this can give two output and i want to encode this output and send to transmitter so which output i use to send encocder which one from this xSensor1=404 or output1=100

AnsariA5 (author)2017-03-16

can you provide a code by which i can turn on a buzzer as a result of the accelerometer's movement

Vivek Vikash (author)2017-01-18

I am using ArduinoDroud to write the above given code but it shows error when I vompile it. Can u please help me out

RishikeshC (author)2016-07-29

I am doing a project which involves using the speed of a motor so how do I find the acceleration of the motor using ADXL335

greatidea (author)2015-02-11

Hi man,

Can you tell how can I measure the three axis orientation in degrees? I'm using MPU-6050 sensor.

Also, how much is the cost in INR of the ADXL335 accelerometer that you are using?

apoorveinstein (author)greatidea2016-05-17

Hey,
You'll have to refer the datasheet for MPU-6050 sensor.
And I bought ADXL335 for around INR 350-400.

SaifL1 made it! (author)2016-05-13

Still didn't quite understand why to connect 3.3v to AREF but, pretty happy it worked

apoorveinstein (author)SaifL12016-05-17

As I've already mentioned, it is to provide reference voltage of 3.3v. Although the module is powered by 5v but the output is only compatible to 3.3v.

pkisfaludi made it! (author)2015-09-28

Thx a lot, got it working in 10mins!

Kudos!

Kudos!

aswinth (author)2015-06-04

Plz help..
I have a accel. with 6 pins on it. The pin reads as
1->vcc
2->gnd
3->st
4->z
5->y
6->x

I connected xyz as you mentioned, i connected vcc to 5v and ground to ground. I also connected st to 3v3. when i powered on my kit i got a burnt smell and found my ic on accel to be very hot. hence powered it down.
My kit works fine, would my accel. have got damaged?
what should i do now?

dyoudal (author)2015-05-23

check out:http://www.analog.com/media/en/technical-documentation/application-notes/AN-1057.pdf for degrees

vvardhan5 (author)2015-02-12

the values your getting are just analog values of 8 bit but not the exert values of ADXL335 your not considering any logic or any formula to get the actual value use this formula x=(value_x/1024.0*ADC_ref-zero_x)/sensitivity_x; y=(value_y/1024.0*ADC_ref-zero_y)/sensitivity_y; z=(value_z/1024.0*ADC_ref-zero_z)/sensitivity_z; refer data sheet of ADXL335 for zero value of x,y,z using these formula you will get the coordinate but still you have to use kalman filter equations to get the accurate value

powersource (author)2014-12-24

Nice bro! This helped me a lot!

ramesh.panchadhi.1 (author)2014-09-26

Fine i'm getting the output but what are the values and how can i convert to acceleration(in m/s^2)..??
thanks in advance...

About This Instructable

140,155views

47favorites

Bio: An electronics enthusiast... #Complexity simplified
More by apoorveinstein:Interfacing 20x4 LCD with ArduinoHome Automation using BluetoothInterfacing ADXL335 with ARDUINO
Add instructable to: