Detecting direction of obstacle

HI there. I am new to Arduinos and sensors.

My project involves an Arduino Nano and Accelerometer MMA8452Q, Maxbotix ultrasonic sensor and a breadboard. I am trying to write code that will determine which direction the accelerometer is moving (left, right, not moving).

The breadboard would not tilt. So I am not trying to determine the tilt. However, is there a way to determine which direction the accelerometer is moving.

Hope that helps.

Thanks.

Hi Arduino_nooby,

In order to do this with SparkFun’s [Arduino library for the MMA8452Q, you will need to modify the code to print a “direction” based on the output from the accelerometer. The [Basic example prints the acceleration measured in G’s so you would need to do some testing by moving the accelerometer along each axis and watching the values print. From there, you should be able to determine which direction the acceleration is occurring in depending on whether the values are positive or negative. Refer to the silkscreen on the board showing the directions for positive acceleration for each axis. After that, you would just need to adjust your code to add an if statement that would print something like “LEFT” or “RIGHT” depending on the values returned by the accelerometer.](SparkFun_MMA8452Q_Arduino_Library/examples/Example1_BasicReading/Example1_BasicReading.ino at main · sparkfun/SparkFun_MMA8452Q_Arduino_Library · GitHub)](GitHub - sparkfun/SparkFun_MMA8452Q_Arduino_Library: SparkFun Triple Axis Accelerometer Breakout - MMA8452Q Arduino Library)