3 Axis Accelerometer - Breakout Board

This node reads 3 analog input pins, one for each axis, and transforms their readings to the range of -1 to 1 to be used in Embrio.

This example is for use with a breakout board, which you can use pins to control ground and voltage. If you are using just the sensor and wiring it up yourself, you can leave that part out.

Supported Products

  • SparkFun Triple Axis Accelerometer Breakout - ADXL335
  • SparkFun Triple Axis Accelerometer Breakout - ADXL345
  • SparkFun Triple Axis Accelerometer Breakout - ADXL362
  • SparkFun Triple Axis Accelerometer Breakout - ADXL377
  • SparkFun Triple Axis Accelerometer Breakout - MMA8452Q

Decleration Code

// these constants describe the pins. They won't change:
const int groundpin = 18;         // analog input pin 4 -- ground
const int powerpin = 19;            // analog input pin 5 -- voltage
const int xpin = A3;                    // x-axis of the accelerometer
const int ypin = A2;                    // y-axis
const int zpin = A1;                    // z-axis (only on 3-axis models)
const int rangeMin = 662;     // Acceleration value for angle -90
const int rangeMax = 355;     // Acceleration value for angle 90

Setup Code

// Provide ground and power by using the analog inputs as normal
// digital pins.    This makes it possible to directly connect the
// breakout board to the Arduino.    If you use the normal 5V and
// GND pins on the Arduino, you can remove these lines.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);

EveryUpdate

// Read each axis and transform its value to the -1 to 1 range
Output_XActivation = transform(analogRead(xpin), rangeMin, rangeMax, -1.0, 1.0);
Output_YActivation = transform(analogRead(ypin), rangeMin, rangeMax, -1.0, 1.0);
Output_ZActivation = transform(analogRead(zpin), rangeMin, rangeMax, -1.0, 1.0);

No required source files.

To use this node in your Embrio project, either add it from the Library toolbar or copy the XML in the below box and paste it into a node screen.

View Comments (0)