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?