Interfacing ADXL335 with Arduino

Measurement of acceleration can help us in doing some really interesting projects. In embedded systems this task is performed by electronic devices called accelerometers. An accelerometer does not only give you information about how faster an object is moving but serve as an indicator for the occurrence of natural events like a fall or a tilt. This tutorial will help you with interfacing ADXL335 accelerometer with Arduino.

Introduction to Arduino

Arduino is a very popular open source platform for engineers, students or hobbyists to develop electronic projects. It consists hardware and software. The hardware is a single-board microcontroller and the software is an Integrated Development Environment(IDE) that helps you program the microcontroller and test your projects. There are other products from Arduino that seamlessly integrate with the boards. You can find out more about Arduino from this article - What-is-Arduino,-How-to-Start-With-Arduino.

ADXL335

ADXL335 is a tripple axis accelerometer. Tipple axis in the sense that it can measure acceleration along three axes viz x, y and z. The measured values appear as change in voltage at three output pins with respect to a common ground. The sensor measures acceleration with the help of a layer of polysilicon suspended above silicon wafer with the help of polysilicon springs. The motion of this mass is translated into the motion of the plates of a differential capacitor and thereby providing an output proportional to acceleration.

ADXL 335 pinout

                            Pinout of ADXL335

The pinout of ADXL335 IC is given above. The pinout has more pins than what one would find in a commercially available product. One would be familiar with the three output pins and the pins for VCC and GND. The ST pin helps in doing a self-test of the accelerometer. When a small voltage of less than 3.6V is applied on the pin output of the accelerometer is affected due to the generation of electrostatic force. It is left open circuit like the No Connection(NC) pins. The COM pins are common ground which are generally short-circuited.

Requirements

1. Any Arduino

2. ADXL335

3. Connecting wires (Make sure they are not too short)

4. USB cable

Components for interfacing ADXL335 with arduino

                                     Components to Interface ADXL335 with Arduino

Steps for interfacing ADXL335 with Arduino

Step 1:- Connecting the pins

The three output pins of accelerometer give analog output and should therefore be connected to the analog input pins of your Arduino. Lets take A0, A1 and A2. Now, look at the power pins. Connect the VCC pin of the accelerometer to the 5V pin of the Arduino. Connect GND of accelerometer to the GND of Arduino. Set the reference voltage of ADC as 3.3V by connecting the AREF pin to 3.3V so as to match the output of ADXL335.

Step 2:- Writing the program

Programming Arduino is very simple and straightforward. Our program will take shape in three steps. First, we shall initialize variables. Next, we call any function that initializes any process. they will be executed only once. Finally, we call the functions that perform the tasks in our project. They are given inside an infinite loop so that they are executed again and again.

Interfacing ADXL 335 with Arduino

                                           Interfacing Diagram of ADXL335 with Arduino

Step 2.1:-Initializing the variables

First, we need three input variables. Let us name them "xout", "yout" and "zout". We will assign the values at the analog input pins of Arduino to these pins.

const int xout = A0;

const int yout = A1;

const int zout = A2;

We will assign three output variables so that we can display the values at the analog input pins on the serial monitor. Three more variables can be used if we want to scale the values to our liking.

int out1 = 0;       

int sout1 = 0;   

int out2 = 0;     

int sout2= 0;     

int out3 = 0;      

int sout3= 0;

Step 2.2:- Initialize serial communication

void setup() {

Serial.begin(9600);

}

The argument of the absolute function is the Baud rate.

Step 2.3 :- The loop

First, we shall read the analog values using the analogread() function. While we read values ADC of Arduino works under the hood and converts the values into digital format.

void loop() {

  analogReference(EXTERNAL);

  out1 = analogRead(xout);           

  sout1 = map(out1, 0, 1023, 0, 255); 

  delay(2);                    

  out2 = analogRead(yout);           

  sout2 = map(out2, 0, 1023, 0, 255);

  delay(2);                

  out3 = analogRead(zout);           

  sout3 = map(out3, 0, 1023, 0, 255); 

  Serial.print("X = " );                      

  Serial.print(out1);     

  Serial.print("\t output1 = ");     

  Serial.println(sout1);  

  Serial.print("Y = " );                      

  Serial.print(out2);     

  Serial.print("\t output2 = ");     

  Serial.println(sout2);  

  Serial.print("Y = " );                      

  Serial.print(out3);     

  Serial.print("\t output3 = ");     

  Serial.println(sout3);  

  delay(3000);                    

}

Step 3:- Uploading the code

How to interface ADXL 335 with Arduino

                               Program code to interface ADXL335 with Arduino

To upload the code connect your Arduino to your PC using the USB connector and click on the upload button on the top of the Arduino IDE window. Click on the serial monitor icon on the top right corner and you can see the accelerometer readings.

You can make use of these readings in your project.

User Review (0)
Related Items