Problem with Wind Speed sensor



  • Hi,

    I recently bought a Windspeed sensor on Ebay: http://www.ebay.com/itm/181741789708?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT This to use it later in domoticz.

    Now, I found some sketches on MySensors which can be used on a Windsensor and domoticz, but I have hard time figure out how to what the data is that I am seeing. I attached the windsensor to a 12V powersupply and the data line of the wind speed sensor is connected to analog pin 1. Now, as a test I only read out the analog A1 line with this code:

    nomod_wspeed = (analogRead(WIND_SENSOR_ANALOG_PIN));

    When I do a Serial.print, I get these numbers below. Now what the strange thing is, I do not rotate my wind speed sensor? So I cannot understand what the data is that I am seeing here?? I would expect that everything is zero when I don't rotate it? In example on this forum, I saw that the sketches will do something with this value, but what then?

    NoMod_WS: 0
    NoMod_WS: 912
    NoMod_WS: 0
    NoMod_WS: 254
    NoMod_WS: 954
    NoMod_WS: 117
    NoMod_WS: 775
    NoMod_WS: 165
    NoMod_WS: 799
    NoMod_WS: 0
    NoMod_WS: 1023
    NoMod_WS: 0
    NoMod_WS: 1023
    NoMod_WS: 10
    NoMod_WS: 1023
    NoMod_WS: 0
    NoMod_WS: 997
    NoMod_WS: 0
    NoMod_WS: 979
    NoMod_WS: 178
    NoMod_WS: 1015
    NoMod_WS: 239
    NoMod_WS: 0
    NoMod_WS: 809
    NoMod_WS: 0
    NoMod_WS: 1023
    NoMod_WS: 0
    NoMod_WS: 1023
    NoMod_WS: 712
    NoMod_WS: 209

    Can someone help ? Is my device well attached or am I doing something wrong here?


  • Mod

    @rnollen It is advertised as a pulse sensor. This means you will get one or more digital pulses (e.g. low level is 0V, a pulse is represented by a 5V level for some time).
    I'm a bit worried by the 12V supply signal to the sensor. It doesn't say what signal level the generated pulses are.
    Your arduino is likely powered by 5V or even 3.3V (depending on the model) and 12V is definately too much for the analog and digital inputs; you might have broken it.
    Another option is that the pulse signal is so called open-collector, which means it will only pull the signal to 0V, and you have to supply the high-level of your choice.
    I would suggest to browse the internet or ask the supplier on some more info on this sensor, or even an example on how to connect it to an Arduino.
    Good luck!



  • Thanks for you're reply. On the ebay website at the product description, it is said: "Supply voltage: DC 12-24 V", so therefore I thought I needed a 12V powersupply to power this device

    I use a nano board, so I can attach a 5V to it, I will give this a try. I still need to find out first if it is broken basically 🙂 But a few things that worries me regarding this setup:

    • The picture on the ebay site shows 4 cables coming out of the device. I only see three 🙂 Regarding the other sketches, this seems to be OK, because A1 is only attached.. but I am not sure
    • When I run the sketch and I just read out the Analog pin 1, I always get data. The device doesn't needs to be attached basically. So I really don't get how the Analog 1 pin should work and why I get data when nothing is attached? I used the sketch of this topic: https://forum.mysensors.org/topic/2856/wind-speed-sensor-node/21 using the last reply. Only I deleted the direction and gust values, because I can only measure speed I think.

    Can you give me a heads up? How should you think I need to connect it? And how I must adjust the sketch in order to get the data?


  • Hero Member

    @rnollen Your values could be from a floating input. So like @Yveaux suggested the wind sensor can have an open collector output. Best to try with a multimeter first. You can connect a 10 - 100k resistor from the output to Vcc and see if you get a pulse output when rotating.


  • Mod

    @rnollen no, without more info it's just guessing and that won't help you at all.
    One thing I am quite sure about is that it doesn't have an analog output and therefore you should not try to read it with an analog input.



  • @AWI said:

    @rnollen Your values could be from a floating input. So like @Yveaux suggested the wind sensor can have an open collector output. Best to try with a multimeter first. You can connect a 10 - 100k resistor from the output to Vcc and see if you get a pulse output when rotating.

    @all thanks for all the replies. I did send an e-mail to that ebay supplier. 🙂

    @AWI: I have a 100 ohm resistor. Connect this to my breadboard, but don't know how to connect this then to an arduino? The windmeter has three cables: black / red and yellow. The yellow line is the data line and black/red are power and ground? I have a multimeter, but not sure how to use it for this purpose 🙂


  • Hero Member

    @rnollen I think you can just assume that red =positive, black = gnd and yellow = signal.
    You should connect the resistor between yellow and red if you assume an open collector output. Then power the sensor on black and red.Connect your multimeter (in volt position)(just noticed you have one) to yellow and ground and rotate the sensor slowly. A 100 ohm resistor will do for testing.



  • @AWI said:

    @rnollen I think you can just assume that red =positive, black = gnd and yellow = signal.
    You should connect the resistor between yellow and red if you assume an open collector output. Then power the sensor on black and red.Connect your multimeter (in volt position)(just noticed you have one) to yellow and ground and rotate the sensor slowly. A 100 ohm resistor will do for testing.

    Thanks. I did a quick test. Grabbed my multimeter and set it on the 20v. (2v gives me an error). Connected it like you have said, using the resistor. Used the ground and 5v of my Arduino nano as power.
    When I do not rotate; I get 4.54V on the yellow and black line. When I start rotating, it is less.. mostly around 3. But it jumps around, but always less then the 4.6 when I start to rotate. I cannot say that rotating faster gives me another or different value, I think it will go to the 3.

    So any idea 🙂


  • Hero Member

    @rnollen can you get it to a stable less than 3v when rotating.? If you can not get it stable than I there is a chance a serial protocol like "onewire" is used. Then you need a clue from the supplier. If you have stable outputs when rotating very slowly it is probably a pulse train which you can count.



  • @AWI said:

    @rnollen can you get it to a stable less than 3v when rotating.? If you can not get it stable than I there is a chance a serial protocol like "onewire" is used. Then you need a clue from the supplier. If you have stable outputs when rotating very slowly it is probably a pulse train which you can count.

    Yes, It is stable when you rotate it. Around the 3V. But how can I count it then?


  • Hero Member

    @rnollen I would expect a low high signal transition when you rotate slowly.
    0_1468496891675_upload-6bd65600-8754-4568-9dff-120fd20da85c
    If that is not the case it is hard to determine from here what kind of signal you get.. (is assume you don't have access to an oscilloscope.. 😉



  • Thanks; but how to go further from here then 🙂 Is there a way to create a sketch for this device? And how to attach it to a Nano board?

    I got a manual from the supplier: https://1drv.ms/w/s!AmsPyx0xoB6jjYo0PZZRazdA3-vPpw for this device. But I already see a difference with the wires 🙂 But to give it a start then, according to the manual it counts the pulses and that gives a windspeed 🙂


  • Hero Member

    @rnollen Hi, the manual is a bit confusing in that it mentions a "serial protocol" and also a table is mentioned with voltages and wind speed. As yours iw 3 wire we can assume it is not a RS485 output.

    Then there are you need to dertermine what kind of output it is either NPN or PNP. : PNP needs a "pull down" resistor. NPN needs a "pull up". resistor..Best thing is to test the different options with the volt meter.

    According to the table the "average" voltage should vary with the rotating spreed.

    Note that I make a lot of assumptions.... but: If you get a voltage on your meter that changes with the rotating spreed than it is time to connect the nan. With the assumption that there are pulses, best thing is to write a routine which counts the pulses in a certain time frame e.g 10 secs. (connect the nano with a either a digital or analog pin, but read with digitalread(),. There should be many examples on the web.

    Have fun



  • @AWI . I will try to find out. But for the record later, can I simply connect the 5V, ground and the Yellow dataline directly to the arduino ? Or do I still need a resistor somewhere?
    Then I will try to find I sketch to read the digital pin. Can i maybe use other pulse sketches as an example?
    I will do the Volt test, I know that the volt test remains the same when I rotate on the same speed. Don't know for sure, if I rotate faster if the volt's are the same then as before. I thought not, but I will test later tonight.


  • Hero Member

    @rnollen If you keep the voltage at 5v you can directy connect to the arduino pin. You still need a pull-up/down resistor though.

    pin D13 on the nano has a LED connected to it. It may help you in observing what is going on. A LED is much faster than a volt meter..



  • @AWI said:

    @rnollen If you keep the voltage at 5v you can directy connect to the arduino pin. You still need a pull-up/down resistor though.

    pin D13 on the nano has a LED connected to it. It may help you in observing what is going on. A LED is much faster than a volt meter..

    Sorry for all the questions 🙂 But I am a noob on this matter. I do know something of scripting, but electronics is not something where I am familiar with.
    But to summarize then how to connect it; The yellow line, will go through a resistor (which one?) and that is connected to D13. Black is Ground, Red is 5 Volt? Is this correct? And is this setup only for testing or also as the final solution later on, because the D13 is also used for the radio? Problem is: I don't know exactly what a LED is in you're example 🙂

    Edit-> Also send questions to the supplier. Maybe he can gives me an answer if it is PNP or NPN device. Also asked for schematics and how to calculate the pulses.



  • When I use the volt meter and I rotate, then the volts are pretty much the same. Rotating faster, doesn't give me higher values.
    As a test I have attached it to my Arduino nano using a 10k Pullup resistor. Found a little example sketch regarding the LED on the arduino site. As the very first test I can see the light bling on the arduino when I rotate the windmeter. Rotating it harder will make the light bling faster, rotating slower and it blings slowly. So the pulses seems to come through.

    But now, I need a vary small and basic way to start counting the pulses when it rotates. I have tried to create a very small sketch (using an example of the Arduino website). But that is not working OK. Tried to modify the examples for powermeter and watermeter which are also pulse sketches, but at this stage it has too much code.
    Does anyone have a very small example sketch to start with for my setup?



  • @AWI said:
    ..... There should be many examples on the web.

    Have fun
    Unfortunately I cannot find any working example code. Found all kind of stuff on the internet, but nothing that will give me some valuable data.
    I think that the examples on the internet mostly uses an pull up anemometer, as far as I can see the Arduino Nano also have a internal one which you can activate on the sketch. But basically, when I use a resistor, which is connected on the yellow and red wire, I am still stuck on the sketch I cannot find something desent (and small), that gives me something valuable. I now know why the windmeter is not an example on the Mysensors site 🙂 Way to difficult :).


  • Hero Member

    @rnollen It shouldn't be so complicated.. there are a many ways to do it. Start in the learning curve with the most simple method of counting pulses using the arduino builtin method pulseIn(). (non MySensors, basic arduino). You should be able to see the pulse frequency on the serial port when turning the rotor.

    const int anemometerPin = 4 ; // wherever you connected the anemometer
    unsigned long timePeriod = 0;  
    unsigned long timeon = 0;
    unsigned long timeoff =0;
    
    void setup()
    { pinMode(anemometerPin, INPUT_PULLUP);
      Serial.begin(9600);
    }
    
    void loop()
    {
       timeon = pulseIn(anemometerPin,HIGH); // Measured Time On
       timeoff = pulseIn(anemometerPin,LOW); // Measure Time Off
       timePeriod = timeon + timeoff; // total period = on + off 
       float frequency  = 1000000.0/timePeriod; // calculate the frequency
       Serial.println(frequency);
       delay(1000);
    }
    
    


  • @AWI Thanks, I will give it a try. Today I also received some additional info. The device is a NPN model. Type 12CM, according to the supplier it is 12 pulses for 1m/s per second. But the manual says that this model is 10 pulses for 1m/s.

    So basically I could now connect the device as NPN, only I need to find out how 🙂


  • Hero Member

    @rnollen good news. Npn needs a pull-up so the sketch above should be able to do it. It uses the internal pull-up of the Arduino. I am curious to the outcome.



  • @AWI said:

    @rnollen good news. Npn needs a pull-up so the sketch above should be able to do it. It uses the internal pull-up of the Arduino. I am curious to the outcome.

    It does not work entirely correct I think. In the serial Monitor I see "Inf" as outcome of the sketch 😞 Don't see exactly where that is coming from 🙂

    Maybe something wrong with the wiring? I Attached the 12V DC to red and blue. The Yellow, connected it to the breadboard and a cable from the D7 also to this connection. I took a 4.7K resistor, connected also to this group and the other side of this resistor I connected to the 5V of the Arduino? Is that correct?

    When I remove the resistor: then this is my outcome of the sketch:
    12.82
    inf
    inf
    3.36
    1.88
    55.06
    inf
    37037.03
    inf
    333333.34
    30.95
    17.43
    inf
    142857.14
    inf
    125000.00
    500000.00
    500000.00
    90909.10
    500000.00
    39.47
    inf
    250000.00
    500000.00
    inf
    20.54
    45.67
    58823.53
    inf
    9.88
    inf
    inf
    9.17
    inf

    Then I got some numbers, but what they mean 🙂 The very high numbers are when rotating..


  • Hero Member

    @rnollen the "inf" means infinite and is caused by a 0 division. You can try to remove the line starting with 'float' and print the time values.
    I assume you changed the anemometer pin in the sketch to d7...?
    And connected the gnd of 12v and 5v together?



  • @AWI said:

    @rnollen the "inf" means infinite and is caused by a 0 division. You can try to remove the line starting with 'float' and print the time values.
    I assume you changed the anemometer pin in the sketch to d7...?

    I have did some additional testing. The DC12 is wrong I think, when I use that then the whole sketch does not give any values back. Now used the 5V of the arduino, then I got something readings using this sketch. I have added some additional serial print lines for logging. But when times are zero, then the frequency is INF and that happens when I don't rotate, so that looks OK I think
    ..
    Timeon: 0
    Timeoff: 0
    TimePeriod: 0
    Frequency: inf
    Timeon: 0
    Timeoff: 87951
    TimePeriod: 87951
    Frequency: 11.37
    Timeon: 24222
    Timeoff: 22899
    TimePeriod: 47121
    Frequency: 21.22
    Timeon: 24960
    Timeoff: 27680
    TimePeriod: 52640
    Frequency: 19.00
    Timeon: 27545
    Timeoff: 28273
    TimePeriod: 55818
    Frequency: 17.92
    Timeon: 63310
    Timeoff: 0
    TimePeriod: 63310
    Frequency: 15.80

    The serial.print lines:
    Serial.print("Timeon: ");
    Serial.println(timeon);
    Serial.print("Timeoff: ");
    Serial.println(timeoff);
    Serial.print("TimePeriod: ");
    Serial.println(timePeriod);
    Serial.print("Frequency: ");
    Serial.println(frequency);

    But any idea, because I am still lost don't know exactly what the conclusion of this is 🙂


  • Hero Member

    @rnollen this looks much better. You get frequencies in the 10 to 20 range when rotating. The inf when you're not rotating are caused by timer overflow so nothing wrong there.
    Now it is time for a more dedicated measurement. Basically replace the standard arduino routines with your own version. It is middle of the night here so I have to leave it for tomorrow...


  • Hero Member

    @rnollen time for "Take 2" I created it in Codebender to make sure it compiles. Could not test functionality yet.

    The "take 2" code implements a non-blocking measurement of the frequency of the anemometer (pulses per second). It should be safe for overflow.
    Take 3 could be to translate it to m/s windspeed according to your type of anemometer and finally:
    Take 4 MySensors' ise it!!

    https://codebender.cc/sketch:347690



  • @AWI Hmm.. I see this:
    1000.00
    1000.00
    1000.00
    1000.00
    1000.00
    1000.00
    1000.00
    1000.00
    1000.00
    500.00
    1000.00
    0.00
    inf
    1000.00
    0.00
    0.00

    Don't think that this is correct right? Am I doing something wrong, or does these numbers say anything to you 🙂


  • Hero Member

    @rnollen was a short night... 😓

    Forgot the return lastFrequencyI changed the sketch in last post. No guarantee that it works, don't have the hardware.



  • @AWI Sorry for the late reply, I got the flu 😞 But did test the sketch, but I got the same results basically.. Mostly 1000, inf and sometimes a 500? So what can be wrong here?

    Thanks for all you're efforts so far!! Really appreciate it 🙂


  • Hero Member

    @rnollen No problem, I hope you recovered well. Haven't looked at the sketch until now and discovered that I must have been suffering from something too... I added a missing line but still can't test it. Please give it a try..



  • @AWI I am still ill, while doing this 🙂 Hopefully tomorrow will be better, Hahaha.. 🙂
    But, the results looks promising and OK I guess 🙂
    8.13
    10.87
    14.08
    20.00
    27.78
    23.81
    25.64
    10.75
    0.00
    1.81
    12.66
    11.49
    10.75
    10.00
    9.35
    8.85
    8.33
    7.87

    It's 0 when I am not turning it around, so that is OK. Low number, when rotating it slowly. High number when rotating it fast 🙂


  • Hero Member

    @rnollen take care.. This is how it should be (with the anemometer) I will post the MySensors version tomorrow (need some sleep now)



  • @AWI said:
    @rnollen take care.. This is how it should be (with the anemometer) I will post the MySensors version tomorrow (need some sleep now)

    @AWI ..Awesome ☺ Thanks so far ☺


  • Hero Member

    @rnollen I made the sketch but forgot to post it... Have a look here

    https://codebender.cc/sketch:347770

    I does not compile in codebender.cc yet because of v2 MySensor but it should in the IDE.

    Have fun and let me know the results


  • Contest Winner

    @AWI Great job. I'm planning to make my own anemometer, just because it's fun to do. And was already thinking about the problems that might occur. Hardware wise it's easy. Just use a hall sensor to detect pulses and a rotating magnet.

    When the diameter of the magnet will be around 9cm, the magnet will reach the Hall sensor within 3ms or less if there's a Hurricane. That can be a problem because the sensor might think that the magnet isn't moving.

    Because of that I was thinking about counting the pulses in a interrupt handler (pin 2 or 3) . And just let the loop periodically read the values and send them to the gateway if necessary.

    Now comes my question for you. I was thinking of using some kind of decade counter IC. And let the IC handle the pulse counting. That way I only have to read and reset the counter IC. Do you happen to know a good counter IC that I can connect to the Arduino? It would make the project much easier.


  • Hero Member

    @TheoL I have to dig in my ancient history to find hardware for that purpose. An interrupt routine would be much easier and fast enough. (would be take 4 of this thread 😄)


  • Contest Winner

    @AWI I know it's ancient stuff 😉 But very reliable. Maybe something like this? THE 4017B DECADE COUNTER But I don't know I it could handle the speed?

    I'm also thinking about replacing the hall sensor with an infrared pulse sensor. It has a shorter on time than a magnet with a hall sensor. At least that's what I'm thinking 😉



  • @AWI Thanks for the sketch, but I still run in some issues. When i download the sketch, I got an error with the line "#include <MySensor.h> ". The strange thing is, everything seems to be OK, but it say it cannot be found. When I copy/paste the lines from a different sketch, it does work correct?? The strange thing is, I don't see difference. Maybe something wrong with a font or some sort?

    But, then the issues really start. All the Mysensors stuff, is not recognized (e.g.send). I was able to fix that, copying from other sketches and add gw. before everything. In the serial monitor it then looks OK. That seems for me to solve the issues on that side.

    But finally, in domoticz, it does not work then 😞 Everything is looking perfect, I see the sensors appear, but no new device is added). I saw a topic on the domoticz forum where the same thing happened 🙂 and where you also replyed in: https://www.domoticz.com/forum/viewtopic.php?f=42&t=11490&p=82522&hilit=wind#p82522

    Tried some various stuff, but no result sofar

    Any idea?


  • Hero Member

    @rnollen it seems you are running into the changes related to the new development syntax. I wrote the sketch with the development version.. There are many threads on the forum discussing that so I won't repeat it here.

    The sensor not appearing I remember from another wind sensor discussion. Domoticz builds it when a few wind types are present. You can add a wind direction dummy (presentation is already in the sketch, commented) and send a "0" degrees value.


  • Hero Member

    @TheoL speed will not be an issue with these components if we are talking milliseconds. The atmega328p also has no problems there. So no need for additional hardware. But for the diehards a shift register can act as a modulo 2^ divider.


  • Contest Winner

    @AWI It's something I have to postpone till winter time 😉 But I'll keep it in mind. I never told about the buck converter you've send to me. Works like a charm much better than the power regulators I was using. Thank you for that. When things will start to settle down, I'll do a repost on my gesture controlled lamp. I've received some cheap gesture sensors so I'll be updating that part is well. Then it I'll be a very cheap project.


  • Hero Member

    @rnollen I updated the sketch for you with a dummy value of "0 degrees" windirection to keep Domoticz happy. (MySensors 2.0)
    https://codebender.cc/sketch:347770



  • @AWI Thanks! The sketch works. But, I am not quite sure if the readings in m/s are correct. As a test, I have used a normal table fan, then I got 3.3 m/s on full speed..
    Then I used a hairdryer, that on full speed.. It spins then very very fast, but it is still only 11 m/s. This is classified as normal, somewhat powerfull wind? Looks to me it's pretty low? Or could this correct for this case? :)'

    Edit-> Maybe it is correct 🙂 Saw somewhere on internet a test with somewhat smaller hairdryer, which gave 9.5 m/s 🙂
    Unfortunately I don't have any experience with windmeters 🙂 Don't know how hard it should spin and how to test the output 🙂


  • Contest Winner

    @rnollen My theory for calculating they outcome of your sensor is the following. All you need to know is the distance it takes from the pulse going from LOW (leaving the hall sensor) to HIGH triggering the hold sensor. If that's for instance 10 cm. Than the distance traveled by one full turn is 10cm. Let's say the wind will cause your windsensor to travel exactly once every second, the speed would by 600 cm's in 60 seconds. That's 1 meter per minute. So the wind speed would be 60 meter per hour which is known is 0 Beaufort.

    If however the wind causes the sensor to turn exactly 3 times per second, that would be 30cm which is 0.3 m/s. Then the wind speed would be 1 Beaufort. Since 12 Beaufort starts at 32.6 m/s it would mean that your wind sensor would turn 3260 cm per second divided by 10 is 326 turns per second. which is roughly once every 3 millisecond.

    But I'm hoping that someone can verify this theory 😉


  • Hero Member

    @TheoL In essence you are right but you need to get some more variables in the equation. It is a rotating sensor with (probably non linear) losses. Best solution in this case is to calibrate it with a known value. @mollen bought himself a quality sensor which is supposed to be calibrated. Type 12CM, according to the supplier it is 12 pulses for 1m/s per second. But the manual says that this model is 10 pulses for 1m/s." which should make the calculation pretty easy: either divide the pulses per second by 12 (or 10). Line 68: float windSpeed = frequency / meterPerPulse ; // calculate m/s for pulses per second and the calibration value (to be adjusted) line 39: const int meterPerPulse = 10 ; // number pulses/s for each m/s

    I am still working on a whole different approach for measuring wind parameters with the help of an acceleration sensor. I looks very promising.


  • Contest Winner

    @AWI Thanx for the explanation. I just have to build the sensor with as much precision as I can. All will of course depend on things like the quality of the ball-bearrings that I use e.t.c. And of course in the quality of the electronic parts. And I have to calibrate it despite of my theory. What I didn't take into account is the minimum force that is needed for the sensor to start rotating.

    Your approach sounds very interesting. I've recently found a sensors that measures the angle movement of a magnet. My theory is, that by probing each angle movement within a couple of ms would end up in a very precise wind sensor. Problem is that I wasn't able to find a breakout board. I can only buy the sensor as an SMD IC. And soldering SMD is just not a skill I have found time to master yet.

    Also this sensor would make a perfect wind direction sensor, which is far more precise than using 8 reed relays or hall sensor that most of these wind direction sensor do. The IC cost around 7 dollar if I remember correctly.


  • Hero Member

    @TheoL I use an acceleration sensor which makes is easy to calculate angle and direction with respect to gravity. Problem is more in the mechanics to make it reliable and damped.
    I will publish in a few weeks and discuss in a separate thread


  • Contest Winner

    @AWI Looking forward to that thread. Would love to team up with you on this on. This is the sensor I was talking about. Just posting it hear so I'll remember it

    http://www.digikey.nl/en/product-highlight/a/ams/as5262-magnetic-position-sensor?WT.srch=1&mkwid=seJnJAtEb&pcrid=86172304838&pkw=_cat%3Adigikey.nl&pmt=b&pdv=c


  • Mod

    @TheoL A compass sensor will probably work just as fine, is a lot cheaper and comes as a module!
    Just use a weak magnet (no neodimium 💀 )


  • Contest Winner

    @Yveaux True. But I think it's much easier to epoxy a magnet under an rotating axis. Let's see what we can come up with saturday.??


  • Mod

    @TheoL that's exactly what I mean! The sensor won't know if it's the earth spinning around our a magnet ;all the same to it.
    Let's discuss /prototype it tomorrow!



  • Hello I bought a TX23 and wanted to integrate it into FHEM.
    Could anyone look over the scetch if it is correct?

    /**
    # Arduino-LaCrosse-TX23-Library
    
    LaCrosse TX23 is a wind speed and direction sensor. It uses 3 wires for communication and power:
    
    Pin1 - Brown(Black) - DATA
    Pin2 - Red - Vcc
    Pin3 - Green - N/C
    Pin4 - Yellow - GND
    
    DATA pin is to be connected directly to one of Arduino ports.
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <MySensors.h>
    #include <SPI.h>
    #include <LaCrosse_TX23.h>
    
    #define CHILD_ID_WIND 1
    
    //DATA wire connected to arduino port 4
    LaCrosse_TX23 anemometer = LaCrosse_TX23(4);
    
    // standard messages
    MyMessage msgWSpeed(CHILD_ID_WIND, V_WIND);
    MyMessage msgWDirection(CHILD_ID_WIND, V_DIRECTION);
    
    
    void setup(){
    }
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Wind Sensor", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_WIND, S_WIND);
    }
    
    void loop()
    {
      
      //String dirTable[]= {"N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"}; 
      String dirTable[]= {"0","22.5","45","67.5","90","112.5","135","157.5","180","202.5","225","247.5","270","292.5","315","337.5"};
      float speed;
      float a = 22.5;
      int direction;
    
      if(anemometer.read(speed, direction))
      {
        send(msgWDirection.set(direction*a ,1));
        send(msgWSpeed.set(speed, 1));
        
        Serial.println("Speed = " + String(speed,1) + " m/s");
        Serial.println("Dir = " + dirTable[direction] + " Grad");  
      }
      else
      {
        Serial.println("Read error");
      }
    
      
      //delay between succesive read requests must be at least 2sec, otherwise wind speed will read 0.
      delay(2000);
    }
    
    

    Thank you



  • Anyone got a working sketch for a pulse anenometer?
    I printed this. https://www.thingiverse.com/thing:2523343
    I used it with ESPHome as testing it and I got OK values.
    Now i would like to use it with mysensors.
    I tried @AWI s sketch but I get stange readings.
    Sometimes I get a very high value when is turns slow.


Log in to reply
 

Suggested Topics

48
Online

11.4k
Users

11.1k
Topics

112.7k
Posts