Wind speed sensor node
-
@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. -
@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. -
@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. -
@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.@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
-
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.
-
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/MapIf you receive 1v that will give you 200/31.605=~7
-
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?
-
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?
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 -
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.
-
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 -
Yesterday I found some example code on the Domoticz forum.
With some modifications I get numbers in wind :smiley:
As below my current sketch that sends values, I will modify it untill it is what I like and will post it here.
#include <SPI.h> #include <MySensor.h> #define CHILD_ID_WIND 20 #define LED_PIN 8 #define ID_WIND 170 #define WIND_SENSOR_ANALOG_PIN 1 MySensor gw; unsigned int val_wspeed; unsigned int val_wgust; unsigned int val_wdirection; unsigned int last_wspeed; unsigned int last_wgust; unsigned int last_wdirection; boolean metric = true; unsigned long currentTime; unsigned long SEND_FREQUENCY = 10000; unsigned long lastSend; MyMessage msgWSpeed(CHILD_ID_WIND, V_WIND); MyMessage msgWGust(CHILD_ID_WIND, V_GUST); MyMessage msgWDirection(CHILD_ID_WIND, V_DIRECTION); //Setup routine void setup() { // Initialize library and add callback for incoming messages gw.begin(); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Windsensor", "0.1"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_WIND, S_WIND); metric = gw.getConfig().isMetric; lastSend = 0; pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN,1); } //Main loop void loop() { gw.process(); currentTime = millis(); unsigned int val_wspeed = (analogRead(WIND_SENSOR_ANALOG_PIN))/31.605; if(last_wspeed != val_wspeed) { last_wspeed = val_wspeed; gw.send(msgWSpeed.set(val_wspeed, 1)); Serial.print("WS: "); Serial.println(val_wspeed); } unsigned int val_wgust = (analogRead(WIND_SENSOR_ANALOG_PIN))/31.605; if(last_wgust != val_wgust) { last_wgust = val_wgust; gw.send(msgWGust.set(val_wgust, 1)); Serial.print("WG: "); Serial.println(val_wgust); } unsigned int val_wdirection = (analogRead(WIND_SENSOR_ANALOG_PIN))/2.842; if(last_wdirection != val_wdirection) { last_wdirection = val_wdirection; gw.send(msgWDirection.set(val_wdirection, 1)); Serial.print("WD: "); Serial.println(val_wdirection); } }