Sei sulla pagina 1di 4

ADXL335 Accelerometer Sensor - How to Use it?

invent.module143.com/adxl335-accelerometer-sensor-how-to-use-it/

August 19, 2017

ADXL335 is accelerometer sensor which works on the principle of Piezoelectric effect.


whenever we will tilt the sensor the ball is supposed to move in that direction
because of Gravitational force. The walls are made of Piezoelectric elements. So,
every time ball is touching the wall an electric current will be produced which will be
interpreted in the form of values in any 3D space. ADXl335 is a triple axis
accelerometer i.e. it will give 3 values in output. BW is adjustable as it has single
capacitor per axis. Analog interfacing is done for communicating with other devices
like Arduino.

Where to use?
We can use this compact device in any motion detection oriented projects, gesture
control robots, smart phones, smart watches etc.

Application:
http://invent.module143.com/arduino-gesture-robot-using-adxl335/

http://invent.module143.com/earthquake-detector-using-arduino/

Project for Reference:

1/4
Code:
Arduino

2/4
1 const int xpin = A1; // x-axis of the accelerometer
2 const int ypin = A2; // y-axis
3 const int zpin = A3; // z-axis (only on 3-axis models)
4 //
5 int sampleDelay = 500; //number of milliseconds between readings
6 void setup()
7 {
8 // initialize the serial communications:
9 Serial.begin(9600);
10 //
11 //Make sure the analog-to-digital converter takes its reference voltage
12 from
13 // the AREF pin
14 pinMode(xpin, INPUT);
15 pinMode(ypin, INPUT);
16 pinMode(zpin, INPUT);
17 }
18 void loop()
19 {
20 int x = analogRead(xpin);
21 //
22 //add a small delay between pin readings. I read that you should
23 //do this but haven't tested the importance
24 delay(1);
25 //
26 int y = analogRead(ypin);
27 //
28 //add a small delay between pin readings. I read that you should
29 //do this but haven't tested the importance
30 delay(1);
31 //
32 int z = analogRead(zpin);
33 //
34 //zero_G is the reading we expect from the sensor when it detects
35 //no acceleration. Subtract this value from the sensor reading to
36 //get a shifted sensor reading.
37 float zero_G = 512.0;
38 //
39 //scale is the number of units we expect the sensor reading to
40 //change when the acceleration along an axis changes by 1G.
41 //Divide the shifted sensor reading by scale to get acceleration in Gs.
42 float scale = 102.3;
43 //
44 Serial.print(((float)x - zero_G)/scale);
45 Serial.print("\t");
46 //
47 Serial.print(((float)y - zero_G)/scale);
48 Serial.print("\t");
49 //
50 Serial.print(((float)z - zero_G)/scale);
51 Serial.print("\n");
52 //
53 // delay before next reading:
54 delay(sampleDelay);
}

3/4
Serial Monitor Output:

4/4

Potrebbero piacerti anche