# ADXL 203 analog accelerometer

#### aviatorbja

##### Member
Hello,

I came accross some ADXL203 2 axis accelerometers. The output is very simple. 2.5 Volts is 0 g's and the sensitivity is 1000 mV/g.
I'm trying to build an inclinometer for my workshop.

The tilt angle is just asin(1/g), where the g's are in the range -1 to 1.

Using excel I've created a table for pitch angle versus volts for a total of 251 data points.

volts pitch angle
1.500 -90
1.508 -82.7
1.516 -79.7
.....etc

I thought I could use the lookup function to compute the angle, but reading the manual I don't think this is possible. I suppose direct calculation is possible, but my Picaxe 20x2 cannot do ASIN, only ATAN function.

I also realize that this topic has probably been discussed at some time, but I can't seem to find it within the forums.

Does anyone have any suggestions on the easiest way to accomplish this?

#### g6ejd

##### Senior Member
You can use your EEPROM on the 20X2 and set a notional 0 address to be e.g. 1.50 volts, so in your short table extract:

Volts, EEPROM word address, value
1.500, 0, 900
1.508, 2, 827
1.516, 4, 797

You can then assume all negative values and divide the word contents of each EEPROM address by 10 to get back to 90.0, 82.7, etc. You may have to check how to write a word value to the EEPROM and to split the word value into high and low bytes. Alternatively use just one byte and lose some resolution, it probably does not matter that much, thus:
1.500, 0, 90
1.508, 1, 82
1.516, 2, 79

#### aviatorbja

##### Member
Thanks g6ejd,

You got me thinking. I CAN do this with the LOOKUP command. I'll use volts*100 and then subtract 150 so that 1.5 volts will become 0.

Then I can regenerate the pitch angles for 1.51V, 1.52V, 1.53V, etc.. using excel

The INDEX variable will be volts*100-150, or (0,1,2,3,4,.....etc). Each step is equal to .01 Volt.

The lookup command would be, LOOKUP INDEX,(900,819,785,759,737,718,701,684,669....), W3

I'll try that this weekend and report back.

You can use your EEPROM on the 20X2 and set a notional 0 address to be e.g. 1.50 volts, so in your short table extract:

Volts, EEPROM word address, value
1.500, 0, 900
1.508, 2, 827
1.516, 4, 797

You can then assume all negative values and divide the word contents of each EEPROM address by 10 to get back to 90.0, 82.7, etc. You may have to check how to write a word value to the EEPROM and to split the word value into high and low bytes. Alternatively use just one byte and lose some resolution, it probably does not matter that much, thus:
1.500, 0, 90
1.508, 1, 82
1.516, 2, 79

#### aviatorbja

##### Member
Here's my non-optimized code for reading the two accelerometer channels converting raw voltage to Bank and Pitch angles using a look up table.

#### Attachments

• 3.3 KB Views: 34