Search This Blog

Saturday 12 October 2013

GY-61 Accelerometer setup and test

The GY-61 is a small board based on the ADXL-335 Chip. There are several similar boards available (see below) and they should operate in much the same way.


The Pins on the GY-61 are:
  • Vcc - 3.3V - Red
  • Xout - A0 - White
  • Yout - A1 - Yellow
  • Zout - A2 - Blue
  • GND - GND - Black

About the Sensors

Three sensors are at right angles to one another and measure the acceleration in each of three axes. According to the datasheet for the ADXL-335 they can measure accelleration up to a minimum of +/- 3 g (where 1 g is approximately the equivalent of the acceleration due to gravity on the earth's surface). The sensor outputs an analogue signal for each of the three axes, the voltage is linearly proportional to the acceleration, with 0V being the maximum negative value. The sensor accepts a wide range of supply voltage from 1.8 to 5V, but is designed for 3.3V, so that's what I used.

As each sensor is different they will need some calibration before use. I couldn't figure out a way to reliably calibrate it automatically, but I have a method that you can use to calculate the range and offsets using a calibration sketch and these values can then be use for more practical applications, or you could have a calibration on start up.

The sensor has a Self Test facility and some breakout boards have a pin marked ST (on the GY-61 there isn't a pin, but there is a hole on the board to the left of the sensor in the picture above). The ST will exercise the accelerometers to their maximum values. I am not really sure how useful this would be for calibration if you do not know what that maximum actually represents.

Wiring it up

Wiring up the sensor is simple. The Frizting diagram below shows how. Fritzing has an ADXL-335 version which has slightly different pin arrangement than the GY-61. The analogue accellerometer outputs are connected to the Arduino analogue inputs, X to A0, Y to A1 and Z to A2. The Arduino 3.3V output is used to provide power to Vcc and the GND is connected to ground.

For the analogue inputs the Arduino uses a reference voltage to convert the input voltage to a value. Normally this is the internal 5V supply. Because we are powering the sensor from the 3.3V we need to provide a reference voltage by feeding the 3.3V into the Arduino AREF input.

 

Calibration

Calibration is based around the assumption that the sensor response is linearly proportional to the accelleration, and that we know three values of accelleration for which we can measure the sensor response on each of the axes.

When the sensor is at rest, positioned flat on a horizontal surface then the Z axis will be measuring the force of gravity - 1g - and the X and Y sensors will each be measuring zero. If we then flip the sensor upside-down we can measure negative 1g on the Z axis. The sensor can be rotated so that each of the axes is in turn parallel to the force of gravity and a reading for zero acceleration, 1g and -1g obtained for each axis.

So for example, when at rest and powered with 3.3V the sensors give analogue readings of:
  • X (0g) - 516
  • Y (0g) - 506
  • Z (1g) - 619
With the sensor upside down:
  • Z (-1g) - 416
With three points we can then use a linear equation to extrapolate the maximum and minimum values using the formula:

y = mx + c

Where m is the slope of the line and c is the intercept - the value on the y axis when x is zero, which you can see from the readings above, is about 510. y is the sensor reading and x is the acceleration.

With readings taken from the 6 different orientations and plotted onto a graph it is reassuring to see that the relationship does appear to be linear as shown below:




Parts

The part I used was the GY-61, which you can buy from Amazon (link below left). There are plenty of other breakout boards for the ADXL-335 on Amazon and your favourite online hobby electronics website.

2 comments:

  1. When you made reference to analog output readings in what type of analog.
    4-20ma (12 bit 16 bit) 0-5 volts. Were are you getting these readings from?

    ReplyDelete
  2. Thanks for sharing this, was helpfull.

    ReplyDelete