Making a compass

Hi,

With the Dinsmore digital sensor I want to build a compass.
I connected the 4 outputs directly to 4 analog inputs from the Arduino.
Then read them and display the result on a display.
The problem is that the outputs are very variable when the device isn’t moving.
I get the following results on the screen:
S = Output (sensor).

Start positionS1: min: 50 max: 93 S2: min:35 max: 85 S3: 0 S4: 0
90 degree turnS1: 0 S2:min:27 max: 42 S3: 0 S4: min: 35 max: 56
180 degree turnS1: 0 S2: 0 S3: min: 17 max: 45 S4: min: 54 max: 76
270 degree turnS1: min: 38 max: 70 S2: 0 S3: min: 0 max: 47 S4: 0

I looked at the display for approximately 10 second and took the highest and lowest value. The goal is to get the amount of degrees I’m from the north. Can somebody help me with processing this data ?

#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12,13);
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int analogPin1 = 5;
int analogPin2 = 4;
int analogPin3 = 3;
int analogPin4 = 2;

void setup(){}

void loop() {
  lcd.clear();
  val1 = analogRead(analogPin1);
  val2 = analogRead(analogPin2);
  val3 = analogRead(analogPin3);
  val4 = analogRead(analogPin4);
  lcd.print("S1:");
  lcd.setCursor(3, 0);
  lcd.print(val1);
  lcd.setCursor(8, 0);
  lcd.print("S2:");
  lcd.setCursor(11, 0);
  lcd.print(val2);
  lcd.setCursor(0, 1);
  lcd.print("S3:");
  lcd.setCursor(3, 1);
  lcd.print(val3);
  lcd.setCursor(8, 1);
  lcd.print("S4:");
  lcd.setCursor(11, 1);
  lcd.print(val4);
  delay(500);
}

Dimby

Looking at the data sheet implies there are only two outputs but you talk of four how have you got them set up?

The data sheet also makes reference to a well decoupled supply. When a data sheet does this it usually means it. Make sure the sensor supplies are heavy decoupled from the arduino power supply. De-coupling

Finally the data sheet talks about only looking at one output to get the direction and using the voltage readings to determine what output that is. This is not done in your software. You could also try and average a few readings to get them a bit more steady.

However, this sort of thing is to be expected from a sensor of this sort you will not get a rock steady reading. It is not being subject to any vibration is it?