How to connect to the Arduino Accelerometer
This time we zaymёmsya connecting an analog three-axis accelerometer ADXL335 to the Arduino.
You will need:
- Arduino; - Accelerometer ADXL335; - PC with Arduino IDE development environment.
Instruction how to connect the accelerometer to arduino
Accelerometers are used to determine the acceleration vector. Accelerometer ADXL335 has a three-axis, and because of this it can determine the acceleration vector in three-dimensional space. Due to the fact that the force of Earth's gravity - is also a vector, an accelerometer can detect its own orientation in three-dimensional space relative to the Earth's center. The illustration shows the drawings of a passport (http://www.analog.com/static/imported-files/data_sheets/ADXL335.pdf) on the accelerometer ADXL335. It depicts the sensitivity axes of the accelerometer relative to the geometric placement of the device body in the space, and a table of voltage values from the accelerometer 3 channels depending on its orientation in space. The data in the table are for resting in a state of the sensor. Let us consider what shows us the accelerometer. Suppose sensor lies horizontally, for example on a table. Then the projection of the acceleration vector is equal to 1g for Z axis or Zout = 1g. For the remaining two axes are zero: Xout = 0 and Yout = 0. By turning the sensor "on the back", It will be sent in the opposite direction relative to the gravity vector, ie, Zout = -1g. Similar measurements are taken on all three axes. It is understood that an accelerometer may be located arbitrarily in space, so on all three channels, we will remove the non-zero readings. If the sensor is to shake strongly along the vertical Z axis, Zout value is greater than "1g". The maximum measured acceleration - "3g" for each of the axes in any direction (i.e., both "plus"And so with "minus").
I think with the principle of the accelerometer understood. Now consider the wiring diagram. analog accelerometer chip ADXL335 is quite small and placed in a BGA package, and at home it is difficult to mount on the board. Therefore, I will use a ready-made module GY-61 with the accelerometer ADXL335. These modules in the Chinese online stores are almost a dime. To power the accelerometer must be submitted at the conclusion of the module voltage VCC +3.3 V. Measuring sensor channels are connected to the Arduino analog outputs, for example, "A0". "A1" and "A2". This whole scheme :)
Load here a sketch to commemorate the Arduino. Let us read from analog input readings on three channels, convert it into a voltage and output them to the serial port. Arduino has a 10-bit ADC, and the maximum permissible voltage on the output - 5 volts. The measured voltage coded bits, which can take only two values - 0 or 1. This means that the entire measurement range is divided by (1 + 1) in the 10th degree, ie, 1024 equal segments. In order to translate the recorded readings in volts, need each measured on the analog input value is divided by 1024 (segment), and then multiply by 5 (V). Let's see what actually comes with an accelerometer on the example of the Z-axis (the last column). When the sensor is placed horizontally, and looking up, come numbers (2.03 +/- 0.01). So, it must comply with the acceleration "+ 1g" on Z axis and the angle of 0 degrees. Perevernёm sensor. Come numbers (1.69 +/- 0.01), which should correspond "-1g" and the angle of 180 degrees.
Deactivate the accelerometer values at angles of 90 and 270 degrees and zanesёm table. Table shows the angles of rotation of the accelerometer (column "A") And the corresponding values in volts Zout (column "B"). For clarity, the reduced schedule on Zout output voltages depending on the angle of rotation. Blue box - this is the range of values in the quiescent state (at 1g acceleration). Pink box on the chart - a reserve so that we can measure acceleration to + 3g and up -3g. When you turn 90 degrees to the Z-axis has to zero acceleration. Those. value of 1.67 volts - it is conditional for zero Zo axis Z. Then, you can find the acceleration: g = Zout - Zo / sensitivity_z, here Zout - measured value in millivolts, Zo - the value at zero acceleration in millivolts, sensitivity_z - sensor sensitivity axis Z. The sensitivity is shown in the passport and is an average of 300 mV / g, but generally it is better to hold the accelerometer calibration and calculate the value of sensitivity for your particular sensor according to the formula: sensitivity_z = [Z (0 deg.) - Z (90 deg.)] * 1000. In this case, the sensitivity of the accelerometer along axis Z = (2.03 - 1.68) * 1000 = 350 mV. Similarly, the sensitivity will need to count the axes X and Y. In the column "FROM" acceleration table is calculated for the five angles at a sensitivity equal to 350. As can be seen, they are practically identical to those shown in Figure 1.
Remembering the basic geometry of course, we get the formula for calculating the accelerometer rotation angles: angle_X = arctg [sqrt (Gz ^ 2 + Gy ^ 2) / Gx]. The values obtained in radians. To put them in degrees, divided by the number "pi" and multiply by 180. As a result, a complete sketch, calculating the acceleration and angle of the accelerometer rotation on all axes, is shown in the illustration. In comments given explanations to the code of the program. In the derivation of the port "Serial.print ()" symbol "\ t" It represents a tab character that the columns were smooth and values located under each other. "+" It means concatenation (connection) lines. And operator "String ()" clearly indicates to the compiler that you want to convert a numeric value into a string. Operator "round ()" It rounds the corner to within 1 degree.
So, we'll learn to shoot and process the data from analog accelerometer ADXL335 using the Arduino. Now we can use the accelerometer in their designs.