my DIS QG series inclination sensor seems to work not correctly. When i put it on my desk it shows a value of 5.80 degrees. so i got my spirit level and leveled it out perfectly and put the sensor on top. Still same problem. Does anybody know whats the reason behind this?
Further information:
Datasheet:
Wiring:
Really simple, sensor is powered by an external power source, grounds connected, output to A0 of the arduino, arduino powered by usb
Code:
int analogPin = 0;
float V = 0.0 ;
float val = 0.0 ;
float winkel = 0.0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
analogReference(DEFAULT);
val = analogRead(analogPin);
Serial.println(val);
V = val*0.0049;
Serial.println(V);
I would first measure the voltage from the sensor with a voltmeter and make sure that it outputs 0V 2.5V [+edit correction] when it is level. Then, with it held level, see what your code outputs for 'val' and 'winkel'.
In your code you should make sure that you don't allow the value of V to go outside the range -4.5 to +4.5, otherwise you'll get invalid results from asin.
Also, use code tags when posting code to make it easier to read.
I tried to measure the Output with a voltmeter but when its level it should output a Voltage of 2.5 V and my voltmeter wasnt precise enough to help. I will try to calibrate it now.