Wind speed sensor node
Hardware
21
Posts
5
Posters
11.0k
Views
4
Watching
-
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); } }