Hi !!!
I am working on weather station project but I am having difficulties in wiring the wind vane and the anemometer to Arduino uno.
I tried to follow the datasheet instructions from sparkfun but it is not very clear to me.
Can anyone supply me with an easy to follow schematic wiring where I can visualise which wire color connects to what.
This is my code below and it outputs number (zero, zero, zero) for all the values from the sensors.
I have a deep suspicious that the failure has to do with the my wiring since I am not sure if I am doing it the right way
Thank you in advance!!!
// Set up the inputs and the interrupts
#define ANEMOMETER_PIN 3
#define ANEMOMETER_INT 1
#define VANE_PWR 4
#define VANE_PIN A0
#define RAIN_GAUGE_PIN 2
#define RAIN_GAUGE_INT 0
void setup() {
Serial.begin(9600);
pinMode(ANEMOMETER_PIN,INPUT);
digitalWrite(ANEMOMETER_PIN,HIGH); // Turn on the internal Pull Up Resistor
pinMode(RAIN_GAUGE_PIN,INPUT);
digitalWrite(RAIN_GAUGE_PIN,HIGH); // Turn on the internal Pull Up Resistor
pinMode(VANE_PWR,OUTPUT);
digitalWrite(VANE_PWR,LOW);
attachInterrupt(ANEMOMETER_INT,anemometerClick,FALLING);
attachInterrupt(RAIN_GAUGE_INT,rainGageClick,FALLING);
interrupts();
}
// ---------------------
// Wind speed (anemometer)
#define WIND_FACTOR 2.4
#define TEST_PAUSE 60000
volatile unsigned long anem_count=0;
volatile unsigned long anem_last=0;
volatile unsigned long anem_min=0xffffffff;
double getUnitWind()
{
unsigned long reading=anem_count;
anem_count=0;
return (WIND_FACTOR*reading)/(TEST_PAUSE/1000);
}
double getGust()
{
unsigned long reading=anem_min;
anem_min=0xffffffff;
double time=reading/1000000.0;
return (1/(reading/1000000.0))*WIND_FACTOR;
}
void anemometerClick()
{
long thisTime=micros()-anem_last;
anem_last=micros();
if(thisTime>500)
{
anem_count++;
if(thisTime<anem_min)
{
anem_min=thisTime;
}
}
}
// ---------------------
// Wind direction (vane)
static const int vaneValues[] PROGMEM={66,84,92,127,184,244,287,406,461,600,631,702,786,827,889,946};
static const int vaneDirections[] PROGMEM={1125,675,900,1575,1350,2025,1800,225,450,2475,2250,3375,0,2925,3150,2700};
double getWindVane()
{
analogReference(DEFAULT);
digitalWrite(VANE_PWR,HIGH);
delay(100);
for(int n=0;n<10;n++)
{
analogRead(VANE_PIN);
}
unsigned int reading=analogRead(VANE_PIN);
digitalWrite(VANE_PWR,LOW);
unsigned int lastDiff=2048;
for (int n=0;n<16;n++)
{
int diff=reading-pgm_read_word(&vaneValues[n]);
diff=abs(diff);
if(diff==0)
return pgm_read_word(&vaneDirections[n])/10.0;
if(diff>lastDiff)
{
return pgm_read_word(&vaneDirections[n-1])/10.0;
}
lastDiff=diff;
}
return pgm_read_word(&vaneDirections[15])/10.0;
}
// ---------------------
// Rain gauge
#define RAIN_FACTOR 0.2794
volatile unsigned long rain_count=0;
volatile unsigned long rain_last=0;
double getUnitRain()
{
unsigned long reading=rain_count;
rain_count=0;
double unit_rain=reading*RAIN_FACTOR;
return unit_rain;
}
void rainGageClick()
{
long thisTime=micros()-rain_last;
rain_last=micros();
if(thisTime>500)
{
rain_count++;
}
}
// ---------------------
// Main loop
void loop() {
Serial.println(getUnitWind());
Serial.println(getGust());
Serial.println(getWindVane());
Serial.println(getUnitRain());
Serial.println(" ");
delay(10000);
}