Basic measurement with accelerometer GY-61 with ADXL335 chip

With this module, you can measure:

1. acceleration (= speed of movements) in three directions x, y, z;
2. a rotation or an angles (in three directions);
3. orientation

In this program, there is only a simple basic measurement of an angle in one direction, just to show how this works.

I also made use of the possibility to use an analog-ports as an output to put VCC (5V) and GND (0V) on the GY-61-module (see picture A0 = VCC and A4 = GND).

This is simple code to show an angle on the serial monitor:

``` // This is a simple working-example to quick measuring: // 1. the x, y and z-values read from a GY-61-acceleration-module // 2. an angle in eg. the x-direction```

// You can put the module in 4 directions to determine the min-max-values:
// –>   0deg   x = 349  y = 341  z = 425
// /\    90deg  x = 281  y = 345  z = 357
// <–  180deg  x = 350  y = 345  z = 288
//  V   270deg  x = 419  y = 341  z = 355
// This can be used to measure degrees

// you can use all the analog inputs to control the GY-61
const int VCCPin = A0;
const int xPin   = A1;
const int yPin   = A2;
const int zPin   = A3;
const int GNDPin = A4;

// variables
int x = 0;
int y = 0;
int z = 0;

void setup() {
// pin A0 (pin14) is VCC and pin A4 (pin18) in GND to activate the GY-61-module
pinMode(A0, OUTPUT);
pinMode(A4, OUTPUT);
digitalWrite(14, HIGH);
digitalWrite(18, LOW);

// activating debugging for arduino UNO
Serial.begin(9600);
} // end setup

void loop() {
// show x, y and z-values
Serial.print(“x = “);
Serial.print(x);
Serial.print(”  y = “);
Serial.print(y);
Serial.print(”  z = “);
Serial.print(z);
// show angle
Serial.print(”  angle = “);
Serial.println(constrain(map(x,349,281,0,90),0,90));
} // end loop

To find further information, on rotation and acceleration, check other sites: