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:
I took it apart and it seems that the following reed switch is built into it.
Reed Switch:
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.
// 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!
2017-04-18 00-39-34-1.mpg (336 KB)