Hello all.
First of all, thanks for any guidance/help throughout this project; it is all very much appreciated. My project is a visual and auditory experience that will be part of an exhibition in may next year. The idea is that through projections and sounds, the viewer/listener will be able to see and hear my abstract interpretations of the wind. This will be achieved via the use of Processing and Arduino.
At the moment, I am currently working on learning Processing and getting the arduino wired up and working, by 10/11/12 I aim to get the arduino part of the project fully functional. For wind input, a Vortex Wind Speed Sensor is used in conjunction with an arduino uno. The sensor itself is essentially a reed switch. When the reed switch contacts, 5V is diverted to ground which triggers an interrupt on pin 3. Below is a sketch of how the circuit will work:
The circuit fully wired up:
To test my circuit, I took code from a previous weather station project. I am currently getting serial readings, so I know my circuit works. If I let the wind sensor (reed switch) stop spinning however,it breaks: It will for example read 20 mph, then continuously read 0mph unless I reset the Arduino. I am wanting to strip down this code to its core functionality, as I won't really need to precisely measure wind speed: rather just 4 or 5 states of wind velocity. Before I do this I need to figure out why the counter isn't resetting after it reads 0. Please could someone explain to me what is wrong with the code below that stops wind speed being measured.
#define uint unsigned int
#define ulong unsigned long
#define PIN_ANEMOMETER 3 // Digital 3
// How often we want to calculate wind speed
#define MSECS_CALC_WIND_SPEED 5000
volatile int numRevsAnemometer = 0; // Incremented in the interrupt
ulong nextCalcSpeed; // When we next calc the wind speed
ulong time; // Millis() at each start of loop().
//=======================================================
// Initialize
//=======================================================
void setup() {
Serial.begin(9600);
pinMode(PIN_ANEMOMETER, INPUT);
digitalWrite(PIN_ANEMOMETER, HIGH);
attachInterrupt(0, countAnemometer, FALLING);
nextCalcSpeed = millis() + MSECS_CALC_WIND_SPEED;
}
//=======================================================
// Main loop.
//=======================================================
void loop() {
time = millis();
if (time >= nextCalcSpeed) {
calcWindSpeed();
nextCalcSpeed = time + MSECS_CALC_WIND_SPEED;
}
}
//=======================================================
// Interrupt handler for anemometer. Called each time the reed
// switch triggers (one revolution).
//=======================================================
void countAnemometer() {
numRevsAnemometer++;
}
//=======================================================
// Calculate the wind speed, and send to serial port.
// 1 rev/sec = 2.5 mph
//=======================================================
void calcWindSpeed() {
int x, iSpeed;
// This will produce mph * 10
// (didn't calc right when done as one statement)
long speed = 25000;//2.5 mph * 1000
speed *= numRevsAnemometer;
speed /= MSECS_CALC_WIND_SPEED;
iSpeed = speed; // Need this for formatting below
Serial.print("Wind speed: ");
x = iSpeed / 10;
Serial.print(x);
Serial.print('.');
x = iSpeed % 10;
Serial.print(x);
Serial.print(" mph, ");
numRevsAnemometer = 0; // Reset counter
}
Resources used so far:
http://www.audon.co.uk/weather_sensors/vortex.html
USB Data Logger | Archived Forum (code found in comments section that i've used to test the sensor)
timeinventorskabinet.org
http://arduino.cc/forum/index.php?topic=116144.0
http://community.cosm.com/arduino/anemometer
ARDUINO DAVIS WEATHERLINK WM-II PROJECT