0% found this document useful (0 votes)
108 views4 pages

Arduino Adxl335 Accelerometer Interfacing With Arduino Uno

This document discusses interfacing an ADXL335 accelerometer module with an Arduino Uno board. It provides an introduction to accelerometers and the ADXL335, shows the interfacing diagram and connections between the module and Arduino, and includes an example code to read acceleration values from the accelerometer and calculate the roll and pitch, outputting the results to the serial monitor. It also provides a link to download the source code.

Uploaded by

ede
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
108 views4 pages

Arduino Adxl335 Accelerometer Interfacing With Arduino Uno

This document discusses interfacing an ADXL335 accelerometer module with an Arduino Uno board. It provides an introduction to accelerometers and the ADXL335, shows the interfacing diagram and connections between the module and Arduino, and includes an example code to read acceleration values from the accelerometer and calculate the roll and pitch, outputting the results to the serial monitor. It also provides a link to download the source code.

Uploaded by

ede
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

6/25/2020 Arduino Adxl335 Accelerometer Interfacing With Arduino Uno | Ardu...

ADXL335 Accelerometer Interfacing with Arduino Uno

Introduction

ADXL335 Accelerometer Module

Accelerometer is an electromechanical device that measures the force of acceleration due to gravity in g unit.

It can be used in applications requiring tilt sensing.

The ADXL335 measures acceleration along X, Y and Z axes and gives analog voltage output proportional to the
acceleration along these 3 axes.

Microcontrollers can process these voltages by converting them to digital signals using ADC.

For more information about ADXL335 accelerometer and how to use it, refer the topic ADXL335
Accelerometer Module in the sensors and modules section.

Interfacing Diagram

https://www.electronicwings.com/arduino/adxl335-accelerometer-interfacing-with-arduino-uno 1/4
6/25/2020 Arduino Adxl335 Accelerometer Interfacing With Arduino Uno | Ardu...

Interfacing ADXL335 Accelerometer Module With Arduino UNO

Example
Finding the roll and pitch of the device using analog voltages of accelerometer module and displaying them on
serial monitor of Arduino .

Sketch

https://www.electronicwings.com/arduino/adxl335-accelerometer-interfacing-with-arduino-uno 2/4
6/25/2020 Arduino Adxl335 Accelerometer Interfacing With Arduino Uno | Ardu...

#include <math.h>
const int x_out = A1; /* connect x_out of module to A1 of UNO board */
const int y_out = A2; /* connect y_out of module to A2 of UNO board */
const int z_out = A3; /* connect z_out of module to A3 of UNO board */

void setup() {
Serial.begin(9600);
}

void loop() {
int x_adc_value, y_adc_value, z_adc_value;
double x_g_value, y_g_value, z_g_value;
double roll, pitch, yaw;
x_adc_value = analogRead(x_out); /* Digital value of voltage on x_out pin */
y_adc_value = analogRead(y_out); /* Digital value of voltage on y_out pin */
z_adc_value = analogRead(z_out); /* Digital value of voltage on z_out pin */
Serial.print("x = ");
Serial.print(x_adc_value);
Serial.print("\t\t");
Serial.print("y = ");
Serial.print(y_adc_value);
Serial.print("\t\t");
Serial.print("z = ");
Serial.print(z_adc_value);
Serial.print("\t\t");
//delay(100);

x_g_value = ( ( ( (double)(x_adc_value * 5)/1024) - 1.65 ) / 0.330 ); /* Acceleration in


y_g_value = ( ( ( (double)(y_adc_value * 5)/1024) - 1.65 ) / 0.330 ); /* Acceleration in
z_g_value = ( ( ( (double)(z_adc_value * 5)/1024) - 1.80 ) / 0.330 ); /* Acceleration in

roll = ( ( (atan2(y_g_value,z_g_value) * 180) / 3.14 ) + 180 ); /* Formula for roll */


pitch = ( ( (atan2(z_g_value,x_g_value) * 180) / 3.14 ) + 180 ); /* Formula for pitch *
//yaw = ( ( (atan2(x_g_value,y_g_value) * 180) / 3.14 ) + 180 ); /* Formula for yaw */
/* Not possible to measure yaw using accelerometer. Gyroscope must be used if yaw is also required */

Serial.print("Roll = ");
Serial.print(roll);
Serial.print("\t");
Serial.print("Pitch = ");
Serial.print(pitch);

https://www.electronicwings.com/arduino/adxl335-accelerometer-interfacing-with-arduino-uno 3/4
6/25/2020 Arduino Adxl335 Accelerometer Interfacing With Arduino Uno | Ardu...

Serial.print("\n\n");
delay(1000);
}

Video

Supporting Files

Source Code
Accelerometer_Interfacing_With_Arduino_INO Download 1127

https://www.electronicwings.com/arduino/adxl335-accelerometer-interfacing-with-arduino-uno 4/4

You might also like