Accelerometer and what they actually do

I bought this accelerometer:

It looks like they are a bit more complex than I though they would be :slight_smile:
I do not need this for any particular project, I just want to play around with it.

So what I though it would do is it would output the G force for each axis. So I though when it's held completely still it would give me 0 on each axis. I also thought that when I would turn it 90 degrees it would still give me 0 on each axis.

This is my test code:

int xPin = 0;
int yPin = 1;
int zPin = 2;
const int STABILITY = 10;

int xValue,yValue,zValue;

void setup (){
  Serial.begin(9600);
  analogReference(EXTERNAL);

  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
  pinMode(zPin, INPUT);

  Serial.println("asd");
}
long axe_x;
long axe_y;
long axe_z;
void loop (){

  xValue = analogRead(xPin);
  yValue = analogRead(yPin);
  zValue = analogRead(zPin);
  Serial.println(mapFloat(xValue,0,1024,-5,5));
  Serial.println(mapFloat(yValue,0,1024,-5,5));
  Serial.println(mapFloat(zValue,0,1024,-5,5));
  Serial.println();

  delay(100);
}

float mapFloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

I really don't get what it actually measures.... The X value goes up and down when i tilt the board around the Y axis. But it also starts to jump if I slide it around the X Axis. If anyone could point me in the right direction what it actually does I would be very happy :wink: I googled and searched on youtube but I couldn't find any useful information.

I can only see examples where it is used to measure the angle, is that what it's used for?

Thanks

So I though when it's held completely still it would give me 0 on each axis.

No.

I really don't get what it actually measures.

It measures the force of gravity pulling down on it, the acceleration due to the gravitational force.
If you were to drop the sensor, then it would be in free fall and then you would get a zero reading before it hit the floor.

Thanks for the answer...

So I read something about static and dynamic forces that can be read from a accelerometer. So is that just a matter of calculation? Or are some accelerometers giving dynamic and the other static forces? See attachment

So I read something about static and dynamic forces that can be read from a accelerometer

A static force is gravity, a dynamic force is one you get when something changes speed, or accelerates or decelerates. In effect it is just measuring how droopy silicon fibers are.

Why do you use this ? : analogReference(EXTERNAL);
Is that for the 3.3V ? Did you connect that to Aref ?

TempleClause:
I bought this accelerometer:
SainSmart | Desktop CNC, 3D Printing & DIY Tools | Power to the Makers – SainSmart.com

It looks like they are a bit more complex than I though they would be :slight_smile:
I do not need this for any particular project, I just want to play around with it.

...
...

I really don't get what it actually measures.... The X value goes up and down when i tilt the board around the Y axis. But it also starts to jump if I slide it around the X Axis. If anyone could point me in the right direction what it actually does I would be very happy :wink: I googled and searched on youtube but I couldn't find any useful information.

I can only see examples where it is used to measure the angle, is that what it's used for?

Thanks

go here;
https://learn.sparkfun.com/tutorials/accelerometer-basics

I am new to arduino and i know very few things but your x/y/z outputs should be conected to an analog input
so at your variables should be A1,A2 and A3 and if you want to stabilize your platform A1(x) and A2(y) should be equal so if A1=A2 then perfect balance and A3(z) if the platform static should be negative because of the gravity.

your x/y/z outputs should be conected to an analog input so at your variables should be A1,A2 and A3

Why those three pins?
He has it connected to A0, A1 and A2 as defined in his code which are just as good as A1, A2 and A3.
Note you do not have to have the A prefix in the analogRead function, a simple number will do.

A0 to A5 whatever he want its fine. And if plain numbers as pin indicator are just fine then how the proggram will recognize if its
analog 1 (A1) or digital 1?

Val =analogRead(1);
Val = analogRead(A1);

These two will both read the same analog pin.
Where as this:-

Val = digitalRead(1); // reads pin 1
Val = digitalRead(A1); // reads analog pin 1 as a digital pin. Note this is the same as the next line
Val = digitalRead(15); // reads analog pin 1 as a digital pin.

Can you spot how the compiler might know what to do?