100% found this document useful (4 votes)
737 views

MMA7361 Accelerometer Basics Arduino Code

This document discusses using an MMA7361 3-axis accelerometer with an Arduino board. It provides code for a sketch that reads the accelerometer's X, Y, and Z axis values and displays them in the serial monitor. The sketch initializes serial communication at 115200 baud and continuously prints the raw analog readings for each axis in a loop, subtracting offset values to set the output near zero when stationary.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
737 views

MMA7361 Accelerometer Basics Arduino Code

This document discusses using an MMA7361 3-axis accelerometer with an Arduino board. It provides code for a sketch that reads the accelerometer's X, Y, and Z axis values and displays them in the serial monitor. The sketch initializes serial communication at 115200 baud and continuously prints the raw analog readings for each axis in a loop, subtracting offset values to set the output near zero when stationary.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/* File : MMA7361_accelerometer_basics.

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(); }

You might also like