MMA7361 Accelerometer Basics Arduino Code
MMA7361 Accelerometer Basics Arduino Code
ino Arduino using MMA7361 3-Axis Accelerometer Basics of using a MMA7361 3 3-Axis Accelerometer with an Arduino Leonardo Using a simple sketch to display MMA7361 3 3-Axis Accelerometer with values in the serial window NOTE: the MA7361 3-Axis Accelerometer has an SL, (SLeep to reduce power used), pin which need to be set high to turn the MA7361 fully on. To view serial port press Crtl+Shift+M This sketch has bee modified from http://forum.arduino.cc/index.php?topic=90284.0 A video about this, on YouTube Arduino using MMA7361 3-Axis Accelerometer YOUTUBE VIDEO Arduino Experiments YouTube Playlist about the $9.00 Arduino. http://www.youtube.com/playlist?list=PL1N3_q4khW7LvjfbQBRtrvbMknXwYzRae The Sketch: http://www.acomputerportal.com/arduino/MMA7361_accelerometer_basics/MMA7361_ac celerometer_basics.ino Microcontrollers, Controllers http://www.acomputerportal.com/microcontrollers_controllers.html Computers, Robots and Electronics, etc... http://www.acomputerportal.com A YouTube video about testing this 3-Axis Accelerometer using a Multimeter MMA7361 3 3-Axis Accelerometer Multimeters to test and brief review http://www.youtube.com/watch?v=-4WvADos_eg This sketch has bee modified from http://forum.arduino.cc/index.php?topic=90284.0 This example code is in the public domain. */ /* Original code commented out, you can try it if you want http://forum.arduino.cc/index.php?topic=90284.0 const int STABILITY = 10; long axe_x=0; long axe_y=0; long axe_z=0; */ void setup() { Serial.begin(115200); // Standard is 9600 the maximum supported speed, 115200
. } ////////////////////////////////////////////////////////// void loop() { /* Original code commented out, you can try it if you want http://forum.arduino.cc/index.php?topic=90284.0 axe_x = ((STABILITY-1)* axe_x + analogRead(A0)) / STABILITY; axe_y = ((STABILITY-1)* axe_y + analogRead(A1)) / STABILITY; axe_z = ((STABILITY-1)* axe_z + analogRead(A2)) / STABILITY; Serial.print("STABILITY X="); Serial.print(axe_x); Serial.print("\tY="); Serial.print(axe_y); Serial.print("\tZ="); Serial.println(axe_z); Serial.println(); */ // The minus values, worked for me // The set the output to about zero, will vary a bit, when the // MMA7361 3-Axis Accelerometer is level and not being moved Serial.print("DIRECT X="); Serial.print(analogRead(A0)-333); Serial.print("\tY="); Serial.print(analogRead(A1)-374); Serial.print("\tZ="); Serial.println(analogRead(A2)-449); // display a blank line between each line Serial.println(); }