Wind Data Logging
A friend of mine wanted to find out which way the wind generally blows in his garden, as he is planning to install a pond and the wind direction would influence where he placed certain equipment.
So we decided on wind speed and direction sensors, logging the data to SD card over a period of days/weeks. After some quick research on SD cards, it turns out they are rather easy to interface with Arduino via SPI; the only issue being that SD cards’ logic is 3.3v.
I ordered an SD card breakout board (cheap at a few pound) and while waiting for it to arrive, made my own crude version; SD card power supplied from the Arduino’s 3.3v and resistor pair voltage dividers for the data lines.
The wind speed sensor simply closed it’s contacts twice per rotation. The direction sensor was a little more complicated, at eight equally spaced positions different resistances were measured across it’s two connections.
So the plan was to connect the speed sensor to one of the Arduino’s digital pins (one with interrupt capability) utilising internal pull-up resistor, and the direction sensor to one of the analog pins so that we can effectively convert the resistance to an analog value. Notice the 0.1 microfarad decoupling cap across the speed sensor for de-bounce.
See this schematic I put together.
I used a spare micro-SD card adaptor as a ‘socket’ by soldering some header pins to it. While testing, I temporarily hooked up an LCD display to make it a little easier to see what was going on.
How it works:
Upon power-up, a random filename is created ready for data to be recorded into. e.g. XXXX-1.CSV
The wind speed sensor is connected to pin 2 of the Arduino, which can be utilised as an interrupt. Every time the speed sensor makes half a turn, the interrupt function runs.
On each run, the wind speed counter is incremented, and the position logged.
Once per minute, the average speed over that minute is calculated, along with the most common direction recorded. These values are then written to the current .CSV file on the SD card.
Every 6 hours a new file is created, XXXX-2.CSV then XXXX-3.CSV etc. Each holding 360 entries. We decided to do this in case of data-loss, at least we would only lose 6 hours and not the entire week for example. The reason for the random filename, was incase power was lost and then regained for some reason, we didn’t want the files to become overwritten (better safe than sorry eh).
Once it was confirmed working, I wrote it to a 5v Arduino mini pro, and connected it all up with the micro SD card board. One option would have been to use a 3.3v Arduino mini pro, negating the use for a proper SD card board and it’s 3.3v regulated logic level conversion. Anyway, it works and does the job.
Here’s some charts compiled by my friend from the data collected in the first week (click to enlarge):
Here you can download the xlsx file my friend used to create the above charts : Wind.xlsx
Find the code below.