Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. MyWindSensor

MyWindSensor

Scheduled Pinned Locked Moved My Project
5 Posts 3 Posters 2.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Bert RamselaarB Offline
    Bert RamselaarB Offline
    Bert Ramselaar
    wrote on last edited by Yveaux
    #1

    Made een Windsensor for MySensors, Works well!
    used an adafruit https://www.adafruit.com/product/1733 windmeter.

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * versie 1.1 bert ramselaar  
     * Used an UNO with a NRF24+ with external antenna
     *
     * DESCRIPTION
     * Arduino Wind Sensor
     * Adafruit Anemometer Wind Speed Sensor -> https://www.adafruit.com/product/1733
     * connect the sensor as follows :
     *   VCC  (brown)      >>> 5V
     *   A    (blue)      >>> A0 or any other analog pin
     *   GND  (black)      >>> GND
     *
    
     *
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <MySensors.h>
    
    #define CHILD_ID_WIND 0
    #define WIND_SENSOR_ANALOG_PIN 0
    
    unsigned long SLEEP_TIME = 2000; // Sleep time between reads (in milliseconds)
    
    // VARIABLES
    float W_Raw_A0 = 0; // stores the RAW value coming from the sensor 0 to 1023
    float W_Volt = 0; // stores voltage calculated form A0
    float W_WindSpeed = 0; // Windspeed in meters per second (m/s)
    float W_WindSpeed_last = 0; // previus Windspeed sended
    float W_Voltage_Conversion = .004882814; //This constant maps the value provided from the analog read function, which ranges from 0 to 1023, to actual voltage, which ranges from 0V to 5V
    float W_voltageMin = .4; // Mininum output voltage from anemometer in mV.
    float W_voltageMax = 2.0; // Maximum output voltage from anemometer in mV.
    float W_windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage
    float W_windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage
    int W_beaufort = 0; // Calculated beaufort scale
    
    MyMessage windMsg(CHILD_ID_WIND, V_WIND);
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Wind Sensor", "1.1");
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_WIND, S_WIND);
    }
    
    void loop()
    {
      W_Raw_A0 = analogRead(WIND_SENSOR_ANALOG_PIN); // Get WIND value from A0
      W_Volt = W_Raw_A0 * W_Voltage_Conversion; //Convert sensor value to actual voltage
    
    //Convert voltage value to wind speed using range of max and min voltages and wind speed for the anemometer
    if (W_Volt <= W_voltageMin)
    {
     W_WindSpeed = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
    }
    else 
    {
      // calculate winspeed in Meters per Second 
      W_WindSpeed = (W_Volt - W_voltageMin) * W_windSpeedMax / (W_voltageMax - W_voltageMin); //For voltages above minimum value, use the linear relationship to calculate wind speed.
      // corrected // ~~W_WindSpeed = W_WindSpeed * 3.6 // convert from m/s to km/h~~
    }
    
      Serial.print("Raw Signal Value (0-1023): ");
      Serial.print(W_Raw_A0);
    
      Serial.print(" - Voltage: ");
      Serial.print(W_Volt);
    
      Serial.print(" - Windspeed M/S: ");
      Serial.print(W_WindSpeed); // unit: M/S
    
      Serial.print(" - Beaufort: ");
      Serial.println(beaufort()); // unit: beaufort scale
    
      if (ceil(W_WindSpeed) != W_WindSpeed_last) 
      {
    **/// CHANGED convert float to de nearest integer and converted (W_WindSpeed * 3.6) to km/h ///**
    send(windMsg.set((int16_t)ceil(W_WindSpeed * 3.6))); 
     W_WindSpeed_last = ceil(W_WindSpeed);
    
        //beaufort(); // option windspeed in beafort
        //send(windMsg.set(W_beaufort)); // option windspeed in beafort
      }
    
      sleep(SLEEP_TIME);
    }
    
    int beaufort(void)
    { 
        if (W_WindSpeed < 0.39)
        {
        W_beaufort = 0;
        return W_beaufort;
        } 
        else if (W_WindSpeed >= 0.3 & W_WindSpeed <= 1.5)
        {
        W_beaufort = 1;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 1.6 & W_WindSpeed <= 3.3)
        {
        W_beaufort = 2;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 3.4 & W_WindSpeed <= 5.4)
        {
        W_beaufort = 3;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 5.5 & W_WindSpeed <= 7.9)
        {
        W_beaufort = 4;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 8.0 & W_WindSpeed <= 10.7)
        {
        W_beaufort = 5;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 10.8 & W_WindSpeed <= 13.8)
        {
        W_beaufort = 6;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 13.9 & W_WindSpeed <= 17.1)
        {
        W_beaufort = 7;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 17.2 & W_WindSpeed <= 20.7)
        {
        W_beaufort = 8;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 20.8 & W_WindSpeed <= 24.4)
        {
        W_beaufort = 9;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 24.5 & W_WindSpeed <= 28.4)
        {
        W_beaufort = 10;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 28.5 & W_WindSpeed <= 32.6)
        {
        W_beaufort = 11;
        return W_beaufort;
        }
        else if (W_WindSpeed >= 32.7)
        {
        W_beaufort = 12;
        return W_beaufort;
        }
     }
    
    YveauxY 1 Reply Last reply
    2
    • Bert RamselaarB Bert Ramselaar

      Made een Windsensor for MySensors, Works well!
      used an adafruit https://www.adafruit.com/product/1733 windmeter.

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * REVISION HISTORY
       * versie 1.1 bert ramselaar  
       * Used an UNO with a NRF24+ with external antenna
       *
       * DESCRIPTION
       * Arduino Wind Sensor
       * Adafruit Anemometer Wind Speed Sensor -> https://www.adafruit.com/product/1733
       * connect the sensor as follows :
       *   VCC  (brown)      >>> 5V
       *   A    (blue)      >>> A0 or any other analog pin
       *   GND  (black)      >>> GND
       *
      
       *
       */
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <MySensors.h>
      
      #define CHILD_ID_WIND 0
      #define WIND_SENSOR_ANALOG_PIN 0
      
      unsigned long SLEEP_TIME = 2000; // Sleep time between reads (in milliseconds)
      
      // VARIABLES
      float W_Raw_A0 = 0; // stores the RAW value coming from the sensor 0 to 1023
      float W_Volt = 0; // stores voltage calculated form A0
      float W_WindSpeed = 0; // Windspeed in meters per second (m/s)
      float W_WindSpeed_last = 0; // previus Windspeed sended
      float W_Voltage_Conversion = .004882814; //This constant maps the value provided from the analog read function, which ranges from 0 to 1023, to actual voltage, which ranges from 0V to 5V
      float W_voltageMin = .4; // Mininum output voltage from anemometer in mV.
      float W_voltageMax = 2.0; // Maximum output voltage from anemometer in mV.
      float W_windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage
      float W_windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage
      int W_beaufort = 0; // Calculated beaufort scale
      
      MyMessage windMsg(CHILD_ID_WIND, V_WIND);
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Wind Sensor", "1.1");
      
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_WIND, S_WIND);
      }
      
      void loop()
      {
        W_Raw_A0 = analogRead(WIND_SENSOR_ANALOG_PIN); // Get WIND value from A0
        W_Volt = W_Raw_A0 * W_Voltage_Conversion; //Convert sensor value to actual voltage
      
      //Convert voltage value to wind speed using range of max and min voltages and wind speed for the anemometer
      if (W_Volt <= W_voltageMin)
      {
       W_WindSpeed = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
      }
      else 
      {
        // calculate winspeed in Meters per Second 
        W_WindSpeed = (W_Volt - W_voltageMin) * W_windSpeedMax / (W_voltageMax - W_voltageMin); //For voltages above minimum value, use the linear relationship to calculate wind speed.
        // corrected // ~~W_WindSpeed = W_WindSpeed * 3.6 // convert from m/s to km/h~~
      }
      
        Serial.print("Raw Signal Value (0-1023): ");
        Serial.print(W_Raw_A0);
      
        Serial.print(" - Voltage: ");
        Serial.print(W_Volt);
      
        Serial.print(" - Windspeed M/S: ");
        Serial.print(W_WindSpeed); // unit: M/S
      
        Serial.print(" - Beaufort: ");
        Serial.println(beaufort()); // unit: beaufort scale
      
        if (ceil(W_WindSpeed) != W_WindSpeed_last) 
        {
      **/// CHANGED convert float to de nearest integer and converted (W_WindSpeed * 3.6) to km/h ///**
      send(windMsg.set((int16_t)ceil(W_WindSpeed * 3.6))); 
       W_WindSpeed_last = ceil(W_WindSpeed);
      
          //beaufort(); // option windspeed in beafort
          //send(windMsg.set(W_beaufort)); // option windspeed in beafort
        }
      
        sleep(SLEEP_TIME);
      }
      
      int beaufort(void)
      { 
          if (W_WindSpeed < 0.39)
          {
          W_beaufort = 0;
          return W_beaufort;
          } 
          else if (W_WindSpeed >= 0.3 & W_WindSpeed <= 1.5)
          {
          W_beaufort = 1;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 1.6 & W_WindSpeed <= 3.3)
          {
          W_beaufort = 2;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 3.4 & W_WindSpeed <= 5.4)
          {
          W_beaufort = 3;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 5.5 & W_WindSpeed <= 7.9)
          {
          W_beaufort = 4;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 8.0 & W_WindSpeed <= 10.7)
          {
          W_beaufort = 5;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 10.8 & W_WindSpeed <= 13.8)
          {
          W_beaufort = 6;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 13.9 & W_WindSpeed <= 17.1)
          {
          W_beaufort = 7;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 17.2 & W_WindSpeed <= 20.7)
          {
          W_beaufort = 8;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 20.8 & W_WindSpeed <= 24.4)
          {
          W_beaufort = 9;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 24.5 & W_WindSpeed <= 28.4)
          {
          W_beaufort = 10;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 28.5 & W_WindSpeed <= 32.6)
          {
          W_beaufort = 11;
          return W_beaufort;
          }
          else if (W_WindSpeed >= 32.7)
          {
          W_beaufort = 12;
          return W_beaufort;
          }
       }
      
      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @Bert-Ramselaar HI and welcome to the forum!
      I modified your post slightly to include code tags, which improves readability.
      Could you give some more info on your project (which sensor did you use? And did I mention that we simply looooove pictures ;-))?

      http://yveaux.blogspot.nl

      gohanG 1 Reply Last reply
      0
      • YveauxY Yveaux

        @Bert-Ramselaar HI and welcome to the forum!
        I modified your post slightly to include code tags, which improves readability.
        Could you give some more info on your project (which sensor did you use? And did I mention that we simply looooove pictures ;-))?

        gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by
        #3

        @Yveaux He actually posted the link to the sensor :)
        It is rather expensive but since it isn't a pulse counter sensor but it gives a voltage to read it is probably why it isn't cheap.

        YveauxY 2 Replies Last reply
        0
        • gohanG gohan

          @Yveaux He actually posted the link to the sensor :)
          It is rather expensive but since it isn't a pulse counter sensor but it gives a voltage to read it is probably why it isn't cheap.

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #4

          @gohan @Bert-Ramselaar sorry, I'd better not browse the forum on my phone anymore :grimacing:

          http://yveaux.blogspot.nl

          1 Reply Last reply
          1
          • gohanG gohan

            @Yveaux He actually posted the link to the sensor :)
            It is rather expensive but since it isn't a pulse counter sensor but it gives a voltage to read it is probably why it isn't cheap.

            YveauxY Offline
            YveauxY Offline
            Yveaux
            Mod
            wrote on last edited by
            #5

            @gohan said in MyWindSensor:

            since it isn't a pulse counter sensor but it gives a voltage to read it is probably why it isn't cheap

            A simple pro-mini can do the same; only costs a few €...
            Looks like it's full metal, so probably a lot more durable than the plastic ones that tend to agree rapidly in the sun...

            http://yveaux.blogspot.nl

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            21

            Online

            11.7k

            Users

            11.2k

            Topics

            113.1k

            Posts


            Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular