Basics project 120a Accelerometer ADXL335


Basics: Project 120a

Project name:  Accelerometer ADXL335

Tags: Arduino, Arduino Nano, ADXL335, accelerometer, MEMS

Attachments: calibration sketch, sketchwithoutcalibration

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1. ADXL335 1 pc

ADXL335
ADXL335
ADXL335

2. Jumper cables  F-M 6 pcs, jumper cables M-M 6 pcs, jumper cables F-F 1 pc

jumper cables

3. Arduino Nano and Mini-B USB cable 1 pc

ARDUINO NANO

4. Resistor 220 Ohm 1pc (for calibration)

resistor 220 ohm

5. Momentary switch (pushbutton) 1 pc (for calibration)

pushbutton

6. Breadboard 1 pc

Breadboard

General

We will learn about the ADXL335 and how to use it with Arduino Nano.

Accelerometers are widely used in cost sensitive, low power, motion and tilt sensing applications like Mobile devices, Gaming systems, Disk drive protection, Image stabilization and Sports & health devices.

What is Acceleration?

The brilliant scientist Isaac Newton in his second law of motion defined acceleration by relating it to mass and force. If you have a certain force (say, the power in your leg as you kick it outward) and you apply it to a mass (a soccer ball), you’ll make the mass accelerate (the ball will shoot off into the air).

Force = Mass x Acceleration

Acceleration = Force / Mass

In other words, acceleration is the amount of force we need to move each unit of mass.

How Accelerometer Works?

To know how accelerometers work, it is often useful to imagine a ball inside a 3D cube. Suppose, the cube is in outer-space where everything is in weightless state, the ball will simply float in the middle of the cube. Now let’s imagine each wall represents particular axis.

Accelerometer

If we suddenly move the box to the left with acceleration 1g(A single G-force 1g is equivalent to gravitational acceleration 9.8 m/s2), no doubt the ball will hit the wall X. If we measure the force that the ball applies to the wall X, we can get an output value of 1g on the X axis.

Accelerometer

Let’s see what happens if we put that cube on Earth. The ball will simply fall on the wall Z and will apply a force of 1g, as shown in the picture below:

 Accelerometer

In this case the box isn’t moving but we still get a reading of 1g on the Z axis. This is because the gravitational force is pulling the ball down with force 1g.

The accelerometer measures the static acceleration of gravity in tilt-sensing applications as well as dynamic acceleration resulting from motion, shock, or vibration.

How MEMS Accelerometer Works?

MEMS(Micro Electro Mechanical Systems) accelerometer consists of a micro-machined structure built on top of a silicon wafer.

MEMS Accelerometer
MEMS Accelerometer

This structure is suspended by polysilicon springs. It allows the structure to deflect at the time when the acceleration is applied on the particular axis. Due to deflection the capacitance between fixed plates and plates attached to the suspended structure is changed. This change in capacitance is proportional to the acceleration on that axis. The sensor processes this change in capacitance and converts it into an analog output voltage.

Understanding the Arduino Nano

You can read more about it here.

Understanding the ADXL335

In the middle of the module there is a small, low power triple axis MEMS accelerometer with extremely low noise – ADXL335. The sensor has a full sensing range of ±3 g. It can measure the static acceleration due to gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration.

ADXL335

The sensor works on power between 1.8V to 3.6VDC (3.3V optimal), and typically consumes just 350µA of current. However, an on-board 3.3V regulator makes it a perfect choice for interfacing with 5V microcontrollers such as the Arduino.

This breadboard friendly board breaks out every pin of the ADXL335 to a 6-pin, 0.1″ pitch header. This includes 3 analog outputs for X, Y and Z axis measurements, 2 supply pins and a self-test pin which allows you to check the functioning of the sensor in the final application.

The analog outputs are Ratiometric, meaning 0g measurement output is nominally equal to half of the 3.3V supply voltage (1.65V), -3g is at 0v and 3g is at 3.3V with full scaling in between.

Specifications of the ADXL335 Accelerometer IC:

Operating Voltage 1.8V – 3.6V
Operating Current 350μA (typical)
Sensing Range ±3g (Full Scale)
Temperature Range −40 to +85°C
Sensing axis 3 axis
Sensitivity 270 to 330mV/g (Ratiometric)
Shock Resistance Up to 10,000g
Dimension 4mm x 4mm x 1.45mm

Signals and connections of the ADXL335

Vin, VCC – provides power for the accelerometer which can be connected to 5V pin on the Arduino board.

3vo – connected to the 3.3V pin of the Arduino board. For the best possible accuracy and precision, you can use the output of the accelerometer boards voltage regulator as the analog reference for the Arduino. Connect the 3Vo pin on the accelerometer board to the AREF pin on the Arduino. If you connect an external voltage reference to the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead() (e.g. in your setup() function). Otherwise, you will short the internal reference with the external reference, possibly damaging your Arduino board.

Test, ST (Self-Test) – controls the self-test feature. This feature is discussed in detail at the end.

GND – connected to GND pin on Arduino board

X-Out, X_out ,X, Xout– outputs analog voltage proportional to acceleration exerted on X axis.

Y-Out ,Y_out, Y, Yout– outputs analog voltage proportional to acceleration exerted on Y axis.

Z-Out, Z_out, Z, Zout– outputs analog voltage proportional to acceleration exerted on Z axis.

Signals and connections of the Arduino Nano

You can read more about it here.

Wiring without calibration

Connections are pretty easy. Start by placing the accelerometer on to your breadboard. Connect VCC pin to the 5V pin on the Arduino board and connect GND pin to the Ground pin on the Arduino board. Also connect X, Y and Z output to the analog pins A0, A1 and A2 on Arduino board.

For accurate results, we need to change the analog reference(AREF) voltage of the Arduino board. This can be done by connecting the 3.3V pin on Arduino board to the AREF pin.

When you’re done you should have something that looks similar to the illustration shown below.

Wiring no calibration
Wiring no calibration

Wiring for calibration

Wiring with calibration

Static Calibration

As with all sensors, there is some variation in output between samples of these accelerometers. For non-critical applications such as game controllers, or simple motion or tilt sensors, these variations are not important. But for applications requiring precise measurements, calibration to a reliable reference is a good idea.

Gravity as a Calibration Reference

Acceleration is measured in units of gravitational force or “G”, where 1G represents the gravitational pull at the surface of the earth. Despite what you may have heard, gravity is a pretty stable force and makes a convenient and reliable calibration reference if you happen to be a surface-dwelling earthling.

For High-G accelerometers such as the ADXL377, the +/- 1G range of static calibration is too small to assure good accuracy over the +/- 200G range of the sensor. Accurate calibration for extreme G-forces requires more specialized equipment to repeatably create these extreme forces in a controlled environment. One commonly used technique is to drop the accelerometer from a known height and measure the negative acceleration at impact.

Calibration Method

To calibrate the sensor to the gravitational reference, you need to determine the sensor output for each axis when it is precisely aligned with the axis of gravitational pull. Laboratory quality calibration uses precision positioning jigs. The method described here is simple and gives surprisingly good results.

The ADXL335 Accelerometer has a self-test feature which allows you to check the functioning of the sensor in the final application.

ST(self-test) pin on the module controls this feature.

When ST pin is connected to 3.3V, an electrostatic force is exerted on the accelerometer beam internally. The resulting movement of the beam allows the user to test if the accelerometer is functional.

The typical change in output is

−1.08 g (−325 mV) on the X-axis
+1.08 g (+325 mV) on the Y-axis
+1.83 g (+550 mV) on the Z-axis
This ST pin can be left open-circuit or connected to GND in normal use.

Warning: Exposing the ST pin to voltages greater than 3.6V may damage the accelerometer permanently.

accelerometer axis

Step by Step instruction

1.Uploading sketch with calibration

  1. First mount the sensor to a breadboard. The back and squared edges of the breadboard make a reasonably accurate set of reference planes to orient the sensor for calibration.
  2. Do wiring.
  3. Open Arduino IDE.
  4. Plug your Adruino Nano board into your PC and select the correct board and com port
  5. Verify and upload calibrationsketch to your Adruino Nano.
  6. Open up Arduino IDE Serial monitor and set your baud to 9600 baud and select Both NL&CR.
  7. Lay the breadboard with the sensor on a flat surface. Press and hold the button until you see “Calibrate” in the serial monitor. This will calibrate the minimum value for the z axis.
  8. Stand the breadboard on the front edge and press the button again. to calibrate +y.
  9. Repeat this for the three other edges to calibrate +x, -y and -x.
  10. Turn the breadboard upside down and press the button again to calibrate +z. (Hint, the underside of a table works well to steady it.)
  11. Once calibrated, the output will show the calibrated raw range for each axis, followed by the measured “G” forces. The raw ranges can be used as constants in sketches.

Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625
511, 511, 625 :: -0.01G, 0.07G, 1.00G
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625
511, 511, 625 :: -0.01G, 0.07G, 1.00G
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625
511, 511, 625 :: -0.01G, 0.07G, 1.00G
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625
511, 511, 625 :: -0.01G, 0.07G, 1.00G
Raw Ranges: X: 408-616, Y: 398-610, Z: 422-625

2.Uploading sketch without calibration

  1. First mount the sensor to a breadboard. The back and squared edges of the breadboard make a reasonably accurate set of reference planes to orient the sensor for calibration.
  2. Do wiring.
  3. Open Arduino IDE.
  4. Plug your Arduino Nano board into your PC and select the correct board and com port
  5. Verify and upload sketchwithoutcalibration to your Arduino Nano.
  6. Open up Arduino IDE Serial monitor and set your baud to 9600 baud and select Both NL&CR.
  7. You will see the accelerometer output in serial monitor at different sensor positions.

Code

1.Sketch Without calibration

The sketch starts by declaring Arduino’s analog input pins to which sensor’s X, Y and Z output pins are connected.

Next, we define the minimum and maximum values the Arduino is going provide. As the Arduino board contains 10-bit analog to digital converter, it will map sensor’s output voltages between 0 and 3.3 volts into integer values between 0 and 1023. That’s why RawMin is set to 0 and RawMax is set to 1023.

The variable sampleSize tells the Arduino to take 10 samples of each conversion to get more precise results.

In setup function, we must set the analog reference to EXTERNAL, as we have connected 3.3V to the AREF pin on Arduino board. This is done by calling analogReference(EXTERNAL).

You can read more about the function on Arduino’s official website. Except this, we initialize serial communications with the PC. Warning: If you fail call analogReference(EXTERNAL), you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging your Arduino board.

In setup function, we read analog outputs from the sensor every 200ms. Instead of calling analogRead() function, we are calling ReadAxis() custom function. This function merely takes 10 sample of ADC conversions and returns the average.

The following code snippet is the most important part of the program. It maps and converts the analog output voltages from the sensor to gravitational acceleration(G).

The IDE’s built-in map() function does the actual mapping. So, when we call map(xRaw, RawMin, RawMax, -3000, 3000), value of RawMin would get mapped to -3000, a value of RawMax to 3000 and values in-between to values in-between.

The values -3000 and 3000 are not arbitrary. They actually represents the gravitational acceleration (in milli-g which is 1/1000 of a g) measured by the sensor i.e. ±3g (-3000 milli-g to 3000 milli-g).

For example,

When the sensor outputs 0 volts on x-axis i.e. xRaw=0, the map() function will return -3000 representing -3g.
When the sensor outputs 3.3 volts on x-axis i.e. xRaw=1023, the map() function will return 3000 representing +3g.
When the sensor outputs 1.65 volts on x-axis i.e. xRaw=511, the map() function will return 0 representing 0g.

The term Ratiometric will make more sense now as the output voltage increases linearly with acceleration over the range.

// Convert raw values to ‘milli-Gs”
long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);
long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);
long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);

Finally, the sensor’s output is scaled down to fractional Gs by dividing it by 1000 and displayed on the serial monitor.

Summary

We have learnt about the ADXL335 Accelerometer and how to use it with Arduino Nano.

Thank you for reading and supporting us.

Libraries:

  • None

Project resources:

  • See attachments on the beginning of this project description.

AcoptexCom

Leave a Reply

Your email address will not be published.

Solve : *
25 − 18 =