Last summer we installed new electric sunshades on our house. A few weeks later in the autumn we discovered they are quite wind sensitive and need to be protected. We could not let them down when leaving the house and also at night we had to be careful or stand up and raise them in all rooms as soon there was wind or storm.
This was the point when I decided to install a wind sensor to control the sunshades. So the first thing was to find something that works well with our existing house automation system "Homematic", which was not easy and every solution that I found was either expensive and/or not working well together with Homematic.
I decided to build my own sensor logic using a cheap wind sensor from Eltako and a Raspberry Pi 2 running Windows 10 IoT Core.
The setupThe setup itself is quite simple. The wind sensor has a built-in switch that closes and opens 2 times every turn the sensor makes. So I only had to hook it up to a GPIO pin and GND (GPIO5 in this case) of the Raspberry and count the number of closings during a given time frame. From that I can calculate the wind speed. The formula originally was provided from Eltako and was refined by Jörg Zieren (http://zieren.de/ip-anemometer/).
The complicated part was how to install a Raspberry Pi at the outside of our house, being protected against wind and weather.
Using a weatherproof case from the local hardware store, a power plug adapter and a small AC-Adapter, which fits in the case, I prepared the power supply for the Raspberry Pi.
The Windows 10 IoT Core UWP app itself is relatively simple. It counts how often GPIO5 gets triggered per second and calculates the wind speed.
private const int BUTTON_PIN = 5;
private GpioPin sensorPin;
private SolidColorBrush redBrush = new SolidColorBrush(Windows.UI.Colors.Red);
private SolidColorBrush greenBrush = new SolidColorBrush(Windows.UI.Colors.Green);
private Timer windsensorTimer;
public MainPage()
{
InitializeComponent();
InitGPIO();
}
private volatile int counter = 0;
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
WindStatus.Text = "There is no GPIO controller on this device.";
return;
}
sensorPin = gpio.OpenPin(BUTTON_PIN);
// Check if input pull-up resistors are supported
if (sensorPin.IsDriveModeSupported(GpioPinDriveMode.InputPullDown))
sensorPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
sensorPin.SetDriveMode(GpioPinDriveMode.Input);
// Set a debounce timeout to filter out switch bounce noise from a button press
sensorPin.DebounceTimeout = TimeSpan.FromMilliseconds(10);
// Register for the ValueChanged event so our buttonPin_ValueChanged
// function is called when the button is pressed
sensorPin.ValueChanged += windsensorTriggered;
WindStatus.Text = "GPIO pins initialized correctly.";
// calculate windspeed every second
windsensorTimer = new Timer(windsensorTimerCallback, null, 1000, 1000);
}
private async void windsensorTimerCallback(object state) // this timer is called every 1000ms
{
var current = counter*2; // two signals per round
counter = 0;
// formula from: http://zieren.de/ip-anemometer/
var windspeed = 1.761 / (1 + current) + 3.013 * current;
if (windspeed<=1.761)
{
windspeed = 0;
}
Debug.WriteLine("Wind speed " + windspeed + " km/h");
var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
WindStatus.Text = "Wind speed " + windspeed + " km/h";
});
}
private void windsensorTriggered(GpioPin sender, GpioPinValueChangedEventArgs e)
{
// toggle the wind sensor rpm counter
if (e.Edge == GpioPinEdge.FallingEdge)
{
counter++;
}
}
There is another branch in the GitHub project under: https://github.com/kreuzhofer/windows10ioteltakowindsensor/tree/temperature_sensor
Which forwards the wind sensor data to another Raspberry Pi running Windows 10 IoT Core and the iot_homesecurity app.
This app takes several other sensors (temperature, light, etc.) and decides what to do in the right moment. For example, there the decision is made, if the wind speed goes over a certain threshold, to trigger the Homematic system to raise the sunshades.
Comments
Please log in or sign up to comment.