You are on page 1of 7

Simple angle meter using ADXL335 accelerometer [Arduino] | electronicsblog.

net

electronicsblog.net
Just another electronics blog

HOME

ABOUT

CONTACT

Simple angle meter using ADXL335


accelerometer [Arduino]

CATEGORIES

Arduino (15)
ARM (1)

67 Comments

Atmega328 (1)
Atmega8 (1)
ATtiny13 (1)
Other (1)
Software (1)
Uncategorized (2)

TAGS

7 segments 16

bit

timer ADC analog


comparator

ADXL335 is 3 axis accelerometer with analog output from Analog


Devices. You can buy it as an evaluation kit with standard 2,5 mm
connector.

Arduino

Atmega8 bin buzzer calculator


capacitance capacitor clock
communication conversion
countdown counter display
download Ebay FM free freeware
GPS GPS module hex IC

interrupt LCD

High Voltage
Tester AC|DC
manual and automatic HiPot
testers perfect technology and
https://www.electronicsblog.net/simple-angle-meter-using-adxl335-accelerometer-arduino/[4/19/2015 10:48:03 AM]

LED meter multiplexing


NMEA

PWM radio RC register

RS232 serial port Sirf


II TEA5767 timer UART
resistor

visual c++ windows

RECENT COMMENTS

Simple angle meter using ADXL335 accelerometer [Arduino] | electronicsblog.net

good prices
Darius on Simple angle meter
using ADXL335 accelerometer
[Arduino]
Dale. on Simple angle meter
using ADXL335 accelerometer

ADXL335 acceleration measurement range is +/- 3 g. Supply voltage is

[Arduino]

1.8 3.6 V, however all specifications at the datasheet is given at 3.0 V.

Darius on Simple angle meter

This accelerometer has 3 outputs for X,Y,Z axis which voltage is

using ADXL335 accelerometer

proportional to acceleration on specific axis.

[Arduino]
Shashank on Simple angle

At midpoint when acceleration is 0 g output is typically 1/2 of supply

meter using ADXL335

voltage. If a supply voltage is 3V, then output is 1.5 V. Output sensitivity

accelerometer [Arduino]

typically is 300 mV/g.

Darius on Reading
temperature from LM92 digital

The connecting ADXL335 to Arduino board is simple. The accelerometer

sensor with Arduino

can be supplied from the 3.3 V output at Arduino board, however then
midpoint voltage and sensitivity is different from specified at datasheet. I
used 3.0 V supply voltage, it came from voltage regulator LM317.

RECENT POSTS

Outputs of X,Y,Z axis are connected directly to analog inputs of Arduino.

Arduino based Temperature


and Humidity/Humidex meter
with DHT22 sensor and color
LCD
Reading temperature from
LM92 digital sensor with
Arduino
How to connect to diagnostics
port of AC Stag gas controllers
without special cable
STM32F4DISCOVERY great
board for starting learn ARM
microcontrollers

R1 is 2.7k resistor, while R2 is variable 10k resistor. Please adjust R2 to

Atmega328 Development Kit

have 3.0 V output at LM317 before connecting ADXL335 board.


Connect the board and adjust again, because output voltage will drop
since load is connected. If readings of theacceleration are unstable

LINKS

please connect additional capacitor between VSS and COM.


EEWeb Electronics Forum

An accelerometer can be used not only measure acceleration, but also


orientation. Its because accelerometer sense the force of gravity which is
pointed to the center of earth.
https://www.electronicsblog.net/simple-angle-meter-using-adxl335-accelerometer-arduino/[4/19/2015 10:48:03 AM]

Simple angle meter using ADXL335 accelerometer [Arduino] | electronicsblog.net

This is how sensing axis are orientated to ADXL335 (images from


ADXL335 datasheet)

Readings from X,Y,Z axis reflects an orientation of an accelerometer.

https://www.electronicsblog.net/simple-angle-meter-using-adxl335-accelerometer-arduino/[4/19/2015 10:48:03 AM]

Simple angle meter using ADXL335 accelerometer [Arduino] | electronicsblog.net

Interesting that if a direction of sensing axis match to gravity direction


measurement result is negative (-1 g).
Lets start with an Arduino program. This program not only sends
readings of acceleration from 3 axis via serial port, but also calculates
rotation of the accelerometer around X, Y, Z, axis.
1
2
3
4
5
6
7
8
9
10
11
12
13

#define

#define

#define

#define

#define

#define

#define

ADC_ref 2.56
zero_x 1.569
zero_y 1.569
zero_z 1.569
sensitivity_x 0.3
sensitivity_y 0.3
sensitivity_z 0.3

ADC reference voltage is 2.56 V. Default on board 5V is not selected


because is slightly lower then 5.0 V and can be unstable. 0 g voltage
after some simple calibration is set to be 1.569 V. The sensitivity for
calculations is used as default 300 mV/g.
1
2
3
4
5
6
7

void setup() {

analogReference(INTERNAL2V56);

Serial.begin(256000);

Setting the ADC reference to 2.56 V and starting serial communication.


void loop() {
1
2
3

value_x = analogRead(0);
value_y = analogRead(1);
value_z = analogRead(2);

At the loop A/D conversions are performed for each of 3 channels.


https://www.electronicsblog.net/simple-angle-meter-using-adxl335-accelerometer-arduino/[4/19/2015 10:48:03 AM]

Simple angle meter using ADXL335 accelerometer [Arduino] | electronicsblog.net

xv=(value_x/1024.0*ADC_ref-zero_x)/sensitivity_x;

The acceleration is calculated at this line.


1

angle_z =atan2(-yv,-xv)*57.2957795+180;

The rotation(for Z axis) is calculated using atan2 function. It calculates


angle from length of X, Y vectors. *57.2957795 is conversation of
radian to degree. +180 is for offset.
Full code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

// Simple angle meter using ADXL335 accelerometer


//from electronicsblog.net/

#define ADC_ref 2.56

#define zero_x 1.569

#define zero_y 1.569

#define zero_z 1.569

#define sensitivity_x 0.3

#define sensitivity_y 0.3

#define sensitivity_z 0.3

unsigned int value_x;


unsigned int value_y;
unsigned int value_z;

float xv;
float yv;
float zv;

float angle_x;
float angle_y;
float angle_z;

void setup() {

analogReference(INTERNAL2V56);

Serial.begin(256000);

void loop() {

value_x = analogRead(0);
value_y = analogRead(1);
value_z = analogRead(2);

xv=(value_x/1024.0*ADC_ref-zero_x)/sensitivity_x;

Serial.print ("x= ");

https://www.electronicsblog.net/simple-angle-meter-using-adxl335-accelerometer-arduino/[4/19/2015 10:48:03 AM]

Simple angle meter using ADXL335 accelerometer [Arduino] | electronicsblog.net

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

Serial.print (xv);
Serial.print(" g ");

yv=(value_y/1024.0*ADC_ref-zero_y)/sensitivity_y;

Serial.print ("y= ");


Serial.print (yv);
Serial.print(" g ");

zv=(value_z/1024.0*ADC_ref-zero_z)/sensitivity_z;

Serial.print ("z= ");


Serial.print (zv);
Serial.print(" g ");

Serial.print("\n");

Serial.print("Rotation ");

Serial.print("x= ");

angle_x =atan2(-yv,-zv)*57.2957795+180;

Serial.print(angle_x);
Serial.print(" deg");
Serial.print(" ");

Serial.print("y= ");

angle_y =atan2(-xv,-zv)*57.2957795+180;

Serial.print(angle_y);
Serial.print(" deg");
Serial.print(" ");

Serial.print("z= ");

angle_z =atan2(-yv,-xv)*57.2957795+180;

Serial.print(angle_z);
Serial.print(" deg");
Serial.print("\n");

delay(1000);
delay(1000);
}

And the demonstration of program in the video below.

Navigation to the webpage was canceled

What you can try:

Retype the address.

https://www.electronicsblog.net/simple-angle-meter-using-adxl335-accelerometer-arduino/[4/19/2015 10:48:03 AM]

Simple angle meter using ADXL335 accelerometer [Arduino] | electronicsblog.net

This entry was posted in Arduino and tagged A/D, ADXL335, Arduino on July
17, 2011.

Start with IAR Embedded


Workbench for Atmel AVR: Attiny13
LED blink with timer interrupt

Arduino and ultra sonic range


measurement module or how to
measure the pulse time with a
hardware timer and an interrupt

Proudly powered by WordPress

https://www.electronicsblog.net/simple-angle-meter-using-adxl335-accelerometer-arduino/[4/19/2015 10:48:03 AM]

You might also like