Conversion of angle

Dear all ,

I am using ADXL335 acceleomter to determine inclination angle. i am using ardunio Uno board for programming. My connection as follows

VIn->3.3v gnd-> xaxis -> connected to analog A0 Yaxis -> connected to analog A1 Zaxis -> connected to analog A2 here it my code. I wanted to convert angle into +70degree and -70 degree format . How can do that here.

#define ADC_ref 2.56

#define zero_x 1.569

#define zero_y 1.569

#define zero_z 1.569

#define sensitivity_x 0.3

#define sensitivity_y 0.3

#define sensitivity_z 0.3

unsigned int value_x;
unsigned int value_y;
unsigned int value_z;

float xv;
float yv;
float zv;

float angle_x;
float angle_y;
float angle_z;

void setup() {

void loop() {

  value_x = analogRead(A0);
  value_y = analogRead(A1);
  value_z = analogRead(A2);
Serial.print("voltage  of x");
  angle_x =atan2(-yv,-zv)*57.2957795+90;
 Serial.print ("x= ");
  Serial.println (xv);

  Serial.print("x_degree= ");
  Serial.println(" deg");

I wanted to convert angle into +70degree and -70 degree format

What does that mean?

Use the Map function.

Here i dont how to read the values from sensor. Like if it is 5V output sensor. I would convert in to voltage format and used relation

voltage= sensor_value*0.0048828125;
degree=( 41.25*voltage)- 95.625

i dont know how can read & convert here

It depends on what angle you are trying to measure, and also whether your device is mounted so that it only tilts in 2 relevant dimensions, or three dimensions.

Your last example calculation makes no sense at all.

You have a roughly 205 degree range (-95 to + 110 degrees). It isn't a programming issue to reduce it to a 140 degree range, it's arithmetic.

For the above product example given i copied code from here

Maybe I'm just thick, but I don't even understand the OP's question. What does it mean, to "convert angle into +70 degree and -70 degree format"?

You are not thick.

Can i use this sensor with Arduino UNo board. IS any iC available which gives angle from 0.5v to 5v analog . and compatiable with arduino UNO board

Angle of what ? What are you actually trying to measure ?

This code working for me

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

//The minimum and maximum values that came from
//the accelerometer while standing still
//You very well may need to change these
int minVal = 264;
int maxVal = 394;

//to hold the caculated values
double x;
double y;
double z;

void setup(){

void loop(){

  //read the analog values from the accelerometer
  int xRead = analogRead(xPin);
  int yRead = analogRead(yPin);
  int zRead = analogRead(zPin);

Serial.print("Xread :");
 int xAng = map(xRead, minVal, maxVal, -90.0, 90.0);
 // x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
 Serial.print("x: ");

but not calibrated properly. When i compare answer with angle meter there is offset.

I don't think anyone actually understands your question....

My application is solar tracking application. I wanted to inclination of panel. Intially i used inclinometer to measure tilt angle. Now i wanted to design my own inclinometer. SO max measure angle go from +90 degree to -90 degree format. SO this sensor read analog bit from min 263 and max 393 when 3.3 v supplied.

relevant data sheet attached here

Now my question is how should i convert this angle. In data sheet not mentioned resolution of sensor.

Or sensor IC available which directly gives 0~5v analog output.§ion2=39&number=200&slide=select§ion2=39&number=168&slide=select

As far as I know, there is no IC which is going to give you an angle output directly.

That IC you have should be fine for providing you with the information required to calculate the angle.

The first thing you have to decide, is whether you need a 2-d or 3-d calculation ?

Your device has 3 different axes, which are marked on page 5 of the datasheet.

If you were to take the chip, and mount it on the sloping face of your solar panel, so that the x axis was pointing down the slope, and the y axis was horizontal across the slope, and the z axis was pointing out the top of the chip towards the sun, then when you tilt the panel up and down, the y axis would be horizontal and you can ignore it's reading, and the ratio of the x and z axis readings would determine it's angle, and you would determine that angle using the atan2( ) function.

If on the other hand, you were to take the chip and stick it on the side frame of the solar panel, with the x axis pointing along the edge of the panel frame down the slope of the panel, and the y axis pointing towards the sun, and the z axis pointing horizontally, then as you tilt the panel up and down, the z axis would remain horizontal, and you and ignore it, and the ratio of the x and y readings would determine the angle.

Those two scenarios are examples of 2-d solutions of the angle

If on the other hand the panel can wave around all over the place, then you need a 3-d solution and it gets more complicated.

To get the correct angle, you may need to do some experiments and adjust the scaling and offset of the analog readings for the two axes you actually plan to use.