2

Maybe it's a simple question but I'm unable to get what I need.

My task is this: Get the acceleration and speed of each axis of the accelerometer.

I thought of something like:

const int VCCPin = A0;
const int xPin   = A1;
const int yPin   = A2;
const int zPin   = A3;
const int GNDPin = A4;

// variables
int old_x = 0;
int old_y = 0;
int old_z = 0;

int new_x = 0;
int new_y = 0;
int new_z = 0;

void setup() {
  // pin A0 (pin14) is VCC and pin A4 (pin18) in GND to activate the GY-61-module
  pinMode(A0, OUTPUT);
  pinMode(A4, OUTPUT);
  digitalWrite(14, HIGH);
  digitalWrite(18, LOW);

  // activating debugging for arduino UNO
  Serial.begin(9600);
} 

void loop() {
  new_x = analogRead(xPin);
  new_y = analogRead(yPin);
  new_z = analogRead(zPin);

  Serial.print("Difference in X=");
  Serial.println(abs(old_x - new_x));

  Serial.print("Difference in Y=");
  Serial.println(abs(old_y - new_y));

  Serial.print("Difference in Z=");
  Serial.println(abs(old_z - new_z));

  old_x = new_x;
  old_y = new_y;
  old_z = new_z;
} 

Unfortunately, the analogRead will give me a value between 0 and 1023 and I don't know how to convert this to speed and acceleration.

Any ideas on how to get this convertion?

5
  • Probably relevant arduino.stackexchange.com/q/13887/972
    – gre_gor
    Sep 2, 2016 at 18:13
  • I assume that your accelaration hardware work. Becuase it gives you different analog outtput in with diffrent accelaration. it seems what you are asking for is how to calibrate it. As a guess there should be away to calibrate the accelaration for each axis when the sensor not moving in the x,y,z plane for zero acceleration. See the page learn.adafruit.com/adafruit-analog-accelerometer-breakouts/… is what you seem to be looking for. Im not sure how your code works works, because acceleration is defined as the differential of velocity function which to me means that yoe mu
    – RS2322016
    Sep 2, 2016 at 19:18
  • st measure the rate of change of velcocity at two different point in time to measure the accelaration-to estimate the accelaration at that time point. Or if the hardware gives you the accelaration directly you dont need to measure new and old velocities. Once you have calibrated it you can convert the accelaration to a single accelration by using pythagoros's theorem in three dimension to get the size of the final accelaration.
    – RS2322016
    Sep 2, 2016 at 19:20
  • However, the above two comments are are just an educated guess, to give you some ideas, becuase I dont have the accelaration hardware you are using.
    – RS2322016
    Sep 2, 2016 at 19:23
  • Since I can't comment I must post this as an answer. To get changes in values to be considered as speeds and accelerations you need to take time into account. Distance=rate*time. So Distance divided by time gives you the rate (speed). Then you can measure the change in speed over time to get accelerations. The GY-61 is capable of directly giving some of the readings you are looking for. Here is one article about it that you may find useful: waime.wordpress.com/2015/03/15/… Like @qwerty, I am just ruminating here.
    – SDsolar
    Oct 28, 2016 at 8:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.