I have interfaced an accelerometer with the UNO and doing single axis tilt measurement. I want to calibrate my device. I am looking for a device already on the market that can do the single axis tilt measurement, you know like with a digital display that can show the angle in degrees. Can someone recommend a device?
The device you are looking for is called an inclinometer or protractor. There are digital versions available. In some cases, hardware stores will carry these, but I am sure that somewhere like eBay will have them.
In woodworking, these are often used to set the angle of table saw blades:- Wixey Digital Angle Gauge
You can get cheaper ones I think, (search for "Digital Angle Gauge", as well as "Inclinometer" as suggested by marco_c), but the Wixey brand are very accurate and reliable.
Edit: The equation below isn't a good one to use. For a better explanation see this post.
If you know the sensitivity of your accelerometer and its precision, you can compute the theoretical angle based on the sensor's reading.
The acceleration from gravity will be
a = g * cosθ
So to find θ you use:
θ = acos(a / g)
If your accelerometer had 12-bit resolution and it was set to a sensitivity of +/-2g then 1g should be (2^12)/4 or 1024.
You would use 1024 for "g" and the value read from the accelerometer for the value of "a".
I believe the force of gravity changes a bit depending on where you are on Earth so it might be a good idea to compare the 1024 figure with a reading from the sensor on a known level surface. You could then use the reading from the level surface as the "g" in the calculations.
I'd be curious to learn if the theoretical angle varied much from the actual angle.
DuaneDegn:
If you know the sensitivity of your accelerometer and its precision, you can compute the theoretical angle based on the sensor's reading.
The acceleration from gravity will be
a = g * cosθ
So to find θ you use:
θ = acos(a / g)
If your accelerometer had 12-bit resolution and it was set to a sensitivity of +/-2g then 1g should be (2^12)/4 or 1024.
You would use 1024 for "g" and the value read from the accelerometer for the value of "a".
I believe the force of gravity changes a bit depending on where you are on Earth so it might be a good idea to compare the 1024 figure with a reading from the sensor on a known level surface. You could then use the reading from the level surface as the "g" in the calculations.
I'd be curious to learn if the theoretical angle varied much from the actual angle.
Sorry if all this is old news to you.
Thanks! Thing is that I am using accelerometer with +/- 3g sensitivity or 330mV/g. I am using 3.3 V supply and 12 bit ADC to sample the values.
But I am using the following to calculate the angle
angle = arc sin ( a/g)
Is it right way to do it? Plus at tilt 90 degrees, I get "math error" because arc sin (90) = error. How can I handle this situation?
MKJohn:
But I am using the following to calculate the angle
angle = arc sin ( a/g)
What is the reading of "a" when the sensor is level with the ground?
What is your zero angle horizontal or vertical?
The equation I gave used the arc cosine (aka "acos"). I assumed "a" = "g" when the sensor was level with the ground and a zero degree angle would be horizontal.
MKJohn:
Is it right way to do it? Plus at tilt 90 degrees, I get "math error" because arc sin (90) = error. How can I handle this situation?
Both arc sine and arc cosine take arguments between -1 and 1. You should test the values of "a/g" to make sure it's between these values before using the inverse trig function.
DuaneDegn:
What is the reading of "a" when the sensor is level with the ground?
What is your zero angle horizontal or vertical?
The equation I gave used the arc cosine (aka "acos"). I assumed "a" = "g" when the sensor was level with the ground and a zero degree angle would be horizontal.
Both arc sine and arc cosine take arguments between -1 and 1. You should test the values of "a/g" to make sure it's between these values before using the inverse trig function.
I am using the following module
As you can see on the 3rd page of the data sheet under voltage to tilt that the paper is suggesting to use arc Sin to calculate the tilt.
MKJohn:
As you can see on the 3rd page of the data sheet under voltage to tilt that the paper is suggesting to use arc Sin to calculate the tilt.
Ah yes, I see that. I see the following quote as well "with respect to the 0g point".
Either arc cosine or arc sine can be used. It depends on which axis you use.
DuaneDegn:
I assumed "a" = "g" when the sensor was level with the ground and a zero degree angle would be horizontal.
The example you mentioned also assumes a zero degree angle is horizontal, but it assumes "a = 0" when level.
I don't know if you're aware of it or not but you can get triple axis accelerometers with combined triple axis gyros from a couple dollars on ebay.
My current favorite IMU type sensor is the BNO055. It's the same price as the DE sensor.
There are certainly times when an accelerometer with an analog output would have an advantage over a sensor with digital output but since you're converting the analog to digital data anyway, you might want to consider using an inexpensive digital sensor (if/when you're in the market for another accelerometer).
@jremington, thanks for the link. It looks very interesting.
DuaneDegn:
Ah yes, I see that. I see the following quote as well "with respect to the 0g point".
Either arc cosine or arc sine can be used. It depends on which axis you use.
The example you mentioned also assumes a zero degree angle is horizontal, but it assumes "a = 0" when level.
I don't know if you're aware of it or not but you can get triple axis accelerometers with combined triple axis gyros from a couple dollars on ebay.
My current favorite IMU type sensor is the BNO055. It's the same price as the DE sensor.
There are certainly times when an accelerometer with an analog output would have an advantage over a sensor with digital output but since you're converting the analog to digital data anyway, you might want to consider using an inexpensive digital sensor (if/when you're in the market for another accelerometer).
@jremington, thanks for the link. It looks very interesting.
Yes. The thing is that what should I do in software to handle the arcsin(90). I get "nan". SO, should I do like when it is nan then say 90 degrees.
MKJohn:
Yes. The thing is that what should I do in software to handle the arcsin(90). I get "nan". SO, should I do like when it is nan then say 90 degrees.
As I mentioned earlier:
DuaneDegn:
Both arc sine and arc cosine take arguments between -1 and 1. You should test the values of "a/g" to make sure it's between these values before using the inverse trig function.
if you're taking the arcsine of 90, there's likely something severely wrong with the program.
The arcsine of 1 is 90 degrees (though the angle will likely be expressed in radians). The absolute value of "a" should be less than or equal to "g". If |a| is greater than "g" then you should probably reject the reading.
Code is not an issue. I am talking about the logic, arc Sin (90) = mathematical error . What should be logic to deal with this situation.? I have seen other digital tilt meter. At 90 they say 90 degrees
MKJohn:
Code is not an issue. I am talking about the logic, arc Sin (90) = mathematical error . What should be logic to deal with this situation.?
Please read my replies again. I thought I covered this question (twice).
The sine function will return a value between -1 and 1. You need to use the same range of numbers as the input of the arcsine function. The smallest number you should take the arcsine of is -1. The largest number is 1. Test the value you're going to take the arcsine of before you actually take the arcsine. If the input to the arcsine function will be outside the range of -1 to 1, then there's something wrong with your data and wait for better data before computing the angle.
Again, you should never be taking the arcsine of 90 degrees. The angle is the output of the arcsine, not the input.
if you're taking the arcsine of 90, there's likely something severely wrong with the program.
The arcsine of 1 is 90 degrees (though the angle will likely be expressed in radians). The absolute value of "a" should be less than or equal to "g". If |a| is greater than "g" then you should probably reject the reading.