Wind speed sensor node
-
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); } }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login