Go Down

Topic: Wind Sensor with Reed Switch and Arduino Nano (Read 181 times) previous topic - next topic

motourer

Apr 18, 2017, 12:51 am Last Edit: Apr 18, 2017, 01:22 am by motourer
Hi All,

I have spent a long time trying to get my wind sensor working with both Arduino and Raspberry, and not having any success at all.

What I am now trying to figure out is if I have a broken sensor, or if I am doing something wrong? It seems to me that whatever I try, the pulses are not being detected by the Arduino Nano.

I would really appreciate some help on the next debugging steps.

Here is the Wind Sensor I am using. Other people seem to be having more luck with it.

Wind Sensor:
https://www.amazon.de/Eltako-Windsensor-WS/dp/B0018LBFG8

I took it apart and it seems that the following reed switch is built into it.

Reed Switch:
http://www.littelfuse.com/products/magnetic-sensors-and-reed-switches/reed-switches/59050.aspx

Wiring:
Wind Sensor has 2 wires. One is attached to Arduino Nano D2 and the other to 3.3v.

If I set digital pin 2 to HIGH I get permanently 0 RPM, and if I set it to LOW, I get permanently 100, regardless of how fast the wind sensor is turning, if at all?

Attached are some photos and a video. I took the wind sensor apart and in the video attached you can see me using the reed switch manually together with the multimeter set to continuity test mode. Applying the magnet to the reed switch appears to have the desired effect. However, this is not translating to a recognised pulse on my Arduino setup. No luck on the Raspberry either.

I have tried all sorts of code snippets from the internet, but the result is always the same - that the pulses are somehow not coming through.

Below is some (edited) code I am using from the internet. I have also tried others and read quite a bit on how the reed sensor is supposed to work. From what I can tell, the reed sensor is a pretty simple device, so I can't understand that it's still not working. :(

Code: [Select]
// An anemometer for the Arduino
int LogInterval;
int SampInterval=2;   //Number of seconds in the LogInterval

#define WAIT_TO_START    0 // Wait for serial input in setup()

const byte nsamp=10;

#define WindPin 2

// Wind variables
bool SeeHigh=false;
int CntRPM=0;
unsigned long CntPeriod=0;
float RPM=0.0;
float AvPeriod=0.0;
float MPH=0.0;
float Twc=0.0;  //Wind chill Temperature

// Timing counters
unsigned long StartTime;  //Log Interval counter
unsigned long StartPeriod=0;  // Period Start
unsigned long timeSense=0;

void setup()
{
  analogReference(EXTERNAL); //3.3V connected to AREF thru 3.3K AREF=3VDC

  Serial.begin(9600);
  Serial.println();
  pinMode(WindPin,INPUT_PULLUP);
  digitalWrite(WindPin,HIGH);
 
  #if WAIT_TO_START
    Serial.println("Type any character to start");
    while (!Serial.available());
  #endif //WAIT_TO_START

  Serial.println("CntRPM",RPM, MPH");

  LogInterval=SampInterval*1000;   //  sec between entries
  StartTime=millis(); //Initialize StartTime

}


void loop()
{
 
  //Serial.print(digitalRead(WindPin));
  // Wind calculator Look for High
  if (digitalRead(WindPin)==HIGH)
    {
    SeeHigh=true;

  }
  //Look for Low thus a High to Low transistion
  else if (SeeHigh==true)
  {
    if (StartPeriod != 0) //Not first sampleFrt
    {
      // Number of milliseconds in a revolution, added together
      CntPeriod=CntPeriod+millis()-StartPeriod;
    }
    StartPeriod=millis();
    //Increment counter
    CntRPM++;
    SeeHigh=false;

  }
   
  if ((millis()-StartTime)>long(LogInterval))  // Log Interval has passed
  {
    // Do Wind calculations for LogInterval
    // RPM is calculated, Period is averaged
    RPM=CntRPM*(60.0/SampInterval);
    AvPeriod=CntPeriod/(CntRPM-1);
    MPH=RPM*.054; //Estimate
    Serial.print(CntRPM);
    Serial.print(", ");       
    Serial.print(RPM,1);
    Serial.print(", ");   
    Serial.print(MPH,1);
    Serial.print(", ");   
 
    StartTime=millis();
    Serial.println();

    StartTime = millis(); //Get StartTime for next LogInterval
    // Clear variables for next LogInterval
    SeeHigh=false;
    CntRPM=0;
    AvPeriod=0.0;
  }
}



Any help would be greatly appreciated so that I can either move on to another wind sensor (if this one is indeed broken), or finally get this on working.

Thanks!

Paul_KD7HB

You can easily test the reed switch with an Ohm meter. Connect the two wires to the meter, and low scale, and rotate the part with the magnet. If the reed switch is working, there will be one or two positions where the Ohms go to zero, or close to it.

The connect one wire to Arduino ground. The other wire to pin D2, like you have it.

Then in your program:
 pinMode(2, INPUT_PULLUP);  // pin is LOW when anemometer switch is closed
  attachInterrupt(0, anemoCount, FALLING);  // interrupt when anemometer magnet closes switch. Twice per rev.

My anemometer rotates the magnet above the reed switch, so there are two closes and opens per rotation. Yours may only have one.

Set up an interrupt function to count the closures. My interrupt function is named "anemoCount". Yours will be anything you want.

In your main loop, disable interrupts, save the switch counter in a work integer, possibly zero the switch counter and re-enable the interrupts.

This should show you if the switch is working properly or not.

Paul

motourer

Thanks Paul! My anemometer does the same thing. The magnet is attached to the spinning cups and rotates above the reed switch.
I will try your suggestion tonight after work (CET).

jremington

All variable associated with timing functions like millis() should be unsigned long.

The following will not always work as you expect:
Code: [Select]
int LogInterval;

Study the examples that come with the Arduino IDE on how to wire and read switches. You need either a pullup (e.g. INPUT_PULLUP) or pulldown resistor.

Beware of switch bounce, which leads to multiple counts when the switch closes. There are several methods to avoid that.

motourer

Ok, the multi meter always shows 0 resistance when connected to the two cables, regardless of the position of the magnet on the reed switch. My multi-meter is auto range (so can't put it into low scale mode), however, I just checked my multimeter with a 1 ohm resistor just to rule out it's not my multimeter that is broken, and it detected the 1 ohm resistance fine.
I guess that means the reed switch is probably not working, or at least the wiring/PCB that comes after the reed switch

Having just said all that, I just tried connecting the multimeter directly to the reed switch, rather than to the end of the wires. In this case I get 220k ohm resistance, which goes down to 0 when I apply the magnet!

So it seems there is something between the reed switch and the end of the cables that is stopping it from working.

Maybe I can rewire/resolder it and connect the reed switch directly and bypass the PCB? Would that work?

motourer

@jremington, I will try that as soon as I have the hardware working. :)

Paul_KD7HB

My unit has only the reed switch in the anemometer head. Seems like your has something more.

I did extensive testing with an oscilloscope to see if bouncing contacts is a problem and never detected any bounce. I think the positioning of the bar magnet in the same plane as the reed switch is why. The magnetic field is always enclosing the steel leaves of the switch. It rotates to open the switch at 90 degrees and pulls then close at 0 and 180 degrees.

Paul

Go Up