Description
Ever wondered how your smartphone knows up from down! It’s one of the coolest features of today’s smartphones. They all got a tiny device called Accelerometer built into the circuitry which can sense when you tilt it from side to side. That’s how your smartphone automatically figures out when to switch the screen layout from portrait to landscape.
Sensor Chip: ADXL335.
Operating voltage: 3V-5V.
Interface: Analogue output.
Operating temperature: -40 +85.
X, Y, Z output
Three-axis accelerometer module magnetic field.
Getting started with the ADXL335 Module 3-axis Analog Output Accelerometer angular transducer
This tutorial shows you how to read from the ADXL335 accelerometer and receive the values in the serial monitor of the Arduino Software (IDE) or another application that receives data over the serial port.
Step1: Hardware required
ADXL335 Accelerometer Pinout
Before diving into hookup and example code, let’s first take a look at its Pinout.
Step2: Connecting the Hardware
Connections are pretty easy. Start by placing the accelerometer on to your breadboard. Connect VCC pin to the 5V pin on the Arduino and connect GND pin to the Ground pin on the Arduino. Also connect X, Y and Z output to the analog pins A0, A1 and A2 on Arduino.
For accurate results, we need to change the analog reference(AREF) voltage of the Arduino. This can be done by connecting the 3.3V pin on Arduino to the AREF pin.
When you’re done you should have something that looks similar to the illustration shown below.
Step3: Upload the sample sketch
/*
ADXL3xx
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from SparkFun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80
The circuit:
- analog 0: accelerometer self test
- analog 1: z-axis
- analog 2: y-axis
- analog 3: x-axis
- analog 4: ground
- analog 5: vcc
created 2 Jul 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/ADXL3xx
*/
// these constants describe the pins. They won't change:
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
void setup() {
// initialize the serial communications:
Serial.begin(9600);
// Provide ground and power by using the analog inputs as normal digital pins.
// This makes it possible to directly connect the breakout board to the
// Arduino. If you use the normal 5V and GND pins on the Arduino,
// you can remove these lines.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop() {
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
// delay before next reading:
delay(100);
}
NOTE: If you get stray ‘223’ in program the problem is with your “and” characters .Replace them with ordinary quotes “. And you should be fine.
Step4: Testing the circuit
Following image shows the accelerometer output on serial monitor at different positions.