Go Down

Topic: how to convert to radians or degree (Read 41097 times) previous topic - next topic

AWOL

Quote
But the ADXL202 also has analog outputs,

Ah yes, you're right.;
But they don't output in gs either.
They need an offset and scaling operation.
Maybe that accounts for the "ridiculous"ness.

westfw

Code: [Select]
tiltx=analogRead(5);
    :
  Serial.print(asin(tiltx/9.81));

analogRead() does not return a floating point number all adjusted to be meaningful for the particular sensor that is connected.  It returns an INTEGER between 0 and 1023, depending on where in the range of 0-5V the input voltage lies.  Typically you would apply some scaling to get the actual voltage (vX = (5.0*analogRead(5)/1000.0), but it depends on signedness/etc), and then some additional math to get that into a value that is meaningful to the thing being sensed (and then, if necessary, convert to radians as required by the trig functions.)

While I appreciate the desire to properly condition newbies, it didn't really require code tags, complete code, or actual output to see that this is currently very wrong at a basic level...

AWOL

Quote
it didn't really require code tags, complete code, or actual output to see that this is currently very wrong at a basic level...

Reply #22.

Go Up