WIND DIRECTION HELP

So i whant to make wind direction sensor and i stuck on program, my main sensors are hall sensors activated by magnet.I whant to use digital inputs for that. I made this: int hallPin1=53; int hallPin2=52; int hallPin3=51; int hallPin4=50; int hallPin5=49;

void setup() { pinMode(hallPin1,INPUT); pinMode(hallPin2,INPUT); pinMode(hallPin3,INPUT); pinMode(hallPin4,INPUT); pinMode(hallPin5,INPUT); digitalWrite(hallPin1,LOW); digitalWrite(hallPin2,LOW); digitalWrite(hallPin3,LOW); digitalWrite(hallPin4,LOW); digitalWrite(hallPin5,LOW); Serial.begin(9600); }

void loop(){ digitalRead(hallPin1); digitalRead(hallPin2); digitalRead(hallPin3); digitalRead(hallPin4); digitalRead(hallPin5);

if( digitalRead(hallPin1)==HIGH) { Serial.println("N"); } else if (digitalRead(hallPin2)==HIGH) { Serial.println("NNE"); } else if (digitalRead(hallPin3)==HIGH) { Serial.println("NE"); } else if (digitalRead(hallPin4)==HIGH) { Serial.println("ENE"); } else if (digitalRead(hallPin5)==HIGH) { Serial.println("E"); }

delay (2000); }

and im geting repeatebly on Monitor: NNE and if i activate secound 52 pin i get NE, and im little confused couse when im activating "wrong" pin i get wrong output. Can you please help me?

your code.. small changes in layout only:

byte n=53;
byte nne=52;
byte ne=51;
byte ene=50;
byte e=49;


void setup() {
  pinMode(n,INPUT);
  pinMode(nne,INPUT);
  pinMode(ne,INPUT);
  pinMode(ene,INPUT);
  pinMode(e,INPUT);
  Serial.begin(9600);
}

void loop()
{
  if( digitalRead(n)==HIGH)
    Serial.println("N");
  else if (digitalRead(nne)==HIGH)
    Serial.println("NNE");
  else if (digitalRead(ne)==HIGH)
    Serial.println("NE");
  else if (digitalRead(ene)==HIGH)
    Serial.println("ENE");
  else if (digitalRead(e)==HIGH)
    Serial.println("E");
  delay (2000);
}

It two sensors are triggered - this code will reflect 1.st hit only

knut_ny: your code.. small changes in layout only:

byte n=53;
byte nne=52;
byte ne=51;
byte ene=50;
byte e=49;

void setup() {   pinMode(n,INPUT);   pinMode(nne,INPUT);   pinMode(ne,INPUT);   pinMode(ene,INPUT);   pinMode(e,INPUT);   Serial.begin(9600); }

void loop() {   if( digitalRead(n)==HIGH)     Serial.println("N");   else if (digitalRead(nne)==HIGH)     Serial.println("NNE");   else if (digitalRead(ne)==HIGH)     Serial.println("NE");   else if (digitalRead(ene)==HIGH)     Serial.println("ENE");   else if (digitalRead(e)==HIGH)     Serial.println("E");   delay (2000); }




It two sensors are triggered - this code will reflect 1.st hit only

And still i always get N on Monitor and only when i activate secound pin i get NNE and other ones dond respond

EpicMadafaka: And still i always get N on Monitor and only when i activate secound pin i get NNE and other ones dond respond

When i activate first pin i get NNE other ones dont respond

The routine selects 1.st hit only.

As a test: remove all 'else' , so there are 5 seperat if-statements.

Looks like more than one sensor is activated simultaniously.