Difference between revisions of "Accelerometer + Arduino"

From ESE205 Wiki
Jump to navigation Jump to search
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Overview==
 
==Overview==
  
This tutorial will cover how to hook up an Arduino with an MMA845 accelerometer. After completing this tutorial, you will be able to read in acceleration data from the x, y, and z directions. Although the MMA845 accelerometer is compatible with all Arduino types, this tutorial will handle hooking up the accelerometer with the Arduino Uno.
+
This tutorial will cover how to hook up an Arduino with an MMA845 accelerometer. After completing this tutorial, you will be able to read in acceleration data from the x, y, and z directions. Although the MMA845 accelerometer is compatible with all Arduino types, this tutorial will handle hooking up the accelerometer with the Arduino Uno. <br/> <br/>
 +
 
 +
The MMA845 accelerometer is a good choice to use if you a looking to use an accelerometer for very fundamental purposes. It does a good job of measuring tilt and acceleration in all three directions. If you are looking to specifically isolate acceleration in one direction or use an accelerometer for more complex ways, you may want to consider using a different accelerometer.
  
 
==Materials and Prerequisites==
 
==Materials and Prerequisites==
 +
Materials:
 
* MMA8451 [https://www.sparkfun.com/products/13926?_ga=2.215074900.2107991562.1543943339-590586114.1539882684 Accelerometer]
 
* MMA8451 [https://www.sparkfun.com/products/13926?_ga=2.215074900.2107991562.1543943339-590586114.1539882684 Accelerometer]
 
* Arduino (we used an Arduino [https://store.arduino.cc/usa/arduino-uno-rev3 Uno], but will work with any kind of Arduino)
 
* Arduino (we used an Arduino [https://store.arduino.cc/usa/arduino-uno-rev3 Uno], but will work with any kind of Arduino)
Line 9: Line 12:
 
* Two [http://www.resistorguide.com/resistor-color-code/ 330 Ω] resistors
 
* Two [http://www.resistorguide.com/resistor-color-code/ 330 Ω] resistors
 
* Connector cables
 
* Connector cables
* Soldering materials (if the headers have not been soldered already)
+
* Soldering materials (only if the headers have not been soldered already. I would recommend buying the accelerometer with headers already attached.)
 +
* Computer
 +
 
 +
Prerequisites:
 +
*Knowledge of how to hook up an Arduino with your computer. For a basic set up guide, see this [https://www.arduino.cc/en/main/howto link].
 +
*Download the Arduino IDE. Download options can be found [https://www.arduino.cc/en/Main/Software here]
  
 
==Setting Up Circuit==
 
==Setting Up Circuit==
 
We will be using I2C, so there will only need to be two connections between the arduino and the sensor. For more information about I2C, refer to this [[I2C + Arduino|tutorial]]. <br/>
 
We will be using I2C, so there will only need to be two connections between the arduino and the sensor. For more information about I2C, refer to this [[I2C + Arduino|tutorial]]. <br/>
 
<br/>
 
<br/>
The materials you will need for this part of the process is the breadboard, MMA845 accelerometer, the resistors, and the Arduino. <br/>
+
The materials you will need for this part of the process is the '''breadboard''', '''MMA845 accelerometer''', the '''330 Ω resistors''', '''connectors''', and the '''Arduino'''. <br/>
 
<br/>
 
<br/>
 
Below, you will see a diagram for the circuit. You need to put the accelerometer somewhere on the breadboard, and connect the power (3.3V) and ground with the Arduino. Using the two 330 Ω resistors, connect the SLC port on the Arduino with the SLC port on the accelerometer so that it goes through the resistance. Do the same for the SDA port. Once you have completed the circuit, you are ready to connect the Arduino with your computer. <br/>  
 
Below, you will see a diagram for the circuit. You need to put the accelerometer somewhere on the breadboard, and connect the power (3.3V) and ground with the Arduino. Using the two 330 Ω resistors, connect the SLC port on the Arduino with the SLC port on the accelerometer so that it goes through the resistance. Do the same for the SDA port. Once you have completed the circuit, you are ready to connect the Arduino with your computer. <br/>  
Line 20: Line 28:
  
 
==Downloading Libraries==
 
==Downloading Libraries==
The nice thing about using this accelerometer is that it comes with libraries that will allow you to quickly start reading in data. Before you download anything though, make sure you have the latest version of the Arduino IDE. If you
+
The only materials you will need for this part is your '''computer'''. <br/>
 +
 
 +
The nice thing about using this accelerometer is that it comes with a library that will allow you to quickly start reading in data. Before you download anything though, make sure you have the latest version of the Arduino IDE (see prerequisites).  
 
<br/>
 
<br/>
 
       To download the library, click this [https://github.com/sparkfun/SparkFun_MMA8452Q_Arduino_Library/archive/master.zip link].
 
       To download the library, click this [https://github.com/sparkfun/SparkFun_MMA8452Q_Arduino_Library/archive/master.zip link].
Line 31: Line 41:
 
     File > Examples > SFE_MMA8452Q > MMA8452Q_Basic
 
     File > Examples > SFE_MMA8452Q > MMA8452Q_Basic
  
Open the example sketch, upload it to your Arduino, and run the script. Once it is running, open the serial monitor to see the acceleration values. The far-left column will be the x-acceleration, the middle column is the y-acceleration, and the far-right column is the z-acceleration. To the right of the z-acceleration, you will see the orientation of the accelerometer.
+
Open the example sketch, upload it to your Arduino, and run the script. Once it is running, open the serial monitor to see the acceleration values. The far-left column is the x-acceleration, the middle column is the y-acceleration, and the far-right column is the z-acceleration. To the right of the z-acceleration, you will see the orientation of the accelerometer. <br/>
  
 
[[File:Serial-monitor-example.png|frameless]]
 
[[File:Serial-monitor-example.png|frameless]]
  
  
 +
Congratulations! If you've reached this point, it means you have successfully hooked up the MMA845 accelerometer with your Arduino.
 +
 +
==Troubleshooting==
 +
*Check to make sure you are using the correct Arduino board. You set the board under
 +
    Tools > Board
 +
*Check to make sure your Serial Port is correct. This can be found under
 +
    Tools > Port
 +
*Now, make sure your Arduino is working. Try running the blink code, which can be found under
 +
    File > Sketchbook > Examples > led_blink
 +
 +
*If that is working, make sure that the code you are running is correct. Compare your code with the code from this [https://www.arduino.cc/en/main/howto github]. <br/>
 +
 +
*If everything up to this point seems correct, check to make sure your circuit is set up properly. Ensure that the resistors and all connectors have a good connection with the breadboard and the Arduino. If you don't have good connections (particularly with the resistors I found), you will not be able to read in values.
 +
 +
If you are still experiencing difficulties, refer to external references.
  
 
==Authors==
 
==Authors==
Line 48: Line 73:
  
 
==External References==
 
==External References==
https://learn.sparkfun.com/tutorials/mma8452q-accelerometer-breakout-hookup-guide
+
*Hookup Guide from purchasing site: [https://learn.sparkfun.com/tutorials/mma8452q-accelerometer-breakout-hookup-guide link]
 
+
*Details on the MMA845 accelerometer: [https://cdn.sparkfun.com/datasheets/Sensors/Accelerometers/MMA8452Q_Breakout-v10.pdf link]
 +
*Arduino GitHub Library: [https://github.com/sparkfun/SparkFun_MMA8452Q_Arduino_Library/tree/master link]
  
  

Latest revision as of 19:53, 5 December 2018

Overview

This tutorial will cover how to hook up an Arduino with an MMA845 accelerometer. After completing this tutorial, you will be able to read in acceleration data from the x, y, and z directions. Although the MMA845 accelerometer is compatible with all Arduino types, this tutorial will handle hooking up the accelerometer with the Arduino Uno.

The MMA845 accelerometer is a good choice to use if you a looking to use an accelerometer for very fundamental purposes. It does a good job of measuring tilt and acceleration in all three directions. If you are looking to specifically isolate acceleration in one direction or use an accelerometer for more complex ways, you may want to consider using a different accelerometer.

Materials and Prerequisites

Materials:

  • MMA8451 Accelerometer
  • Arduino (we used an Arduino Uno, but will work with any kind of Arduino)
  • Breadboard
  • Two 330 Ω resistors
  • Connector cables
  • Soldering materials (only if the headers have not been soldered already. I would recommend buying the accelerometer with headers already attached.)
  • Computer

Prerequisites:

  • Knowledge of how to hook up an Arduino with your computer. For a basic set up guide, see this link.
  • Download the Arduino IDE. Download options can be found here

Setting Up Circuit

We will be using I2C, so there will only need to be two connections between the arduino and the sensor. For more information about I2C, refer to this tutorial.

The materials you will need for this part of the process is the breadboard, MMA845 accelerometer, the 330 Ω resistors, connectors, and the Arduino.

Below, you will see a diagram for the circuit. You need to put the accelerometer somewhere on the breadboard, and connect the power (3.3V) and ground with the Arduino. Using the two 330 Ω resistors, connect the SLC port on the Arduino with the SLC port on the accelerometer so that it goes through the resistance. Do the same for the SDA port. Once you have completed the circuit, you are ready to connect the Arduino with your computer.
Circuit diagram.pdf.png

Downloading Libraries

The only materials you will need for this part is your computer.

The nice thing about using this accelerometer is that it comes with a library that will allow you to quickly start reading in data. Before you download anything though, make sure you have the latest version of the Arduino IDE (see prerequisites).

      To download the library, click this link.

If you do not know how to install an Arduino library, follow the links below.

  • Installing a library on a Mac: link
  • Installing a library on a Windows: link

Once you install the library, restart the Arduino. Upon reboot, go to:

    File > Examples > SFE_MMA8452Q > MMA8452Q_Basic

Open the example sketch, upload it to your Arduino, and run the script. Once it is running, open the serial monitor to see the acceleration values. The far-left column is the x-acceleration, the middle column is the y-acceleration, and the far-right column is the z-acceleration. To the right of the z-acceleration, you will see the orientation of the accelerometer.

Serial-monitor-example.png


Congratulations! If you've reached this point, it means you have successfully hooked up the MMA845 accelerometer with your Arduino.

Troubleshooting

  • Check to make sure you are using the correct Arduino board. You set the board under
    Tools > Board
  • Check to make sure your Serial Port is correct. This can be found under
    Tools > Port
  • Now, make sure your Arduino is working. Try running the blink code, which can be found under
    File > Sketchbook > Examples > led_blink
  • If that is working, make sure that the code you are running is correct. Compare your code with the code from this github.
  • If everything up to this point seems correct, check to make sure your circuit is set up properly. Ensure that the resistors and all connectors have a good connection with the breadboard and the Arduino. If you don't have good connections (particularly with the resistors I found), you will not be able to read in values.

If you are still experiencing difficulties, refer to external references.

Authors

  • Gillian Laming

Published fall 2018.

Group Link

Our project was called Zesty Vesty. See below for links to our project page and weekly log.
Weekly log
Link to project page

External References

  • Hookup Guide from purchasing site: link
  • Details on the MMA845 accelerometer: link
  • Arduino GitHub Library: link