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. Hardware
  3. Wind speed sensor node

Wind speed sensor node

Scheduled Pinned Locked Moved Hardware
21 Posts 5 Posters 11.0k Views 4 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.
  • JohanRCJ Offline
    JohanRCJ Offline
    JohanRC
    wrote on last edited by
    #1

    Hi,

    I am building a wind speed sensor node, but I am having diffictulty's in programming the code since I have not found any example code.
    It is probably very easy but hey I am NOOB ;)

    The sensor I am using has a 0 to 5V analog output for windspeeds from 0 to 32,4 m/s.
    So what I did right now is I took the lightsensor example code and changed the formula to give me the value in m/s instead of lux, this already works.

    But now I would also like it that my Domoticz gateway would also see it as a wind speed sensor instead of a light sensor.

    Any hints/tips/help would be greatly appriciated!

    Greetz Johan

    RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

    1 Reply Last reply
    0
    • sundberg84S Offline
      sundberg84S Offline
      sundberg84
      Hardware Contributor
      wrote on last edited by
      #2

      Hi Johan!

      Nice - what kind of hardware are you using? (I want to build one).
      You need to present it as a wind sensor and not a light sensor.

      Controller: Proxmox VM - Home Assistant
      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

      1 Reply Last reply
      0
      • mfalkviddM Offline
        mfalkviddM Offline
        mfalkvidd
        Mod
        wrote on last edited by mfalkvidd
        #3

        Welcome Johan!
        Change
        V_LIGHT_LEVEL to V_WIND
        and
        S_LIGHT_LEVEL to S_WIND
        The full specification of sensor types is available at http://www.mysensors.org/download/serial_api_15#message-structure-elements

        1 Reply Last reply
        1
        • JohanRCJ Offline
          JohanRCJ Offline
          JohanRC
          wrote on last edited by
          #4

          Thanks guys I will try to change these valuess :)

          For the anemometer I use to following:
          http://www.aliexpress.com/item/0-5V-voltage-wind-speed-sensor-Voltage-output-Anemometer-360-degree-wind-speed-sensor/32371852577.html

          Greetz Johan

          RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

          1 Reply Last reply
          0
          • JohanRCJ Offline
            JohanRCJ Offline
            JohanRC
            wrote on last edited by
            #5

            Hmmz, just changing V_LIGHT_LEVEL to V_WIND and S_LIGHT_LEVEL to S_WIND doesnt seem to do the trick.
            When these values are changed, Domoticz does not seem to recognize it any more (no new devices or updated lux values).

            I think I am missing something here.

            RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

            ? 1 Reply Last reply
            0
            • JohanRCJ JohanRC

              Hmmz, just changing V_LIGHT_LEVEL to V_WIND and S_LIGHT_LEVEL to S_WIND doesnt seem to do the trick.
              When these values are changed, Domoticz does not seem to recognize it any more (no new devices or updated lux values).

              I think I am missing something here.

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @JohanRC Please post your sketch

              1 Reply Last reply
              0
              • JohanRCJ Offline
                JohanRCJ Offline
                JohanRC
                wrote on last edited by
                #7

                This is the sketch that is working with just changing the formula:

                #include <SPI.h>
                #include <MySensor.h>  
                
                #define CHILD_ID_LIGHT 0
                #define LIGHT_SENSOR_ANALOG_PIN 0
                
                unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                
                MySensor gw;
                MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
                int lastLightLevel;
                
                void setup()  
                { 
                  gw.begin();
                
                  // Send the sketch version information to the gateway and Controller
                  gw.sendSketchInfo("Light Sensor", "1.0");
                
                  // Register all sensors to gateway (they will be created as child devices)
                  gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
                }
                
                void loop()      
                {     
                  int lightLevel = (analogRead(LIGHT_SENSOR_ANALOG_PIN))/31.605; 
                  Serial.println(lightLevel);
                  if (lightLevel != lastLightLevel) {
                      gw.send(msg.set(lightLevel));
                      lastLightLevel = lightLevel;
                  }
                  gw.sleep(SLEEP_TIME);
                }
                

                And than when I change it like below it doent seem to do anything anymore

                #include <SPI.h>
                #include <MySensor.h>  
                
                #define CHILD_ID_LIGHT 0
                #define LIGHT_SENSOR_ANALOG_PIN 0
                
                unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                
                MySensor gw;
                MyMessage msg(CHILD_ID_LIGHT, V_WIND);
                int lastLightLevel;
                
                void setup()  
                { 
                  gw.begin();
                
                  // Send the sketch version information to the gateway and Controller
                  gw.sendSketchInfo("Light Sensor", "1.0");
                
                  // Register all sensors to gateway (they will be created as child devices)
                  gw.present(CHILD_ID_LIGHT, S_WIND);
                }
                
                void loop()      
                {     
                  int lightLevel = (analogRead(LIGHT_SENSOR_ANALOG_PIN))/31.605; 
                  Serial.println(lightLevel);
                  if (lightLevel != lastLightLevel) {
                      gw.send(msg.set(lightLevel));
                      lastLightLevel = lightLevel;
                  }
                  gw.sleep(SLEEP_TIME);
                }
                

                I think it is somewhere wrond in comunication text or something (I mean have a resonable amount of experiance in Arduino programming only not in the communication part).

                Thanks!

                RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

                1 Reply Last reply
                0
                • sundberg84S Offline
                  sundberg84S Offline
                  sundberg84
                  Hardware Contributor
                  wrote on last edited by
                  #8

                  Do you see anything I domoticz log? I'm thinking of you only changed sensor type it might not be supported. If so the log should tell you.

                  Controller: Proxmox VM - Home Assistant
                  MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                  MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                  RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                  1 Reply Last reply
                  0
                  • JohanRCJ Offline
                    JohanRCJ Offline
                    JohanRC
                    wrote on last edited by
                    #9

                    At 7:08 I changed to the "Wind" code, as you can see it sends its sketch info but nothing more

                    2016-01-20 07:01:02.472 Domoticz V2.3530 (c)2012-2015 GizMoCuz
                    2016-01-20 07:01:02.474 Build Hash: 9eef872, Date: 2015-11-01 11:41:18
                    2016-01-20 07:01:02.475 System: Raspberry Pi
                    2016-01-20 07:01:02.475 Startup Path: /home/pi/domoticz/
                    2016-01-20 07:01:02.850 Sunrise: 08:32:00 SunSet:16:57:00
                    2016-01-20 07:01:02.850 EventSystem: reset all events...
                    2016-01-20 07:01:02.904 Active notification subsystems: (0/10)
                    2016-01-20 07:01:03.062 Webserver started on port: 8080
                    2016-01-20 07:01:03.117 Webserver started on port: 443
                    2016-01-20 07:01:03.143 Started shared server on: 0.0.0.0
                    2016-01-20 07:01:05.148 EventSystem: reset all events...
                    2016-01-20 07:01:05.149 EventSystem: reset all device statuses...
                    2016-01-20 07:01:05.151 EventSystem: Started
                    2016-01-20 07:01:06.148 MySensors: Using serial port: /dev/ttyUSB0
                    2016-01-20 07:01:07.627 MySensors: Gateway Ready...
                    2016-01-20 07:01:07.703 MySensors: Gateway Version: 1.5
                    2016-01-20 07:02:01.877 (Arduino_Gateway) Humidity (Unknown)
                    2016-01-20 07:02:21.109 (Arduino_Gateway) General/Barometer (Barometer)
                    2016-01-20 07:02:33.803 Incoming connection from: 192.168.2.104
                    2016-01-20 07:02:34.397 (Arduino_Gateway) Humidity (Unknown)
                    2016-01-20 07:03:26.039 (Arduino_Gateway) General/Barometer (Barometer)
                    2016-01-20 07:03:34.371 (Arduino_Gateway) Lux (Windmeter)
                    2016-01-20 07:03:39.421 (Arduino_Gateway) Humidity (Unknown)
                    2016-01-20 07:04:06.690 (Arduino_Gateway) Lux (Windmeter)
                    2016-01-20 07:04:30.971 (Arduino_Gateway) General/Barometer (Barometer)
                    2016-01-20 07:05:05.811 MySensors: Node: 4, Sketch Name: Light Sensor
                    2016-01-20 07:05:05.822 MySensors: Node: 4, Sketch Version: 1.0
                    2016-01-20 07:05:05.837 (Arduino_Gateway) Lux (Windmeter)
                    2016-01-20 07:05:38.195 (Arduino_Gateway) Lux (Windmeter)
                    2016-01-20 07:06:10.553 (Arduino_Gateway) Lux (Windmeter)
                    2016-01-20 07:06:42.911 (Arduino_Gateway) Lux (Windmeter)
                    2016-01-20 07:07:15.274 (Arduino_Gateway) Lux (Windmeter)
                    2016-01-20 07:08:02.692 MySensors: Node: 4, Sketch Version: 1.0
                    2016-01-20 07:08:11.010 MySensors: Node: 4, Sketch Name: Light Sensor
                    2016-01-20 07:08:11.017 MySensors: Node: 4, Sketch Version: 1.0
                    2016-01-20 07:08:50.713 (Arduino_Gateway) General/Barometer (Barometer)
                    2016-01-20 07:09:36.974 (Arduino_Gateway) Humidity (Unknown)
                    2016-01-20 07:09:55.656 (Arduino_Gateway) General/Barometer (Barometer)

                    RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

                    1 Reply Last reply
                    0
                    • sundberg84S Offline
                      sundberg84S Offline
                      sundberg84
                      Hardware Contributor
                      wrote on last edited by sundberg84
                      #10

                      Ah... in your code it doesnt send if its the same value as before - can this be your problem (you dont have any wind today?) So since the value is zero all the time you wont get any new values?

                      if (lightLevel != lastLightLevel){ 
                      

                      Also, sensors are not shown in Domoticz until the first value is recieved.

                      Controller: Proxmox VM - Home Assistant
                      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                      1 Reply Last reply
                      0
                      • JohanRCJ Offline
                        JohanRCJ Offline
                        JohanRC
                        wrote on last edited by
                        #11

                        @sundberg84
                        No unfortunatly this is not the problem, the setup is still on my kitchen table so i can "produce wind with my finger" :)

                        The thing is when I leave the V and S values to "Light" it transfers the data without any problems you can aslo see this in the log file between 07:05 and 07:06.
                        But when I change it to WIND there is no transfer of data anymore, I can see by the TX light on my Arduino nano that it is sending info.

                        RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

                        mfalkviddM 1 Reply Last reply
                        0
                        • sundberg84S Offline
                          sundberg84S Offline
                          sundberg84
                          Hardware Contributor
                          wrote on last edited by
                          #12

                          @JOhanRC And when you changed to Vind you added the new node in devices in Domoticz?
                          It will not update the last node but create a new if you change the presentation.

                          Controller: Proxmox VM - Home Assistant
                          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                          JohanRCJ 1 Reply Last reply
                          0
                          • JohanRCJ JohanRC

                            @sundberg84
                            No unfortunatly this is not the problem, the setup is still on my kitchen table so i can "produce wind with my finger" :)

                            The thing is when I leave the V and S values to "Light" it transfers the data without any problems you can aslo see this in the log file between 07:05 and 07:06.
                            But when I change it to WIND there is no transfer of data anymore, I can see by the TX light on my Arduino nano that it is sending info.

                            mfalkviddM Offline
                            mfalkviddM Offline
                            mfalkvidd
                            Mod
                            wrote on last edited by
                            #13

                            But when I change it to WIND there is no transfer of data anymore, I can see by the TX light on my Arduino nano that it is sending info.

                            That's strange. Could you post your new sketch?

                            1 Reply Last reply
                            0
                            • sundberg84S sundberg84

                              @JOhanRC And when you changed to Vind you added the new node in devices in Domoticz?
                              It will not update the last node but create a new if you change the presentation.

                              JohanRCJ Offline
                              JohanRCJ Offline
                              JohanRC
                              wrote on last edited by JohanRC
                              #14

                              @sundberg84
                              This might be a good tip, I did not add any new node in Domoticz but I waited until would appear automaticly, this ofcourse did not happen. So I need to find out how to manually add a new node in Domoticz. (I am only a 3 days old baby regarding to Domoticz:smile: )

                              @mfalkvidd
                              My latest sketch is the one I last posted in post 8.

                              Already thanks for all the input I am not there yet but I think were getting close :)
                              When finished I think it would perhaps be a good idea to post the code as an example so more people can have the benefits of it.

                              Greetz Johan

                              RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

                              1 Reply Last reply
                              0
                              • mfalkviddM Offline
                                mfalkviddM Offline
                                mfalkvidd
                                Mod
                                wrote on last edited by
                                #15

                                ok. The changes between the two sketches look fine. What pops out is that you use pin 0 which is shared with the serial port on some Arduinos but as long as you're not using the serial port that should be fine and the code is the same in both sketches anyway.

                                How about disabling the read and sending a fixed value instead, to eliminate reading problems?

                                or add lots of Serial.println statements.

                                1 Reply Last reply
                                0
                                • F Offline
                                  F Offline
                                  flopp
                                  wrote on last edited by flopp
                                  #16

                                  You divide the value from analog sensor by 31.605 why?
                                  Edit: 1023/31.605=32.366. To get 32,4m/s?
                                  I should try to use map instead.
                                  https://www.arduino.cc/en/Reference/Map

                                  If you receive 1v that will give you 200/31.605=~7

                                  1 Reply Last reply
                                  0
                                  • F Offline
                                    F Offline
                                    flopp
                                    wrote on last edited by flopp
                                    #17

                                    This is from the link you posted

                                    Wind speed values (output voltage -0.4) /1.6 * 32.4
                                    Eg. Receive ~6m/s (1-0.4)/1.6*32.4=0.6/51.84=0.0115
                                    I don't understand what that means or did I calculate wrong?

                                    Have you measured the output voltage when you push the sensor?

                                    ? 1 Reply Last reply
                                    0
                                    • F flopp

                                      This is from the link you posted

                                      Wind speed values (output voltage -0.4) /1.6 * 32.4
                                      Eg. Receive ~6m/s (1-0.4)/1.6*32.4=0.6/51.84=0.0115
                                      I don't understand what that means or did I calculate wrong?

                                      Have you measured the output voltage when you push the sensor?

                                      ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on last edited by A Former User
                                      #18

                                      You got the wrong formula. This formula is for the sensor which output voltage is 0.4v by 0 m/s and 2.0v by 32.4 m/s

                                      If your windsensor is for 0-5v then use this:

                                      outVoltage = analogRead(A0) * (5.0 /1023.0) 
                                      speed = (outVoltage / 5) * 32.4
                                      
                                      JohanRCJ 1 Reply Last reply
                                      0
                                      • JohanRCJ Offline
                                        JohanRCJ Offline
                                        JohanRC
                                        wrote on last edited by JohanRC
                                        #19

                                        My current code that is not sending info is:

                                        #include <SPI.h>
                                        #include <MySensor.h>  
                                        
                                        #define CHILD_ID_WIND 1
                                        #define WIND_SENSOR_ANALOG_PIN 1
                                        
                                        unsigned long SLEEP_TIME = 10000; // Sleep time between reads (in milliseconds)
                                        
                                        MySensor gw;
                                        MyMessage msg(CHILD_ID_WIND, V_WIND);
                                        float lastWindLevel;
                                        
                                        void setup()  
                                        { 
                                          gw.begin();
                                        
                                          // Send the sketch version information to the gateway and Controller
                                          gw.sendSketchInfo("Wind Sensor", "2.0");
                                        
                                          // Register all sensors to gateway (they will be created as child devices)
                                          gw.present(CHILD_ID_WIND, S_WIND);
                                        }
                                        
                                        void loop()      
                                        {     
                                          float windLevel = (analogRead(WIND_SENSOR_ANALOG_PIN))/31.605; 
                                          Serial.println(windLevel);
                                          if (windLevel != lastWindLevel) {
                                              gw.send(msg.set(windLevel, 1));
                                              lastWindLevel = windLevel;
                                          }
                                          gw.sleep(SLEEP_TIME);
                                        }
                                        

                                        The code that is sending data (in lux) is:

                                        #include <SPI.h>
                                        #include <MySensor.h>  
                                        
                                        #define CHILD_ID_WIND 1
                                        #define WIND_SENSOR_ANALOG_PIN 1
                                        
                                        unsigned long SLEEP_TIME = 10000; // Sleep time between reads (in milliseconds)
                                        
                                        MySensor gw;
                                        MyMessage msg(CHILD_ID_WIND, V_LIGHT_LEVEL);
                                        float lastWindLevel;
                                        
                                        void setup()  
                                        { 
                                          gw.begin();
                                        
                                          // Send the sketch version information to the gateway and Controller
                                          gw.sendSketchInfo("Wind Sensor", "2.0");
                                        
                                          // Register all sensors to gateway (they will be created as child devices)
                                          gw.present(CHILD_ID_WIND, S_LIGHT_LEVEL);
                                        }
                                        
                                        void loop()      
                                        {     
                                          float windLevel = (analogRead(WIND_SENSOR_ANALOG_PIN))/31.605; 
                                          Serial.println(windLevel);
                                          if (windLevel != lastWindLevel) {
                                              gw.send(msg.set(windLevel, 1));
                                              lastWindLevel = windLevel;
                                          }
                                          gw.sleep(SLEEP_TIME);
                                        }
                                        

                                        I dont really see why my formula is wrong, my sensor output is 0V to 5V in wind ranging from 0m/s to 32,4ms.
                                        This means when I have 5V on the input sensor (32,4m/s) I will measure a value of 1023 when I devide this through 31,605 I will read a value of 32,368 m/s
                                        I have made it a float and rounded it to one decimal, so I dont realy see the problem here (please correct me if I am wrong)

                                        I am more and more suspecting that there might be something going on on the Domoticz side.

                                        RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

                                        1 Reply Last reply
                                        0
                                        • ? A Former User

                                          You got the wrong formula. This formula is for the sensor which output voltage is 0.4v by 0 m/s and 2.0v by 32.4 m/s

                                          If your windsensor is for 0-5v then use this:

                                          outVoltage = analogRead(A0) * (5.0 /1023.0) 
                                          speed = (outVoltage / 5) * 32.4
                                          
                                          JohanRCJ Offline
                                          JohanRCJ Offline
                                          JohanRC
                                          wrote on last edited by
                                          #20

                                          @kenci
                                          Ah I checked the manufacturers data again and now see what you mean :)
                                          I will change this, thanx!

                                          RaspberryPi Domoticz - Serial gateway - 12 nodes and counting

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


                                          11

                                          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