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. Announcements
  3. 💬 Rain Gauge

💬 Rain Gauge

Scheduled Pinned Locked Moved Announcements
61 Posts 17 Posters 16.8k Views 16 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.
  • I itbeyond

    @user2684 That is great news - your understanding is basically correct. When no rain the 1K is providing the pull up to 3.3/5v and charging the cap at the same time (current limit is really for when you go to ground not to hold the pin up). When the bucket tips the cap is discharged via the resistor to ground (bucket switch) and thus the pin goes low. Yes - simple and effective pull up and debounce system which works every time - in fact I use this on all interrupt triggered pins for all my projects.

    @petewill it would be good to include something like this on most of the projects, would have saved me a lot of early angst in having faulty triggered interrupts. I suspect different cloned Arduino boards have different to zero internal pull ups (3 different ones I have tried seem to have none) and to be 100% sure it is much better to document an external arrangement. It will really help the beginners to get it right first time and keep some hair regardless of the quality of the board they are using. I needed this on my irrigation controller also - same problem with a 10cm cable to a push button.

    U Offline
    U Offline
    user2684
    Contest Winner
    wrote on last edited by
    #33

    @itbeyond thanks for the explanation! Last question even if not necessarily mysensors related: how did you size the cap the resistors? Thanks!

    1 Reply Last reply
    0
    • I itbeyond

      @user2684 That is great news - your understanding is basically correct. When no rain the 1K is providing the pull up to 3.3/5v and charging the cap at the same time (current limit is really for when you go to ground not to hold the pin up). When the bucket tips the cap is discharged via the resistor to ground (bucket switch) and thus the pin goes low. Yes - simple and effective pull up and debounce system which works every time - in fact I use this on all interrupt triggered pins for all my projects.

      @petewill it would be good to include something like this on most of the projects, would have saved me a lot of early angst in having faulty triggered interrupts. I suspect different cloned Arduino boards have different to zero internal pull ups (3 different ones I have tried seem to have none) and to be 100% sure it is much better to document an external arrangement. It will really help the beginners to get it right first time and keep some hair regardless of the quality of the board they are using. I needed this on my irrigation controller also - same problem with a 10cm cable to a push button.

      petewillP Offline
      petewillP Offline
      petewill
      Admin
      wrote on last edited by petewill
      #34

      @itbeyond said in 💬 Rain Gauge:

      I needed this on my irrigation controller also - same problem with a 10cm cable to a push button.

      Interesting. I haven't experienced this behavior with any of my devices yet. I do power most of my sensors with my whole house power supply though so I guess that would explain it.

      I will update the rain gauge page and also add this info to the troubleshooting section. Thanks for your help with this!

      If anyone needs a visual of what @itbeyond described above here is the wiring diagram.

      0_1495740779599_Hardware-Debounce-False-Interrupt-Fix.jpg

      My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

      1 Reply Last reply
      1
      • EnfeetE Offline
        EnfeetE Offline
        Enfeet
        wrote on last edited by
        #35

        Hi friends,

        here is my replica of Rain Guage MySensors project
        photos:
        https://goo.gl/photos/4kA7T4d8SsDBRrrS7

        The sketch is adopted for 'Adafruit Unified Sensor by Adafruit' + 'DHT sensor library' just uncomment both DHT_ON and DHT_ADAFRUIT
        and last version of Arduino IDE 1.8.3

        ...and Yes, I'm using rfm69hw radio with encryption enabled ;-)

        #define MY_RFM69_ENABLE_ENCRYPTION
        
        /*
         Arduino Tipping Bucket Rain Gauge
        
         April 26, 2015
        
         Version 2.0
        
         Arduino Tipping Bucket Rain Gauge
        
         Utilizing a tipping bucket sensor, your Vera home automation controller and the MySensors.org
         gateway you can measure and sense local rain.  This sketch will create two devices on your
         Vera controller.  One will display your total precipitation for the last 5 days.  The other, 
         a sensor that changes state if there is recent rain (up to last 120 hours)  above a threshold.  
         Both these settings are user definable.
        
         There is a build overview video here: https://youtu.be/1eMfKQaLROo
        
         This sketch features the following:
        
         * Allows you to set the rain threshold in mm
         * Allows you to determine the tripped indicator window up to 120 hours.
         * Displays the last 5 days of rain in Variable1 through Variable5
           of the Rain Sensor device
         * Configuration changes to Sensor device updated every hour
         * Should run on any Arduino
         * Will retain Tripped/Not Tripped status and data in a power interruption, saving small amount
           of data to EEPROM (Circular Buffer to maximize life of EEPROM)
         * LED status indicator
         * Optional Temp/Humidity (DHT-22 or DHT-11) and Light LUX (BH1750) sensors. To use, uncomment
           #define DHT_ON  and/or #define LUX_ON
         * Optionally send total accumulation of each day's rainfall or send only individual days rainfall totals.
           Uncomment #define USE_DAILY to display individual daily rainfall.  If it is commented out it will display
           a cumulative total rainfall (day4 = day1+day2+day3+day4 etc)
        
         by @BulldogLowell and @PeteWill for free public use
        
         */
        
        // Enable debug prints to serial monitor
        //#define MY_DEBUG
        //#define MY_DEBUG_VERBOSE
        #define MY_NODE_ID AUTO
        // Enable and select radio type attached
        //#define MY_RADIO_NRF24
        #define MY_RADIO_RFM69
        #define MY_IS_RFM69HW
        #define MY_RFM69_FREQUENCY RF69_433MHZ
        #define MY_RFM69_NETWORKID 100
        #define MY_RFM69_TX_POWER 31
        
        #include <math.h>
        #include <TimeLib.h>
        #include <MySensors.h>
        
        #define SKETCH_NAME "Rain Gauge"
        #define SKETCH_VERSION "2.0"
        
        #define DWELL_TIME 40  // this allows for radio to come back to power after a transmission, ideally 0 
        
        //#define DEBUG_ON  // Rain gauge specific debug messages. 
        #define DHT_ON // uncomment out this line to enable DHT sensor
        
        // 20170621 by Enfeet
        #define DHT_ADAFRUIT // uncomment out this line to enable DHT with 'Adafruit Unified Sensor by Adafruit' + 'DHT sensor library'
        //#define DHTTYPE           DHT11     // DHT 11 
        #define DHTTYPE           DHT22     // DHT 22 (AM2302)
        //#define DHTTYPE           DHT21     // DHT 21 (AM2301)
        // /20170621 by Enfeet
        
        //#define LUX_ON // uncomment out this line to enable BH1750 sensor
        //#define USE_DAILY // Uncomment to display individual daily rainfall totals in the variables sent to your controller. If it's commented it will add each day to the next for a cumulative total.
        
        #define TIP_SENSOR_PIN 3
        //d=112 mm
        //11689.863832 mm2 =  116,89863832 cm2
        //42,77209787776081 mm
        //88 89 91 91 90 = 89,8
        //0,4763039852757329
        #define CALIBRATE_FACTOR 48 // amount of rain per rain bucket tip e.g. 5 is .05mm
        #define DHT_LUX_DELAY 300000  //Delay in milliseconds that the DHT and LUX sensors will wait before sending data
        
        #define CHILD_ID_RAIN_LOG 3  // Keeps track of accumulated rainfall
        #define CHILD_ID_TRIPPED_INDICATOR 4  // Indicates Tripped when rain detected
        #define EEPROM_BUFFER_LOCATION 0  // location of the EEPROM circular buffer
        #define E_BUFFER_LENGTH 240
        #define RAIN_BUCKET_SIZE 120
        
          #ifdef  DEBUG_ON
            #define M_DEBUG_PRINT(x)   Serial.print(x)
            #define M_DEBUG_PRINTLN(x) Serial.println(x)  
            #define SERIAL_START(x)  Serial.begin(x)
            #else
            #define M_DEBUG_PRINT(x)
            #define M_DEBUG_PRINTLN(x)
            #define SERIAL_START(x)
          #endif
        //
        MyMessage msgRainRate(CHILD_ID_RAIN_LOG, V_RAINRATE);
        MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN);
        //
        MyMessage msgRainVAR1(CHILD_ID_RAIN_LOG, V_VAR1);
        MyMessage msgRainVAR2(CHILD_ID_RAIN_LOG, V_VAR2);
        MyMessage msgRainVAR3(CHILD_ID_RAIN_LOG, V_VAR3);
        MyMessage msgRainVAR4(CHILD_ID_RAIN_LOG, V_VAR4);
        MyMessage msgRainVAR5(CHILD_ID_RAIN_LOG, V_VAR5);
        //
        MyMessage msgTripped(CHILD_ID_TRIPPED_INDICATOR, V_TRIPPED);
        MyMessage msgTrippedVar1(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
        MyMessage msgTrippedVar2(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
        //
        #ifdef DHT_ON
        // 20170621 by Enfeet
          #ifdef DHT_ADAFRUIT
          #include <Adafruit_Sensor.h>
          #include <DHT_U.h>
          #endif
        // /20170621 by Enfeet
          #include <DHT.h>
          #define CHILD_ID_HUM 0
          #define CHILD_ID_TEMP 1
          #define HUMIDITY_SENSOR_DIGITAL_PIN 8
          #ifndef DHT_ADAFRUIT // 20170621 by Enfeet
            DHT dht;
          #else 
            DHT_Unified dht(HUMIDITY_SENSOR_DIGITAL_PIN, DHTTYPE);
            sensors_event_t event;
          #endif // /20170621 by Enfeet  
          float lastTemp;
          float lastHum;
          bool metric = true;
          MyMessage msgHum(CHILD_ID_HUM, V_HUM);
          MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
        #endif
        //
        #ifdef LUX_ON
          //BH1750 is connected to SCL (analog input A5) and SDA (analog input A4)
          #include <BH1750.h>
          #include <Wire.h>
          #define CHILD_ID_LIGHT 2
          BH1750 lightSensor;
          MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
          unsigned int lastlux;
          uint8_t heartbeat = 10; //Used to send the light lux to gateway as soon as the device is restarted and after the DHT_LUX_DELAY has happened 10 times
        #endif
        unsigned long sensorPreviousMillis;
        int eepromIndex;
        int tipSensorPin = 3; // Pin the tipping bucket is connected to. Must be interrupt capable pin
        int ledPin = 5; // Pin the LED is connected to.  PWM capable pin required
        #ifdef DEBUG_ON
        unsigned long dataMillis;
        unsigned long serialInterval = 600000UL;
        #endif
        const unsigned long oneHour = 3600000UL;
        unsigned long lastTipTime;
        unsigned long lastRainTime; //Used for rainRate calculation
        unsigned int rainBucket [RAIN_BUCKET_SIZE] ; /* 24 hours x 5 Days = 120 hours */
        unsigned int rainRate = 0;
        uint8_t rainWindow = 72;         //default rain window in hours.  Will be overwritten with msgTrippedVar1.
        volatile int wasTippedBuffer = 0;
        int rainSensorThreshold = 50; //default rain sensor sensitivity in hundredths.  Will be overwritten with msgTrippedVar2.
        uint8_t state = 0;
        uint8_t oldState = 2; //Setting the default to something other than 1 or 0
        unsigned int lastRainRate = 0;
        int lastMeasure = 0;
        bool gotTime = false;
        uint8_t lastHour;
        uint8_t currentHour;
        //
        void presentation()  {
          // Register all sensors to gw (they will be created as child devices)
          sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
          wait(DWELL_TIME);
          present(CHILD_ID_RAIN_LOG, S_RAIN);
          wait(DWELL_TIME);
          present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION);
          wait(DWELL_TIME);
        
        #ifdef DHT_ON
          present(CHILD_ID_HUM, S_HUM);
          wait(DWELL_TIME);
          present(CHILD_ID_TEMP, S_TEMP);
          wait(DWELL_TIME);
        #endif
        
        
        #ifdef LUX_ON
          present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        #endif
        
          M_DEBUG_PRINTLN(F("Sensor Presentation Complete"));
        }
        
        void setup()
        {
          #ifndef MY_DEBUG
          SERIAL_START(115200);  //Start serial if MySensors debugging isn't enabled
          #endif
          //
          // Set up the IO
          pinMode(TIP_SENSOR_PIN, INPUT);
          attachInterrupt (digitalPinToInterrupt(TIP_SENSOR_PIN), sensorTipped, FALLING);  // depending on location of the hall effect sensor may need CHANGE
          pinMode(ledPin, OUTPUT);
          digitalWrite(ledPin, HIGH);
          //
          //Sync time with the server
          //
          unsigned long functionTimeout = millis();
          while (timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL)
          {
            requestTime();
            M_DEBUG_PRINTLN(F("Getting Time"));
            wait(1000); // call once per second
            M_DEBUG_PRINTLN(F("."));
          }
          currentHour = hour();
          lastHour = hour();
          //
          //retrieve from EEPROM stored values on a power cycle.
          //
          bool isDataOnEeprom = false;
          for (int i = 0; i < E_BUFFER_LENGTH; i++)
          {
            uint8_t locator = loadState(EEPROM_BUFFER_LOCATION + i);
            if (locator == 0xFE)  // found the EEPROM circular buffer index
            {
              eepromIndex = EEPROM_BUFFER_LOCATION + i;
              M_DEBUG_PRINT(F("EEPROM Index "));
              M_DEBUG_PRINTLN(eepromIndex);
              //Now that we have the buffer index let's populate the rainBucket[] with data from eeprom
              loadRainArray(eepromIndex);
              isDataOnEeprom = true;
              break;
            }
          }
          //
          if (!isDataOnEeprom) // Added for the first time it is run on a new Arduino
          {
            M_DEBUG_PRINTLN(F("I didn't find valid EEPROM Index, so I'm writing one to location 0"));
            eepromIndex = EEPROM_BUFFER_LOCATION;
            saveState(eepromIndex, 0xFE);
            saveState(eepromIndex + 1, 0xFE);
            //then I will clear out any bad data
            for (int i = 2; i <= E_BUFFER_LENGTH; i++)
            {
              saveState(i, 0x00);
            }
          }
          #ifdef DEBUG_ON
          dataMillis = millis();
          #endif
          lastTipTime = millis(); 
          //
          request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
          wait(DWELL_TIME);
          request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
          wait(DWELL_TIME);
          //
        #ifdef DHT_ON
        // 20170621 by Enfeet
          #ifndef DHT_ADAFRUIT
            dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
          #else
            dht.begin();
          #endif
          metric = getControllerConfig().isMetric;
          wait(DWELL_TIME);
        #endif
          //
        #ifdef LUX_ON
          lightSensor.begin();
        #endif
          //
          transmitRainData(); //Setup complete send any data loaded from eeprom to gateway
        }
        
        void loop()
        {
          if (state)
          {
            prettyFade();  // breathe if tripped
          }
          else
          {
            slowFlash();   // blink if not tripped
          }
        #ifdef DEBUG_ON  // Serial Debug Block
          if ( (millis() - dataMillis) >= serialInterval)
          {
            for (int i = 24; i <= 120; i = i + 24)
            {
              updateSerialData(i);
            }
            dataMillis = millis();
          }
        #endif
          //
          // let's constantly check to see if the rain in the past rainWindow hours is greater than rainSensorThreshold
          //
          int measure = 0; // Check to see if we need to show sensor tripped in this block
          for (int i = 0; i < rainWindow; i++)
          {
            measure += rainBucket [i];
            if (measure != lastMeasure)
            {
              //      M_DEBUG_PRINT(F("measure value (total rainBucket within rainWindow): "));
              //      M_DEBUG_PRINTLN(measure);
              lastMeasure = measure;
            }
          }
          //
          state = (measure >= (rainSensorThreshold * 100));
          if (state != oldState)
          {
            send(msgTripped.set(state));
            wait(DWELL_TIME);
            M_DEBUG_PRINT(F("New Sensor State... Sensor: "));
            M_DEBUG_PRINTLN(state ? "Tripped" : "Not Tripped");
            oldState = state;
          }
          //
          unsigned long tipDelay = millis() - lastRainTime;
          if (wasTippedBuffer) // if was tipped, then update the 24hour total and transmit to Vera
          {
            M_DEBUG_PRINTLN(F("Sensor Tipped"));
            M_DEBUG_PRINT(F("rainBucket [0] value: "));
            M_DEBUG_PRINTLN(rainBucket [0]);
            send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); //Calculate the total rain for the day
            wait(DWELL_TIME);
            wasTippedBuffer--;
            rainRate = ((oneHour) / tipDelay);
            if (rainRate != lastRainRate)
            {
              send(msgRainRate.set(rainRate, 1));
              wait(DWELL_TIME);
              M_DEBUG_PRINT(F("RainRate= "));
              M_DEBUG_PRINTLN(rainRate);
              lastRainRate = rainRate;
            }
            lastRainTime = lastTipTime;
          }
          //
          currentHour = hour();
          if (currentHour != lastHour)
          {
            M_DEBUG_PRINTLN(F("One hour elapsed."));
            send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); // send today's rainfall
            wait(DWELL_TIME);
            saveState(eepromIndex, highByte(rainBucket[0]));
            saveState(eepromIndex + 1, lowByte(rainBucket[0]));
            M_DEBUG_PRINT(F("Saving rainBucket[0] to eeprom. rainBucket[0] = "));
            M_DEBUG_PRINTLN(rainBucket[0]);
            for (int i = RAIN_BUCKET_SIZE - 1; i >= 0; i--)//cascade an hour of values back into the array
            {
              rainBucket [i + 1] = rainBucket [i];
            }
            request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
            wait(DWELL_TIME);
            request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
            wait(DWELL_TIME);
            rainBucket[0] = 0;
            eepromIndex = eepromIndex + 2;
            if (eepromIndex > EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH)
            {
              eepromIndex = EEPROM_BUFFER_LOCATION;
            }
            M_DEBUG_PRINT(F("Writing to EEPROM.  Index: "));
            M_DEBUG_PRINTLN(eepromIndex);
            saveState(eepromIndex, 0xFE);
            saveState(eepromIndex + 1, 0xFE);
            requestTime(); // sync the time every hour
            wait(DWELL_TIME);
            transmitRainData();
            rainRate = 0;
            send(msgRainRate.set(rainRate, 1));
            wait(DWELL_TIME);
            M_DEBUG_PRINTLN(F("Sending rainRate is 0 to controller"));
            lastHour = hour();
          }
          if (millis() - sensorPreviousMillis > DHT_LUX_DELAY)
          {
            #ifdef DHT_ON  //DHT Code
              doDHT();
            #endif
            #ifdef LUX_ON
              doLUX();
            #endif
            sensorPreviousMillis = millis();
          }
        }
        //
        #ifdef DHT_ON
        void doDHT(void)
        {
          // 20170621 by Enfeet
          #ifndef DHT_ADAFRUIT
            float temperature = dht.getTemperature();
            if (isnan(temperature))
          #else
            dht.temperature().getEvent(&event);
            float temperature = event.temperature;
            if (isnan(event.temperature))
          #endif
          // /20170621 by Enfeet   
            {
              M_DEBUG_PRINTLN(F("Failed reading temperature from DHT"));
            } else if (temperature != lastTemp) 
            {
              lastTemp = temperature;
              #ifndef DHT_ADAFRUIT
                if (!metric) 
                {
                  temperature = dht.toFahrenheit(temperature);
                }
              #endif
              send(msgTemp.set(temperature, 1));
              wait(DWELL_TIME);
              M_DEBUG_PRINT(F("Temperature is: "));
              M_DEBUG_PRINTLN(temperature);
            }
          // 20170621 by Enfeet
          #ifndef DHT_ADAFRUIT
            float humidity = dht.getHumidity();;
            if (isnan(humidity)) 
          #else
            dht.humidity().getEvent(&event);
            float humidity = event.relative_humidity;
            if (isnan(event.relative_humidity))
          #endif
          // /20170621 by Enfeet     
            {
              M_DEBUG_PRINTLN(F("Failed reading humidity from DHT"));
            } else if (humidity != lastHum) 
            {
              lastHum = humidity;
              send(msgHum.set(humidity, 1));
              wait(DWELL_TIME);
              M_DEBUG_PRINT(F("Humidity is: "));
              M_DEBUG_PRINTLN(humidity);
            }
        }
        #endif
        //
        #ifdef LUX_ON
        void doLUX(void)
        {
          unsigned int lux = lightSensor.readLightLevel();// Get Lux value
          M_DEBUG_PRINT(F("Current LUX Level: "));
          M_DEBUG_PRINTLN(lux);
          heartbeat++;
          if (lux != lastlux || heartbeat > 10) 
          {
            send(msg.set(lux));
            lastlux = lux;
          }
          if (heartbeat > 10) 
          {
            heartbeat = 0;
          }
        }
        #endif
        //
        void sensorTipped()
        {
          unsigned long thisTipTime = millis();
          if (thisTipTime - lastTipTime > 100UL)
          {
            rainBucket[0] += CALIBRATE_FACTOR; // adds CALIBRATE_FACTOR hundredths of unit each tip
            wasTippedBuffer++;
          }
          lastTipTime = thisTipTime;
        }
        //
        int rainTotal(int hours)
        {
          int total = 0;
          for ( int i = 0; i <= hours; i++)
          {
            total += rainBucket [i];
          }
          return total;
        }
        
        #ifdef DEBUG_ON
        void updateSerialData(int x)
        {
          M_DEBUG_PRINT(F("Rain last "));
          M_DEBUG_PRINT(x);
          M_DEBUG_PRINTLN(F(" hours: "));
          float tipCount = 0;
          for (int i = 0; i < x; i++)
          {
            tipCount = tipCount + rainBucket [i];
          }
          tipCount = tipCount / 100;
          M_DEBUG_PRINTLN(tipCount);
        }
        #endif
        
        void loadRainArray(int eValue) // retrieve stored rain array from EEPROM on powerup
        {
          for (int i = 1; i < RAIN_BUCKET_SIZE; i++)
          {
            eValue = eValue - 2;
            if (eValue < EEPROM_BUFFER_LOCATION)
            {
              eValue = EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH;
            }
            M_DEBUG_PRINT(F("EEPROM location: "));
            M_DEBUG_PRINTLN(eValue);
            uint8_t rainValueHigh = loadState(eValue);
            uint8_t rainValueLow = loadState(eValue + 1);
            unsigned int rainValue = rainValueHigh << 8;
            rainValue |= rainValueLow;
            rainBucket[i] = rainValue;
            //
            M_DEBUG_PRINT(F("rainBucket[ value: "));
            M_DEBUG_PRINT(i);
            M_DEBUG_PRINT(F("] value: "));
            M_DEBUG_PRINTLN(rainBucket[i]);
          }
        }
        
        void transmitRainData(void)
        {
          M_DEBUG_PRINT(F("In transmitRainData. currentHour = "));
          M_DEBUG_PRINTLN(currentHour);
          int rainUpdateTotal = 0;
          for (int i = currentHour; i >= 0; i--)
          {
            rainUpdateTotal += rainBucket[i];
            M_DEBUG_PRINT(F("Adding rainBucket["));
            M_DEBUG_PRINT(i);
            M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
          }
          M_DEBUG_PRINT(F("TX Day 1: rainUpdateTotal = "));
          M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
          send(msgRainVAR1.set((float)rainUpdateTotal / 100.0, 1)); //Send current day rain totals (resets at midnight)
          wait(DWELL_TIME);
        #ifdef USE_DAILY
          rainUpdateTotal = 0;
        #endif
          for (int i = currentHour + 24; i > currentHour; i--)
          {
            rainUpdateTotal += rainBucket[i];
            M_DEBUG_PRINT(F("Adding rainBucket["));
            M_DEBUG_PRINT(i);
            M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
          }
          M_DEBUG_PRINT(F("TX Day 2: rainUpdateTotal = "));
          M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
          send(msgRainVAR2.set((float)rainUpdateTotal / 100.0, 1));
          wait(DWELL_TIME);
        #ifdef USE_DAILY
          rainUpdateTotal = 0;
        #endif
          for (int i = currentHour + 48; i > currentHour + 24; i--)
          {
            rainUpdateTotal += rainBucket[i];
            M_DEBUG_PRINT(F("Adding rainBucket["));
            M_DEBUG_PRINT(i);
            M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
          }
          M_DEBUG_PRINT(F("TX Day 3: rainUpdateTotal = "));
          M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
          send(msgRainVAR3.set((float)rainUpdateTotal / 100.0, 1));
          wait(DWELL_TIME);
        #ifdef USE_DAILY
          rainUpdateTotal = 0;
        #endif
          for (int i = currentHour + 72; i > currentHour + 48; i--)
          {
            rainUpdateTotal += rainBucket[i];
            M_DEBUG_PRINT(F("Adding rainBucket["));
            M_DEBUG_PRINT(i);
            M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
          }
          M_DEBUG_PRINT(F("TX Day 4: rainUpdateTotal = "));
          M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
          send(msgRainVAR4.set((float)rainUpdateTotal / 100.0, 1));
          wait(DWELL_TIME);
        #ifdef USE_DAILY
          rainUpdateTotal = 0;
        #endif
          for (int i = currentHour + 96; i > currentHour + 72; i--)
          {
            rainUpdateTotal += rainBucket[i];
            M_DEBUG_PRINT(F("Adding rainBucket["));
            M_DEBUG_PRINT(i);
            M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
          }
          M_DEBUG_PRINT(F("TX Day 5: rainUpdateTotal = "));
          M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
          send(msgRainVAR5.set((float)rainUpdateTotal / 100.0, 1));
          wait(DWELL_TIME);
        }
        
        void receive(const MyMessage &message)
        {
          if (message.sensor == CHILD_ID_RAIN_LOG)
          {
            // nothing to do here
          }
          else if (message.sensor == CHILD_ID_TRIPPED_INDICATOR)
          {
            if (message.type == V_VAR1)
            {
              rainWindow = atoi(message.data);
              if (rainWindow > 120)
              {
                rainWindow = 120;
              }
              else if (rainWindow < 1)
              {
                rainWindow = 1;
              }
              if (rainWindow != atoi(message.data))   // if I changed the value back inside the boundries, push that number back to Vera
              {
                send(msgTrippedVar1.set(rainWindow));
              }
            }
            else if (message.type == V_VAR2)
            {
              rainSensorThreshold = atoi(message.data);
              if (rainSensorThreshold > 10000)
              {
                rainSensorThreshold = 10000;
              }
              else if (rainSensorThreshold < 1)
              {
                rainSensorThreshold = 1;
              }
              if (rainSensorThreshold != atoi(message.data))  // if I changed the value back inside the boundries, push that number back to Vera
              {
                send(msgTrippedVar2.set(rainSensorThreshold));
              }
            }
          }
        }
        
        void prettyFade(void)
        {
          float val = (exp(sin(millis() / 2000.0 * PI)) - 0.36787944) * 108.0;
          analogWrite(ledPin, val);
        }
        
        void slowFlash(void)
        {
          static bool ledState = true;
          static unsigned long pulseStart = millis();
          if (millis() - pulseStart < 100UL)
          {
            digitalWrite(ledPin, !ledState);
            pulseStart = millis();
          }
        }
        
        void receiveTime(unsigned long newTime)
        {
          M_DEBUG_PRINTLN(F("Time received..."));
          setTime(newTime);
          char theTime[6];
          sprintf(theTime, "%d:%2d", hour(), minute());
          M_DEBUG_PRINTLN(theTime);
        }
        

        i take an original .stl files from the link provided: https://drive.google.com/drive/folders/0B3KGTJHUgpw1fkwtM3RreEF2QWg4eUdsUHdSQjl6UWx2Q3dPS19WSGdqd0pZQ3hhQk1TMkE

        but in order to save a support material recreate and split it a little ;-)

        The result are visible on photos

        here is an .scad code of my modifications on top of original files, also i print them up side down ;-)

        $fn=300;
        difference(){
        translate([35,0,0])
        import("Can.stl");
        cube([210,150,150],center=true);
        }
        
        
        
        
        translate([62,0,0])
        rotate([0,90,0])
        difference(){
        cylinder(d=10,h=3,center=true);
        cylinder(d=4,h=6,center=true);
        }
        
        
        difference(){
        translate([-88,0,0])
        sphere(d=300);
        translate([-90,0,0])
        sphere(d=300);
        translate([61,0,0])
        rotate([0,90,0])    
        cylinder(d=4,h=4,center=true);
        rotate([0,90,0])
        difference(){
        cylinder(d=310,h=208,center=true);
        cylinder(d=122.5+4,h=310,center=true);
        }    
        }
        
        
        translate([54,0,0])
        rotate([0,90,0])
        difference(){
        cylinder(d=122.5+4,h=108,center=true);
        cylinder(d=122.5,h=310,center=true);
        } 
        
        $fn=300;
        
        /*
        difference(){
        translate([35,0,0])
        import("Can.stl");
        cube([210,150,150],center=true);
        }
        
        
        
        
        translate([62,0,0])
        rotate([0,90,0])
        difference(){
        cylinder(d=10,h=3,center=true);
        cylinder(d=4,h=6,center=true);
        }
        
        
        difference(){
        translate([-88,0,0])
        sphere(d=300);
        translate([-90,0,0])
        sphere(d=300);
        translate([61,0,0])
        rotate([0,90,0])    
        cylinder(d=4,h=4,center=true);
        rotate([0,90,0])
        difference(){
        cylinder(d=310,h=208,center=true);
        cylinder(d=122.5+4,h=310,center=true);
        }    
        }
        */
        
        translate([54,0,0])
        rotate([0,90,0])
        difference(){
        cylinder(d=122.5+4,h=40
           ,center=true);
        cylinder(d=122.5,h=310,center=true);
        } 
        
        
        translate([32,0,0])
        rotate([0,90,0])
        difference(){
        cylinder(d=122.5+4+4,h=8
           ,center=true);
        cylinder(d=122.5+4,h=9,center=true);
        } 
        

        --
        SY
        Enfeet

        dbemowskD 2 Replies Last reply
        0
        • EnfeetE Enfeet

          Hi friends,

          here is my replica of Rain Guage MySensors project
          photos:
          https://goo.gl/photos/4kA7T4d8SsDBRrrS7

          The sketch is adopted for 'Adafruit Unified Sensor by Adafruit' + 'DHT sensor library' just uncomment both DHT_ON and DHT_ADAFRUIT
          and last version of Arduino IDE 1.8.3

          ...and Yes, I'm using rfm69hw radio with encryption enabled ;-)

          #define MY_RFM69_ENABLE_ENCRYPTION
          
          /*
           Arduino Tipping Bucket Rain Gauge
          
           April 26, 2015
          
           Version 2.0
          
           Arduino Tipping Bucket Rain Gauge
          
           Utilizing a tipping bucket sensor, your Vera home automation controller and the MySensors.org
           gateway you can measure and sense local rain.  This sketch will create two devices on your
           Vera controller.  One will display your total precipitation for the last 5 days.  The other, 
           a sensor that changes state if there is recent rain (up to last 120 hours)  above a threshold.  
           Both these settings are user definable.
          
           There is a build overview video here: https://youtu.be/1eMfKQaLROo
          
           This sketch features the following:
          
           * Allows you to set the rain threshold in mm
           * Allows you to determine the tripped indicator window up to 120 hours.
           * Displays the last 5 days of rain in Variable1 through Variable5
             of the Rain Sensor device
           * Configuration changes to Sensor device updated every hour
           * Should run on any Arduino
           * Will retain Tripped/Not Tripped status and data in a power interruption, saving small amount
             of data to EEPROM (Circular Buffer to maximize life of EEPROM)
           * LED status indicator
           * Optional Temp/Humidity (DHT-22 or DHT-11) and Light LUX (BH1750) sensors. To use, uncomment
             #define DHT_ON  and/or #define LUX_ON
           * Optionally send total accumulation of each day's rainfall or send only individual days rainfall totals.
             Uncomment #define USE_DAILY to display individual daily rainfall.  If it is commented out it will display
             a cumulative total rainfall (day4 = day1+day2+day3+day4 etc)
          
           by @BulldogLowell and @PeteWill for free public use
          
           */
          
          // Enable debug prints to serial monitor
          //#define MY_DEBUG
          //#define MY_DEBUG_VERBOSE
          #define MY_NODE_ID AUTO
          // Enable and select radio type attached
          //#define MY_RADIO_NRF24
          #define MY_RADIO_RFM69
          #define MY_IS_RFM69HW
          #define MY_RFM69_FREQUENCY RF69_433MHZ
          #define MY_RFM69_NETWORKID 100
          #define MY_RFM69_TX_POWER 31
          
          #include <math.h>
          #include <TimeLib.h>
          #include <MySensors.h>
          
          #define SKETCH_NAME "Rain Gauge"
          #define SKETCH_VERSION "2.0"
          
          #define DWELL_TIME 40  // this allows for radio to come back to power after a transmission, ideally 0 
          
          //#define DEBUG_ON  // Rain gauge specific debug messages. 
          #define DHT_ON // uncomment out this line to enable DHT sensor
          
          // 20170621 by Enfeet
          #define DHT_ADAFRUIT // uncomment out this line to enable DHT with 'Adafruit Unified Sensor by Adafruit' + 'DHT sensor library'
          //#define DHTTYPE           DHT11     // DHT 11 
          #define DHTTYPE           DHT22     // DHT 22 (AM2302)
          //#define DHTTYPE           DHT21     // DHT 21 (AM2301)
          // /20170621 by Enfeet
          
          //#define LUX_ON // uncomment out this line to enable BH1750 sensor
          //#define USE_DAILY // Uncomment to display individual daily rainfall totals in the variables sent to your controller. If it's commented it will add each day to the next for a cumulative total.
          
          #define TIP_SENSOR_PIN 3
          //d=112 mm
          //11689.863832 mm2 =  116,89863832 cm2
          //42,77209787776081 mm
          //88 89 91 91 90 = 89,8
          //0,4763039852757329
          #define CALIBRATE_FACTOR 48 // amount of rain per rain bucket tip e.g. 5 is .05mm
          #define DHT_LUX_DELAY 300000  //Delay in milliseconds that the DHT and LUX sensors will wait before sending data
          
          #define CHILD_ID_RAIN_LOG 3  // Keeps track of accumulated rainfall
          #define CHILD_ID_TRIPPED_INDICATOR 4  // Indicates Tripped when rain detected
          #define EEPROM_BUFFER_LOCATION 0  // location of the EEPROM circular buffer
          #define E_BUFFER_LENGTH 240
          #define RAIN_BUCKET_SIZE 120
          
            #ifdef  DEBUG_ON
              #define M_DEBUG_PRINT(x)   Serial.print(x)
              #define M_DEBUG_PRINTLN(x) Serial.println(x)  
              #define SERIAL_START(x)  Serial.begin(x)
              #else
              #define M_DEBUG_PRINT(x)
              #define M_DEBUG_PRINTLN(x)
              #define SERIAL_START(x)
            #endif
          //
          MyMessage msgRainRate(CHILD_ID_RAIN_LOG, V_RAINRATE);
          MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN);
          //
          MyMessage msgRainVAR1(CHILD_ID_RAIN_LOG, V_VAR1);
          MyMessage msgRainVAR2(CHILD_ID_RAIN_LOG, V_VAR2);
          MyMessage msgRainVAR3(CHILD_ID_RAIN_LOG, V_VAR3);
          MyMessage msgRainVAR4(CHILD_ID_RAIN_LOG, V_VAR4);
          MyMessage msgRainVAR5(CHILD_ID_RAIN_LOG, V_VAR5);
          //
          MyMessage msgTripped(CHILD_ID_TRIPPED_INDICATOR, V_TRIPPED);
          MyMessage msgTrippedVar1(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
          MyMessage msgTrippedVar2(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
          //
          #ifdef DHT_ON
          // 20170621 by Enfeet
            #ifdef DHT_ADAFRUIT
            #include <Adafruit_Sensor.h>
            #include <DHT_U.h>
            #endif
          // /20170621 by Enfeet
            #include <DHT.h>
            #define CHILD_ID_HUM 0
            #define CHILD_ID_TEMP 1
            #define HUMIDITY_SENSOR_DIGITAL_PIN 8
            #ifndef DHT_ADAFRUIT // 20170621 by Enfeet
              DHT dht;
            #else 
              DHT_Unified dht(HUMIDITY_SENSOR_DIGITAL_PIN, DHTTYPE);
              sensors_event_t event;
            #endif // /20170621 by Enfeet  
            float lastTemp;
            float lastHum;
            bool metric = true;
            MyMessage msgHum(CHILD_ID_HUM, V_HUM);
            MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
          #endif
          //
          #ifdef LUX_ON
            //BH1750 is connected to SCL (analog input A5) and SDA (analog input A4)
            #include <BH1750.h>
            #include <Wire.h>
            #define CHILD_ID_LIGHT 2
            BH1750 lightSensor;
            MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
            unsigned int lastlux;
            uint8_t heartbeat = 10; //Used to send the light lux to gateway as soon as the device is restarted and after the DHT_LUX_DELAY has happened 10 times
          #endif
          unsigned long sensorPreviousMillis;
          int eepromIndex;
          int tipSensorPin = 3; // Pin the tipping bucket is connected to. Must be interrupt capable pin
          int ledPin = 5; // Pin the LED is connected to.  PWM capable pin required
          #ifdef DEBUG_ON
          unsigned long dataMillis;
          unsigned long serialInterval = 600000UL;
          #endif
          const unsigned long oneHour = 3600000UL;
          unsigned long lastTipTime;
          unsigned long lastRainTime; //Used for rainRate calculation
          unsigned int rainBucket [RAIN_BUCKET_SIZE] ; /* 24 hours x 5 Days = 120 hours */
          unsigned int rainRate = 0;
          uint8_t rainWindow = 72;         //default rain window in hours.  Will be overwritten with msgTrippedVar1.
          volatile int wasTippedBuffer = 0;
          int rainSensorThreshold = 50; //default rain sensor sensitivity in hundredths.  Will be overwritten with msgTrippedVar2.
          uint8_t state = 0;
          uint8_t oldState = 2; //Setting the default to something other than 1 or 0
          unsigned int lastRainRate = 0;
          int lastMeasure = 0;
          bool gotTime = false;
          uint8_t lastHour;
          uint8_t currentHour;
          //
          void presentation()  {
            // Register all sensors to gw (they will be created as child devices)
            sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
            wait(DWELL_TIME);
            present(CHILD_ID_RAIN_LOG, S_RAIN);
            wait(DWELL_TIME);
            present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION);
            wait(DWELL_TIME);
          
          #ifdef DHT_ON
            present(CHILD_ID_HUM, S_HUM);
            wait(DWELL_TIME);
            present(CHILD_ID_TEMP, S_TEMP);
            wait(DWELL_TIME);
          #endif
          
          
          #ifdef LUX_ON
            present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
          #endif
          
            M_DEBUG_PRINTLN(F("Sensor Presentation Complete"));
          }
          
          void setup()
          {
            #ifndef MY_DEBUG
            SERIAL_START(115200);  //Start serial if MySensors debugging isn't enabled
            #endif
            //
            // Set up the IO
            pinMode(TIP_SENSOR_PIN, INPUT);
            attachInterrupt (digitalPinToInterrupt(TIP_SENSOR_PIN), sensorTipped, FALLING);  // depending on location of the hall effect sensor may need CHANGE
            pinMode(ledPin, OUTPUT);
            digitalWrite(ledPin, HIGH);
            //
            //Sync time with the server
            //
            unsigned long functionTimeout = millis();
            while (timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL)
            {
              requestTime();
              M_DEBUG_PRINTLN(F("Getting Time"));
              wait(1000); // call once per second
              M_DEBUG_PRINTLN(F("."));
            }
            currentHour = hour();
            lastHour = hour();
            //
            //retrieve from EEPROM stored values on a power cycle.
            //
            bool isDataOnEeprom = false;
            for (int i = 0; i < E_BUFFER_LENGTH; i++)
            {
              uint8_t locator = loadState(EEPROM_BUFFER_LOCATION + i);
              if (locator == 0xFE)  // found the EEPROM circular buffer index
              {
                eepromIndex = EEPROM_BUFFER_LOCATION + i;
                M_DEBUG_PRINT(F("EEPROM Index "));
                M_DEBUG_PRINTLN(eepromIndex);
                //Now that we have the buffer index let's populate the rainBucket[] with data from eeprom
                loadRainArray(eepromIndex);
                isDataOnEeprom = true;
                break;
              }
            }
            //
            if (!isDataOnEeprom) // Added for the first time it is run on a new Arduino
            {
              M_DEBUG_PRINTLN(F("I didn't find valid EEPROM Index, so I'm writing one to location 0"));
              eepromIndex = EEPROM_BUFFER_LOCATION;
              saveState(eepromIndex, 0xFE);
              saveState(eepromIndex + 1, 0xFE);
              //then I will clear out any bad data
              for (int i = 2; i <= E_BUFFER_LENGTH; i++)
              {
                saveState(i, 0x00);
              }
            }
            #ifdef DEBUG_ON
            dataMillis = millis();
            #endif
            lastTipTime = millis(); 
            //
            request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
            wait(DWELL_TIME);
            request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
            wait(DWELL_TIME);
            //
          #ifdef DHT_ON
          // 20170621 by Enfeet
            #ifndef DHT_ADAFRUIT
              dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
            #else
              dht.begin();
            #endif
            metric = getControllerConfig().isMetric;
            wait(DWELL_TIME);
          #endif
            //
          #ifdef LUX_ON
            lightSensor.begin();
          #endif
            //
            transmitRainData(); //Setup complete send any data loaded from eeprom to gateway
          }
          
          void loop()
          {
            if (state)
            {
              prettyFade();  // breathe if tripped
            }
            else
            {
              slowFlash();   // blink if not tripped
            }
          #ifdef DEBUG_ON  // Serial Debug Block
            if ( (millis() - dataMillis) >= serialInterval)
            {
              for (int i = 24; i <= 120; i = i + 24)
              {
                updateSerialData(i);
              }
              dataMillis = millis();
            }
          #endif
            //
            // let's constantly check to see if the rain in the past rainWindow hours is greater than rainSensorThreshold
            //
            int measure = 0; // Check to see if we need to show sensor tripped in this block
            for (int i = 0; i < rainWindow; i++)
            {
              measure += rainBucket [i];
              if (measure != lastMeasure)
              {
                //      M_DEBUG_PRINT(F("measure value (total rainBucket within rainWindow): "));
                //      M_DEBUG_PRINTLN(measure);
                lastMeasure = measure;
              }
            }
            //
            state = (measure >= (rainSensorThreshold * 100));
            if (state != oldState)
            {
              send(msgTripped.set(state));
              wait(DWELL_TIME);
              M_DEBUG_PRINT(F("New Sensor State... Sensor: "));
              M_DEBUG_PRINTLN(state ? "Tripped" : "Not Tripped");
              oldState = state;
            }
            //
            unsigned long tipDelay = millis() - lastRainTime;
            if (wasTippedBuffer) // if was tipped, then update the 24hour total and transmit to Vera
            {
              M_DEBUG_PRINTLN(F("Sensor Tipped"));
              M_DEBUG_PRINT(F("rainBucket [0] value: "));
              M_DEBUG_PRINTLN(rainBucket [0]);
              send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); //Calculate the total rain for the day
              wait(DWELL_TIME);
              wasTippedBuffer--;
              rainRate = ((oneHour) / tipDelay);
              if (rainRate != lastRainRate)
              {
                send(msgRainRate.set(rainRate, 1));
                wait(DWELL_TIME);
                M_DEBUG_PRINT(F("RainRate= "));
                M_DEBUG_PRINTLN(rainRate);
                lastRainRate = rainRate;
              }
              lastRainTime = lastTipTime;
            }
            //
            currentHour = hour();
            if (currentHour != lastHour)
            {
              M_DEBUG_PRINTLN(F("One hour elapsed."));
              send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); // send today's rainfall
              wait(DWELL_TIME);
              saveState(eepromIndex, highByte(rainBucket[0]));
              saveState(eepromIndex + 1, lowByte(rainBucket[0]));
              M_DEBUG_PRINT(F("Saving rainBucket[0] to eeprom. rainBucket[0] = "));
              M_DEBUG_PRINTLN(rainBucket[0]);
              for (int i = RAIN_BUCKET_SIZE - 1; i >= 0; i--)//cascade an hour of values back into the array
              {
                rainBucket [i + 1] = rainBucket [i];
              }
              request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
              wait(DWELL_TIME);
              request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
              wait(DWELL_TIME);
              rainBucket[0] = 0;
              eepromIndex = eepromIndex + 2;
              if (eepromIndex > EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH)
              {
                eepromIndex = EEPROM_BUFFER_LOCATION;
              }
              M_DEBUG_PRINT(F("Writing to EEPROM.  Index: "));
              M_DEBUG_PRINTLN(eepromIndex);
              saveState(eepromIndex, 0xFE);
              saveState(eepromIndex + 1, 0xFE);
              requestTime(); // sync the time every hour
              wait(DWELL_TIME);
              transmitRainData();
              rainRate = 0;
              send(msgRainRate.set(rainRate, 1));
              wait(DWELL_TIME);
              M_DEBUG_PRINTLN(F("Sending rainRate is 0 to controller"));
              lastHour = hour();
            }
            if (millis() - sensorPreviousMillis > DHT_LUX_DELAY)
            {
              #ifdef DHT_ON  //DHT Code
                doDHT();
              #endif
              #ifdef LUX_ON
                doLUX();
              #endif
              sensorPreviousMillis = millis();
            }
          }
          //
          #ifdef DHT_ON
          void doDHT(void)
          {
            // 20170621 by Enfeet
            #ifndef DHT_ADAFRUIT
              float temperature = dht.getTemperature();
              if (isnan(temperature))
            #else
              dht.temperature().getEvent(&event);
              float temperature = event.temperature;
              if (isnan(event.temperature))
            #endif
            // /20170621 by Enfeet   
              {
                M_DEBUG_PRINTLN(F("Failed reading temperature from DHT"));
              } else if (temperature != lastTemp) 
              {
                lastTemp = temperature;
                #ifndef DHT_ADAFRUIT
                  if (!metric) 
                  {
                    temperature = dht.toFahrenheit(temperature);
                  }
                #endif
                send(msgTemp.set(temperature, 1));
                wait(DWELL_TIME);
                M_DEBUG_PRINT(F("Temperature is: "));
                M_DEBUG_PRINTLN(temperature);
              }
            // 20170621 by Enfeet
            #ifndef DHT_ADAFRUIT
              float humidity = dht.getHumidity();;
              if (isnan(humidity)) 
            #else
              dht.humidity().getEvent(&event);
              float humidity = event.relative_humidity;
              if (isnan(event.relative_humidity))
            #endif
            // /20170621 by Enfeet     
              {
                M_DEBUG_PRINTLN(F("Failed reading humidity from DHT"));
              } else if (humidity != lastHum) 
              {
                lastHum = humidity;
                send(msgHum.set(humidity, 1));
                wait(DWELL_TIME);
                M_DEBUG_PRINT(F("Humidity is: "));
                M_DEBUG_PRINTLN(humidity);
              }
          }
          #endif
          //
          #ifdef LUX_ON
          void doLUX(void)
          {
            unsigned int lux = lightSensor.readLightLevel();// Get Lux value
            M_DEBUG_PRINT(F("Current LUX Level: "));
            M_DEBUG_PRINTLN(lux);
            heartbeat++;
            if (lux != lastlux || heartbeat > 10) 
            {
              send(msg.set(lux));
              lastlux = lux;
            }
            if (heartbeat > 10) 
            {
              heartbeat = 0;
            }
          }
          #endif
          //
          void sensorTipped()
          {
            unsigned long thisTipTime = millis();
            if (thisTipTime - lastTipTime > 100UL)
            {
              rainBucket[0] += CALIBRATE_FACTOR; // adds CALIBRATE_FACTOR hundredths of unit each tip
              wasTippedBuffer++;
            }
            lastTipTime = thisTipTime;
          }
          //
          int rainTotal(int hours)
          {
            int total = 0;
            for ( int i = 0; i <= hours; i++)
            {
              total += rainBucket [i];
            }
            return total;
          }
          
          #ifdef DEBUG_ON
          void updateSerialData(int x)
          {
            M_DEBUG_PRINT(F("Rain last "));
            M_DEBUG_PRINT(x);
            M_DEBUG_PRINTLN(F(" hours: "));
            float tipCount = 0;
            for (int i = 0; i < x; i++)
            {
              tipCount = tipCount + rainBucket [i];
            }
            tipCount = tipCount / 100;
            M_DEBUG_PRINTLN(tipCount);
          }
          #endif
          
          void loadRainArray(int eValue) // retrieve stored rain array from EEPROM on powerup
          {
            for (int i = 1; i < RAIN_BUCKET_SIZE; i++)
            {
              eValue = eValue - 2;
              if (eValue < EEPROM_BUFFER_LOCATION)
              {
                eValue = EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH;
              }
              M_DEBUG_PRINT(F("EEPROM location: "));
              M_DEBUG_PRINTLN(eValue);
              uint8_t rainValueHigh = loadState(eValue);
              uint8_t rainValueLow = loadState(eValue + 1);
              unsigned int rainValue = rainValueHigh << 8;
              rainValue |= rainValueLow;
              rainBucket[i] = rainValue;
              //
              M_DEBUG_PRINT(F("rainBucket[ value: "));
              M_DEBUG_PRINT(i);
              M_DEBUG_PRINT(F("] value: "));
              M_DEBUG_PRINTLN(rainBucket[i]);
            }
          }
          
          void transmitRainData(void)
          {
            M_DEBUG_PRINT(F("In transmitRainData. currentHour = "));
            M_DEBUG_PRINTLN(currentHour);
            int rainUpdateTotal = 0;
            for (int i = currentHour; i >= 0; i--)
            {
              rainUpdateTotal += rainBucket[i];
              M_DEBUG_PRINT(F("Adding rainBucket["));
              M_DEBUG_PRINT(i);
              M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
            }
            M_DEBUG_PRINT(F("TX Day 1: rainUpdateTotal = "));
            M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
            send(msgRainVAR1.set((float)rainUpdateTotal / 100.0, 1)); //Send current day rain totals (resets at midnight)
            wait(DWELL_TIME);
          #ifdef USE_DAILY
            rainUpdateTotal = 0;
          #endif
            for (int i = currentHour + 24; i > currentHour; i--)
            {
              rainUpdateTotal += rainBucket[i];
              M_DEBUG_PRINT(F("Adding rainBucket["));
              M_DEBUG_PRINT(i);
              M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
            }
            M_DEBUG_PRINT(F("TX Day 2: rainUpdateTotal = "));
            M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
            send(msgRainVAR2.set((float)rainUpdateTotal / 100.0, 1));
            wait(DWELL_TIME);
          #ifdef USE_DAILY
            rainUpdateTotal = 0;
          #endif
            for (int i = currentHour + 48; i > currentHour + 24; i--)
            {
              rainUpdateTotal += rainBucket[i];
              M_DEBUG_PRINT(F("Adding rainBucket["));
              M_DEBUG_PRINT(i);
              M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
            }
            M_DEBUG_PRINT(F("TX Day 3: rainUpdateTotal = "));
            M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
            send(msgRainVAR3.set((float)rainUpdateTotal / 100.0, 1));
            wait(DWELL_TIME);
          #ifdef USE_DAILY
            rainUpdateTotal = 0;
          #endif
            for (int i = currentHour + 72; i > currentHour + 48; i--)
            {
              rainUpdateTotal += rainBucket[i];
              M_DEBUG_PRINT(F("Adding rainBucket["));
              M_DEBUG_PRINT(i);
              M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
            }
            M_DEBUG_PRINT(F("TX Day 4: rainUpdateTotal = "));
            M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
            send(msgRainVAR4.set((float)rainUpdateTotal / 100.0, 1));
            wait(DWELL_TIME);
          #ifdef USE_DAILY
            rainUpdateTotal = 0;
          #endif
            for (int i = currentHour + 96; i > currentHour + 72; i--)
            {
              rainUpdateTotal += rainBucket[i];
              M_DEBUG_PRINT(F("Adding rainBucket["));
              M_DEBUG_PRINT(i);
              M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
            }
            M_DEBUG_PRINT(F("TX Day 5: rainUpdateTotal = "));
            M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
            send(msgRainVAR5.set((float)rainUpdateTotal / 100.0, 1));
            wait(DWELL_TIME);
          }
          
          void receive(const MyMessage &message)
          {
            if (message.sensor == CHILD_ID_RAIN_LOG)
            {
              // nothing to do here
            }
            else if (message.sensor == CHILD_ID_TRIPPED_INDICATOR)
            {
              if (message.type == V_VAR1)
              {
                rainWindow = atoi(message.data);
                if (rainWindow > 120)
                {
                  rainWindow = 120;
                }
                else if (rainWindow < 1)
                {
                  rainWindow = 1;
                }
                if (rainWindow != atoi(message.data))   // if I changed the value back inside the boundries, push that number back to Vera
                {
                  send(msgTrippedVar1.set(rainWindow));
                }
              }
              else if (message.type == V_VAR2)
              {
                rainSensorThreshold = atoi(message.data);
                if (rainSensorThreshold > 10000)
                {
                  rainSensorThreshold = 10000;
                }
                else if (rainSensorThreshold < 1)
                {
                  rainSensorThreshold = 1;
                }
                if (rainSensorThreshold != atoi(message.data))  // if I changed the value back inside the boundries, push that number back to Vera
                {
                  send(msgTrippedVar2.set(rainSensorThreshold));
                }
              }
            }
          }
          
          void prettyFade(void)
          {
            float val = (exp(sin(millis() / 2000.0 * PI)) - 0.36787944) * 108.0;
            analogWrite(ledPin, val);
          }
          
          void slowFlash(void)
          {
            static bool ledState = true;
            static unsigned long pulseStart = millis();
            if (millis() - pulseStart < 100UL)
            {
              digitalWrite(ledPin, !ledState);
              pulseStart = millis();
            }
          }
          
          void receiveTime(unsigned long newTime)
          {
            M_DEBUG_PRINTLN(F("Time received..."));
            setTime(newTime);
            char theTime[6];
            sprintf(theTime, "%d:%2d", hour(), minute());
            M_DEBUG_PRINTLN(theTime);
          }
          

          i take an original .stl files from the link provided: https://drive.google.com/drive/folders/0B3KGTJHUgpw1fkwtM3RreEF2QWg4eUdsUHdSQjl6UWx2Q3dPS19WSGdqd0pZQ3hhQk1TMkE

          but in order to save a support material recreate and split it a little ;-)

          The result are visible on photos

          here is an .scad code of my modifications on top of original files, also i print them up side down ;-)

          $fn=300;
          difference(){
          translate([35,0,0])
          import("Can.stl");
          cube([210,150,150],center=true);
          }
          
          
          
          
          translate([62,0,0])
          rotate([0,90,0])
          difference(){
          cylinder(d=10,h=3,center=true);
          cylinder(d=4,h=6,center=true);
          }
          
          
          difference(){
          translate([-88,0,0])
          sphere(d=300);
          translate([-90,0,0])
          sphere(d=300);
          translate([61,0,0])
          rotate([0,90,0])    
          cylinder(d=4,h=4,center=true);
          rotate([0,90,0])
          difference(){
          cylinder(d=310,h=208,center=true);
          cylinder(d=122.5+4,h=310,center=true);
          }    
          }
          
          
          translate([54,0,0])
          rotate([0,90,0])
          difference(){
          cylinder(d=122.5+4,h=108,center=true);
          cylinder(d=122.5,h=310,center=true);
          } 
          
          $fn=300;
          
          /*
          difference(){
          translate([35,0,0])
          import("Can.stl");
          cube([210,150,150],center=true);
          }
          
          
          
          
          translate([62,0,0])
          rotate([0,90,0])
          difference(){
          cylinder(d=10,h=3,center=true);
          cylinder(d=4,h=6,center=true);
          }
          
          
          difference(){
          translate([-88,0,0])
          sphere(d=300);
          translate([-90,0,0])
          sphere(d=300);
          translate([61,0,0])
          rotate([0,90,0])    
          cylinder(d=4,h=4,center=true);
          rotate([0,90,0])
          difference(){
          cylinder(d=310,h=208,center=true);
          cylinder(d=122.5+4,h=310,center=true);
          }    
          }
          */
          
          translate([54,0,0])
          rotate([0,90,0])
          difference(){
          cylinder(d=122.5+4,h=40
             ,center=true);
          cylinder(d=122.5,h=310,center=true);
          } 
          
          
          translate([32,0,0])
          rotate([0,90,0])
          difference(){
          cylinder(d=122.5+4+4,h=8
             ,center=true);
          cylinder(d=122.5+4,h=9,center=true);
          } 
          

          --
          SY
          Enfeet

          dbemowskD Offline
          dbemowskD Offline
          dbemowsk
          wrote on last edited by
          #36

          @Enfeet What type of sensor did you use for the tipping bucket? Reed switch? Hall effect sensor?

          Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
          Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

          EnfeetE 1 Reply Last reply
          0
          • dbemowskD dbemowsk

            @Enfeet What type of sensor did you use for the tipping bucket? Reed switch? Hall effect sensor?

            EnfeetE Offline
            EnfeetE Offline
            Enfeet
            wrote on last edited by
            #37

            @dbemowsk

            20mm magnetic contact like this:
            alt text

            SY
            Enfeet

            dbemowskD 1 Reply Last reply
            0
            • EnfeetE Enfeet

              @dbemowsk

              20mm magnetic contact like this:
              alt text

              SY
              Enfeet

              dbemowskD Offline
              dbemowskD Offline
              dbemowsk
              wrote on last edited by
              #38

              @Enfeet Thanks, it was hard to tell from your pics. It almost looked like a hall sensor. I too am using a reed switch. I have some reed switch boards that I salvaged from some old laptops. They were the sensors for closing the LCD.

              Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
              Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

              1 Reply Last reply
              0
              • EnfeetE Enfeet

                Hi friends,

                here is my replica of Rain Guage MySensors project
                photos:
                https://goo.gl/photos/4kA7T4d8SsDBRrrS7

                The sketch is adopted for 'Adafruit Unified Sensor by Adafruit' + 'DHT sensor library' just uncomment both DHT_ON and DHT_ADAFRUIT
                and last version of Arduino IDE 1.8.3

                ...and Yes, I'm using rfm69hw radio with encryption enabled ;-)

                #define MY_RFM69_ENABLE_ENCRYPTION
                
                /*
                 Arduino Tipping Bucket Rain Gauge
                
                 April 26, 2015
                
                 Version 2.0
                
                 Arduino Tipping Bucket Rain Gauge
                
                 Utilizing a tipping bucket sensor, your Vera home automation controller and the MySensors.org
                 gateway you can measure and sense local rain.  This sketch will create two devices on your
                 Vera controller.  One will display your total precipitation for the last 5 days.  The other, 
                 a sensor that changes state if there is recent rain (up to last 120 hours)  above a threshold.  
                 Both these settings are user definable.
                
                 There is a build overview video here: https://youtu.be/1eMfKQaLROo
                
                 This sketch features the following:
                
                 * Allows you to set the rain threshold in mm
                 * Allows you to determine the tripped indicator window up to 120 hours.
                 * Displays the last 5 days of rain in Variable1 through Variable5
                   of the Rain Sensor device
                 * Configuration changes to Sensor device updated every hour
                 * Should run on any Arduino
                 * Will retain Tripped/Not Tripped status and data in a power interruption, saving small amount
                   of data to EEPROM (Circular Buffer to maximize life of EEPROM)
                 * LED status indicator
                 * Optional Temp/Humidity (DHT-22 or DHT-11) and Light LUX (BH1750) sensors. To use, uncomment
                   #define DHT_ON  and/or #define LUX_ON
                 * Optionally send total accumulation of each day's rainfall or send only individual days rainfall totals.
                   Uncomment #define USE_DAILY to display individual daily rainfall.  If it is commented out it will display
                   a cumulative total rainfall (day4 = day1+day2+day3+day4 etc)
                
                 by @BulldogLowell and @PeteWill for free public use
                
                 */
                
                // Enable debug prints to serial monitor
                //#define MY_DEBUG
                //#define MY_DEBUG_VERBOSE
                #define MY_NODE_ID AUTO
                // Enable and select radio type attached
                //#define MY_RADIO_NRF24
                #define MY_RADIO_RFM69
                #define MY_IS_RFM69HW
                #define MY_RFM69_FREQUENCY RF69_433MHZ
                #define MY_RFM69_NETWORKID 100
                #define MY_RFM69_TX_POWER 31
                
                #include <math.h>
                #include <TimeLib.h>
                #include <MySensors.h>
                
                #define SKETCH_NAME "Rain Gauge"
                #define SKETCH_VERSION "2.0"
                
                #define DWELL_TIME 40  // this allows for radio to come back to power after a transmission, ideally 0 
                
                //#define DEBUG_ON  // Rain gauge specific debug messages. 
                #define DHT_ON // uncomment out this line to enable DHT sensor
                
                // 20170621 by Enfeet
                #define DHT_ADAFRUIT // uncomment out this line to enable DHT with 'Adafruit Unified Sensor by Adafruit' + 'DHT sensor library'
                //#define DHTTYPE           DHT11     // DHT 11 
                #define DHTTYPE           DHT22     // DHT 22 (AM2302)
                //#define DHTTYPE           DHT21     // DHT 21 (AM2301)
                // /20170621 by Enfeet
                
                //#define LUX_ON // uncomment out this line to enable BH1750 sensor
                //#define USE_DAILY // Uncomment to display individual daily rainfall totals in the variables sent to your controller. If it's commented it will add each day to the next for a cumulative total.
                
                #define TIP_SENSOR_PIN 3
                //d=112 mm
                //11689.863832 mm2 =  116,89863832 cm2
                //42,77209787776081 mm
                //88 89 91 91 90 = 89,8
                //0,4763039852757329
                #define CALIBRATE_FACTOR 48 // amount of rain per rain bucket tip e.g. 5 is .05mm
                #define DHT_LUX_DELAY 300000  //Delay in milliseconds that the DHT and LUX sensors will wait before sending data
                
                #define CHILD_ID_RAIN_LOG 3  // Keeps track of accumulated rainfall
                #define CHILD_ID_TRIPPED_INDICATOR 4  // Indicates Tripped when rain detected
                #define EEPROM_BUFFER_LOCATION 0  // location of the EEPROM circular buffer
                #define E_BUFFER_LENGTH 240
                #define RAIN_BUCKET_SIZE 120
                
                  #ifdef  DEBUG_ON
                    #define M_DEBUG_PRINT(x)   Serial.print(x)
                    #define M_DEBUG_PRINTLN(x) Serial.println(x)  
                    #define SERIAL_START(x)  Serial.begin(x)
                    #else
                    #define M_DEBUG_PRINT(x)
                    #define M_DEBUG_PRINTLN(x)
                    #define SERIAL_START(x)
                  #endif
                //
                MyMessage msgRainRate(CHILD_ID_RAIN_LOG, V_RAINRATE);
                MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN);
                //
                MyMessage msgRainVAR1(CHILD_ID_RAIN_LOG, V_VAR1);
                MyMessage msgRainVAR2(CHILD_ID_RAIN_LOG, V_VAR2);
                MyMessage msgRainVAR3(CHILD_ID_RAIN_LOG, V_VAR3);
                MyMessage msgRainVAR4(CHILD_ID_RAIN_LOG, V_VAR4);
                MyMessage msgRainVAR5(CHILD_ID_RAIN_LOG, V_VAR5);
                //
                MyMessage msgTripped(CHILD_ID_TRIPPED_INDICATOR, V_TRIPPED);
                MyMessage msgTrippedVar1(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
                MyMessage msgTrippedVar2(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
                //
                #ifdef DHT_ON
                // 20170621 by Enfeet
                  #ifdef DHT_ADAFRUIT
                  #include <Adafruit_Sensor.h>
                  #include <DHT_U.h>
                  #endif
                // /20170621 by Enfeet
                  #include <DHT.h>
                  #define CHILD_ID_HUM 0
                  #define CHILD_ID_TEMP 1
                  #define HUMIDITY_SENSOR_DIGITAL_PIN 8
                  #ifndef DHT_ADAFRUIT // 20170621 by Enfeet
                    DHT dht;
                  #else 
                    DHT_Unified dht(HUMIDITY_SENSOR_DIGITAL_PIN, DHTTYPE);
                    sensors_event_t event;
                  #endif // /20170621 by Enfeet  
                  float lastTemp;
                  float lastHum;
                  bool metric = true;
                  MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                  MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                #endif
                //
                #ifdef LUX_ON
                  //BH1750 is connected to SCL (analog input A5) and SDA (analog input A4)
                  #include <BH1750.h>
                  #include <Wire.h>
                  #define CHILD_ID_LIGHT 2
                  BH1750 lightSensor;
                  MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
                  unsigned int lastlux;
                  uint8_t heartbeat = 10; //Used to send the light lux to gateway as soon as the device is restarted and after the DHT_LUX_DELAY has happened 10 times
                #endif
                unsigned long sensorPreviousMillis;
                int eepromIndex;
                int tipSensorPin = 3; // Pin the tipping bucket is connected to. Must be interrupt capable pin
                int ledPin = 5; // Pin the LED is connected to.  PWM capable pin required
                #ifdef DEBUG_ON
                unsigned long dataMillis;
                unsigned long serialInterval = 600000UL;
                #endif
                const unsigned long oneHour = 3600000UL;
                unsigned long lastTipTime;
                unsigned long lastRainTime; //Used for rainRate calculation
                unsigned int rainBucket [RAIN_BUCKET_SIZE] ; /* 24 hours x 5 Days = 120 hours */
                unsigned int rainRate = 0;
                uint8_t rainWindow = 72;         //default rain window in hours.  Will be overwritten with msgTrippedVar1.
                volatile int wasTippedBuffer = 0;
                int rainSensorThreshold = 50; //default rain sensor sensitivity in hundredths.  Will be overwritten with msgTrippedVar2.
                uint8_t state = 0;
                uint8_t oldState = 2; //Setting the default to something other than 1 or 0
                unsigned int lastRainRate = 0;
                int lastMeasure = 0;
                bool gotTime = false;
                uint8_t lastHour;
                uint8_t currentHour;
                //
                void presentation()  {
                  // Register all sensors to gw (they will be created as child devices)
                  sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
                  wait(DWELL_TIME);
                  present(CHILD_ID_RAIN_LOG, S_RAIN);
                  wait(DWELL_TIME);
                  present(CHILD_ID_TRIPPED_INDICATOR, S_MOTION);
                  wait(DWELL_TIME);
                
                #ifdef DHT_ON
                  present(CHILD_ID_HUM, S_HUM);
                  wait(DWELL_TIME);
                  present(CHILD_ID_TEMP, S_TEMP);
                  wait(DWELL_TIME);
                #endif
                
                
                #ifdef LUX_ON
                  present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
                #endif
                
                  M_DEBUG_PRINTLN(F("Sensor Presentation Complete"));
                }
                
                void setup()
                {
                  #ifndef MY_DEBUG
                  SERIAL_START(115200);  //Start serial if MySensors debugging isn't enabled
                  #endif
                  //
                  // Set up the IO
                  pinMode(TIP_SENSOR_PIN, INPUT);
                  attachInterrupt (digitalPinToInterrupt(TIP_SENSOR_PIN), sensorTipped, FALLING);  // depending on location of the hall effect sensor may need CHANGE
                  pinMode(ledPin, OUTPUT);
                  digitalWrite(ledPin, HIGH);
                  //
                  //Sync time with the server
                  //
                  unsigned long functionTimeout = millis();
                  while (timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL)
                  {
                    requestTime();
                    M_DEBUG_PRINTLN(F("Getting Time"));
                    wait(1000); // call once per second
                    M_DEBUG_PRINTLN(F("."));
                  }
                  currentHour = hour();
                  lastHour = hour();
                  //
                  //retrieve from EEPROM stored values on a power cycle.
                  //
                  bool isDataOnEeprom = false;
                  for (int i = 0; i < E_BUFFER_LENGTH; i++)
                  {
                    uint8_t locator = loadState(EEPROM_BUFFER_LOCATION + i);
                    if (locator == 0xFE)  // found the EEPROM circular buffer index
                    {
                      eepromIndex = EEPROM_BUFFER_LOCATION + i;
                      M_DEBUG_PRINT(F("EEPROM Index "));
                      M_DEBUG_PRINTLN(eepromIndex);
                      //Now that we have the buffer index let's populate the rainBucket[] with data from eeprom
                      loadRainArray(eepromIndex);
                      isDataOnEeprom = true;
                      break;
                    }
                  }
                  //
                  if (!isDataOnEeprom) // Added for the first time it is run on a new Arduino
                  {
                    M_DEBUG_PRINTLN(F("I didn't find valid EEPROM Index, so I'm writing one to location 0"));
                    eepromIndex = EEPROM_BUFFER_LOCATION;
                    saveState(eepromIndex, 0xFE);
                    saveState(eepromIndex + 1, 0xFE);
                    //then I will clear out any bad data
                    for (int i = 2; i <= E_BUFFER_LENGTH; i++)
                    {
                      saveState(i, 0x00);
                    }
                  }
                  #ifdef DEBUG_ON
                  dataMillis = millis();
                  #endif
                  lastTipTime = millis(); 
                  //
                  request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
                  wait(DWELL_TIME);
                  request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
                  wait(DWELL_TIME);
                  //
                #ifdef DHT_ON
                // 20170621 by Enfeet
                  #ifndef DHT_ADAFRUIT
                    dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
                  #else
                    dht.begin();
                  #endif
                  metric = getControllerConfig().isMetric;
                  wait(DWELL_TIME);
                #endif
                  //
                #ifdef LUX_ON
                  lightSensor.begin();
                #endif
                  //
                  transmitRainData(); //Setup complete send any data loaded from eeprom to gateway
                }
                
                void loop()
                {
                  if (state)
                  {
                    prettyFade();  // breathe if tripped
                  }
                  else
                  {
                    slowFlash();   // blink if not tripped
                  }
                #ifdef DEBUG_ON  // Serial Debug Block
                  if ( (millis() - dataMillis) >= serialInterval)
                  {
                    for (int i = 24; i <= 120; i = i + 24)
                    {
                      updateSerialData(i);
                    }
                    dataMillis = millis();
                  }
                #endif
                  //
                  // let's constantly check to see if the rain in the past rainWindow hours is greater than rainSensorThreshold
                  //
                  int measure = 0; // Check to see if we need to show sensor tripped in this block
                  for (int i = 0; i < rainWindow; i++)
                  {
                    measure += rainBucket [i];
                    if (measure != lastMeasure)
                    {
                      //      M_DEBUG_PRINT(F("measure value (total rainBucket within rainWindow): "));
                      //      M_DEBUG_PRINTLN(measure);
                      lastMeasure = measure;
                    }
                  }
                  //
                  state = (measure >= (rainSensorThreshold * 100));
                  if (state != oldState)
                  {
                    send(msgTripped.set(state));
                    wait(DWELL_TIME);
                    M_DEBUG_PRINT(F("New Sensor State... Sensor: "));
                    M_DEBUG_PRINTLN(state ? "Tripped" : "Not Tripped");
                    oldState = state;
                  }
                  //
                  unsigned long tipDelay = millis() - lastRainTime;
                  if (wasTippedBuffer) // if was tipped, then update the 24hour total and transmit to Vera
                  {
                    M_DEBUG_PRINTLN(F("Sensor Tipped"));
                    M_DEBUG_PRINT(F("rainBucket [0] value: "));
                    M_DEBUG_PRINTLN(rainBucket [0]);
                    send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); //Calculate the total rain for the day
                    wait(DWELL_TIME);
                    wasTippedBuffer--;
                    rainRate = ((oneHour) / tipDelay);
                    if (rainRate != lastRainRate)
                    {
                      send(msgRainRate.set(rainRate, 1));
                      wait(DWELL_TIME);
                      M_DEBUG_PRINT(F("RainRate= "));
                      M_DEBUG_PRINTLN(rainRate);
                      lastRainRate = rainRate;
                    }
                    lastRainTime = lastTipTime;
                  }
                  //
                  currentHour = hour();
                  if (currentHour != lastHour)
                  {
                    M_DEBUG_PRINTLN(F("One hour elapsed."));
                    send(msgRain.set((float)rainTotal(currentHour) / 100, 1)); // send today's rainfall
                    wait(DWELL_TIME);
                    saveState(eepromIndex, highByte(rainBucket[0]));
                    saveState(eepromIndex + 1, lowByte(rainBucket[0]));
                    M_DEBUG_PRINT(F("Saving rainBucket[0] to eeprom. rainBucket[0] = "));
                    M_DEBUG_PRINTLN(rainBucket[0]);
                    for (int i = RAIN_BUCKET_SIZE - 1; i >= 0; i--)//cascade an hour of values back into the array
                    {
                      rainBucket [i + 1] = rainBucket [i];
                    }
                    request(CHILD_ID_TRIPPED_INDICATOR, V_VAR1);
                    wait(DWELL_TIME);
                    request(CHILD_ID_TRIPPED_INDICATOR, V_VAR2);
                    wait(DWELL_TIME);
                    rainBucket[0] = 0;
                    eepromIndex = eepromIndex + 2;
                    if (eepromIndex > EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH)
                    {
                      eepromIndex = EEPROM_BUFFER_LOCATION;
                    }
                    M_DEBUG_PRINT(F("Writing to EEPROM.  Index: "));
                    M_DEBUG_PRINTLN(eepromIndex);
                    saveState(eepromIndex, 0xFE);
                    saveState(eepromIndex + 1, 0xFE);
                    requestTime(); // sync the time every hour
                    wait(DWELL_TIME);
                    transmitRainData();
                    rainRate = 0;
                    send(msgRainRate.set(rainRate, 1));
                    wait(DWELL_TIME);
                    M_DEBUG_PRINTLN(F("Sending rainRate is 0 to controller"));
                    lastHour = hour();
                  }
                  if (millis() - sensorPreviousMillis > DHT_LUX_DELAY)
                  {
                    #ifdef DHT_ON  //DHT Code
                      doDHT();
                    #endif
                    #ifdef LUX_ON
                      doLUX();
                    #endif
                    sensorPreviousMillis = millis();
                  }
                }
                //
                #ifdef DHT_ON
                void doDHT(void)
                {
                  // 20170621 by Enfeet
                  #ifndef DHT_ADAFRUIT
                    float temperature = dht.getTemperature();
                    if (isnan(temperature))
                  #else
                    dht.temperature().getEvent(&event);
                    float temperature = event.temperature;
                    if (isnan(event.temperature))
                  #endif
                  // /20170621 by Enfeet   
                    {
                      M_DEBUG_PRINTLN(F("Failed reading temperature from DHT"));
                    } else if (temperature != lastTemp) 
                    {
                      lastTemp = temperature;
                      #ifndef DHT_ADAFRUIT
                        if (!metric) 
                        {
                          temperature = dht.toFahrenheit(temperature);
                        }
                      #endif
                      send(msgTemp.set(temperature, 1));
                      wait(DWELL_TIME);
                      M_DEBUG_PRINT(F("Temperature is: "));
                      M_DEBUG_PRINTLN(temperature);
                    }
                  // 20170621 by Enfeet
                  #ifndef DHT_ADAFRUIT
                    float humidity = dht.getHumidity();;
                    if (isnan(humidity)) 
                  #else
                    dht.humidity().getEvent(&event);
                    float humidity = event.relative_humidity;
                    if (isnan(event.relative_humidity))
                  #endif
                  // /20170621 by Enfeet     
                    {
                      M_DEBUG_PRINTLN(F("Failed reading humidity from DHT"));
                    } else if (humidity != lastHum) 
                    {
                      lastHum = humidity;
                      send(msgHum.set(humidity, 1));
                      wait(DWELL_TIME);
                      M_DEBUG_PRINT(F("Humidity is: "));
                      M_DEBUG_PRINTLN(humidity);
                    }
                }
                #endif
                //
                #ifdef LUX_ON
                void doLUX(void)
                {
                  unsigned int lux = lightSensor.readLightLevel();// Get Lux value
                  M_DEBUG_PRINT(F("Current LUX Level: "));
                  M_DEBUG_PRINTLN(lux);
                  heartbeat++;
                  if (lux != lastlux || heartbeat > 10) 
                  {
                    send(msg.set(lux));
                    lastlux = lux;
                  }
                  if (heartbeat > 10) 
                  {
                    heartbeat = 0;
                  }
                }
                #endif
                //
                void sensorTipped()
                {
                  unsigned long thisTipTime = millis();
                  if (thisTipTime - lastTipTime > 100UL)
                  {
                    rainBucket[0] += CALIBRATE_FACTOR; // adds CALIBRATE_FACTOR hundredths of unit each tip
                    wasTippedBuffer++;
                  }
                  lastTipTime = thisTipTime;
                }
                //
                int rainTotal(int hours)
                {
                  int total = 0;
                  for ( int i = 0; i <= hours; i++)
                  {
                    total += rainBucket [i];
                  }
                  return total;
                }
                
                #ifdef DEBUG_ON
                void updateSerialData(int x)
                {
                  M_DEBUG_PRINT(F("Rain last "));
                  M_DEBUG_PRINT(x);
                  M_DEBUG_PRINTLN(F(" hours: "));
                  float tipCount = 0;
                  for (int i = 0; i < x; i++)
                  {
                    tipCount = tipCount + rainBucket [i];
                  }
                  tipCount = tipCount / 100;
                  M_DEBUG_PRINTLN(tipCount);
                }
                #endif
                
                void loadRainArray(int eValue) // retrieve stored rain array from EEPROM on powerup
                {
                  for (int i = 1; i < RAIN_BUCKET_SIZE; i++)
                  {
                    eValue = eValue - 2;
                    if (eValue < EEPROM_BUFFER_LOCATION)
                    {
                      eValue = EEPROM_BUFFER_LOCATION + E_BUFFER_LENGTH;
                    }
                    M_DEBUG_PRINT(F("EEPROM location: "));
                    M_DEBUG_PRINTLN(eValue);
                    uint8_t rainValueHigh = loadState(eValue);
                    uint8_t rainValueLow = loadState(eValue + 1);
                    unsigned int rainValue = rainValueHigh << 8;
                    rainValue |= rainValueLow;
                    rainBucket[i] = rainValue;
                    //
                    M_DEBUG_PRINT(F("rainBucket[ value: "));
                    M_DEBUG_PRINT(i);
                    M_DEBUG_PRINT(F("] value: "));
                    M_DEBUG_PRINTLN(rainBucket[i]);
                  }
                }
                
                void transmitRainData(void)
                {
                  M_DEBUG_PRINT(F("In transmitRainData. currentHour = "));
                  M_DEBUG_PRINTLN(currentHour);
                  int rainUpdateTotal = 0;
                  for (int i = currentHour; i >= 0; i--)
                  {
                    rainUpdateTotal += rainBucket[i];
                    M_DEBUG_PRINT(F("Adding rainBucket["));
                    M_DEBUG_PRINT(i);
                    M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
                  }
                  M_DEBUG_PRINT(F("TX Day 1: rainUpdateTotal = "));
                  M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
                  send(msgRainVAR1.set((float)rainUpdateTotal / 100.0, 1)); //Send current day rain totals (resets at midnight)
                  wait(DWELL_TIME);
                #ifdef USE_DAILY
                  rainUpdateTotal = 0;
                #endif
                  for (int i = currentHour + 24; i > currentHour; i--)
                  {
                    rainUpdateTotal += rainBucket[i];
                    M_DEBUG_PRINT(F("Adding rainBucket["));
                    M_DEBUG_PRINT(i);
                    M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
                  }
                  M_DEBUG_PRINT(F("TX Day 2: rainUpdateTotal = "));
                  M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
                  send(msgRainVAR2.set((float)rainUpdateTotal / 100.0, 1));
                  wait(DWELL_TIME);
                #ifdef USE_DAILY
                  rainUpdateTotal = 0;
                #endif
                  for (int i = currentHour + 48; i > currentHour + 24; i--)
                  {
                    rainUpdateTotal += rainBucket[i];
                    M_DEBUG_PRINT(F("Adding rainBucket["));
                    M_DEBUG_PRINT(i);
                    M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
                  }
                  M_DEBUG_PRINT(F("TX Day 3: rainUpdateTotal = "));
                  M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
                  send(msgRainVAR3.set((float)rainUpdateTotal / 100.0, 1));
                  wait(DWELL_TIME);
                #ifdef USE_DAILY
                  rainUpdateTotal = 0;
                #endif
                  for (int i = currentHour + 72; i > currentHour + 48; i--)
                  {
                    rainUpdateTotal += rainBucket[i];
                    M_DEBUG_PRINT(F("Adding rainBucket["));
                    M_DEBUG_PRINT(i);
                    M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
                  }
                  M_DEBUG_PRINT(F("TX Day 4: rainUpdateTotal = "));
                  M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
                  send(msgRainVAR4.set((float)rainUpdateTotal / 100.0, 1));
                  wait(DWELL_TIME);
                #ifdef USE_DAILY
                  rainUpdateTotal = 0;
                #endif
                  for (int i = currentHour + 96; i > currentHour + 72; i--)
                  {
                    rainUpdateTotal += rainBucket[i];
                    M_DEBUG_PRINT(F("Adding rainBucket["));
                    M_DEBUG_PRINT(i);
                    M_DEBUG_PRINTLN(F("] to rainUpdateTotal."));
                  }
                  M_DEBUG_PRINT(F("TX Day 5: rainUpdateTotal = "));
                  M_DEBUG_PRINTLN((float)rainUpdateTotal / 100.0);
                  send(msgRainVAR5.set((float)rainUpdateTotal / 100.0, 1));
                  wait(DWELL_TIME);
                }
                
                void receive(const MyMessage &message)
                {
                  if (message.sensor == CHILD_ID_RAIN_LOG)
                  {
                    // nothing to do here
                  }
                  else if (message.sensor == CHILD_ID_TRIPPED_INDICATOR)
                  {
                    if (message.type == V_VAR1)
                    {
                      rainWindow = atoi(message.data);
                      if (rainWindow > 120)
                      {
                        rainWindow = 120;
                      }
                      else if (rainWindow < 1)
                      {
                        rainWindow = 1;
                      }
                      if (rainWindow != atoi(message.data))   // if I changed the value back inside the boundries, push that number back to Vera
                      {
                        send(msgTrippedVar1.set(rainWindow));
                      }
                    }
                    else if (message.type == V_VAR2)
                    {
                      rainSensorThreshold = atoi(message.data);
                      if (rainSensorThreshold > 10000)
                      {
                        rainSensorThreshold = 10000;
                      }
                      else if (rainSensorThreshold < 1)
                      {
                        rainSensorThreshold = 1;
                      }
                      if (rainSensorThreshold != atoi(message.data))  // if I changed the value back inside the boundries, push that number back to Vera
                      {
                        send(msgTrippedVar2.set(rainSensorThreshold));
                      }
                    }
                  }
                }
                
                void prettyFade(void)
                {
                  float val = (exp(sin(millis() / 2000.0 * PI)) - 0.36787944) * 108.0;
                  analogWrite(ledPin, val);
                }
                
                void slowFlash(void)
                {
                  static bool ledState = true;
                  static unsigned long pulseStart = millis();
                  if (millis() - pulseStart < 100UL)
                  {
                    digitalWrite(ledPin, !ledState);
                    pulseStart = millis();
                  }
                }
                
                void receiveTime(unsigned long newTime)
                {
                  M_DEBUG_PRINTLN(F("Time received..."));
                  setTime(newTime);
                  char theTime[6];
                  sprintf(theTime, "%d:%2d", hour(), minute());
                  M_DEBUG_PRINTLN(theTime);
                }
                

                i take an original .stl files from the link provided: https://drive.google.com/drive/folders/0B3KGTJHUgpw1fkwtM3RreEF2QWg4eUdsUHdSQjl6UWx2Q3dPS19WSGdqd0pZQ3hhQk1TMkE

                but in order to save a support material recreate and split it a little ;-)

                The result are visible on photos

                here is an .scad code of my modifications on top of original files, also i print them up side down ;-)

                $fn=300;
                difference(){
                translate([35,0,0])
                import("Can.stl");
                cube([210,150,150],center=true);
                }
                
                
                
                
                translate([62,0,0])
                rotate([0,90,0])
                difference(){
                cylinder(d=10,h=3,center=true);
                cylinder(d=4,h=6,center=true);
                }
                
                
                difference(){
                translate([-88,0,0])
                sphere(d=300);
                translate([-90,0,0])
                sphere(d=300);
                translate([61,0,0])
                rotate([0,90,0])    
                cylinder(d=4,h=4,center=true);
                rotate([0,90,0])
                difference(){
                cylinder(d=310,h=208,center=true);
                cylinder(d=122.5+4,h=310,center=true);
                }    
                }
                
                
                translate([54,0,0])
                rotate([0,90,0])
                difference(){
                cylinder(d=122.5+4,h=108,center=true);
                cylinder(d=122.5,h=310,center=true);
                } 
                
                $fn=300;
                
                /*
                difference(){
                translate([35,0,0])
                import("Can.stl");
                cube([210,150,150],center=true);
                }
                
                
                
                
                translate([62,0,0])
                rotate([0,90,0])
                difference(){
                cylinder(d=10,h=3,center=true);
                cylinder(d=4,h=6,center=true);
                }
                
                
                difference(){
                translate([-88,0,0])
                sphere(d=300);
                translate([-90,0,0])
                sphere(d=300);
                translate([61,0,0])
                rotate([0,90,0])    
                cylinder(d=4,h=4,center=true);
                rotate([0,90,0])
                difference(){
                cylinder(d=310,h=208,center=true);
                cylinder(d=122.5+4,h=310,center=true);
                }    
                }
                */
                
                translate([54,0,0])
                rotate([0,90,0])
                difference(){
                cylinder(d=122.5+4,h=40
                   ,center=true);
                cylinder(d=122.5,h=310,center=true);
                } 
                
                
                translate([32,0,0])
                rotate([0,90,0])
                difference(){
                cylinder(d=122.5+4+4,h=8
                   ,center=true);
                cylinder(d=122.5+4,h=9,center=true);
                } 
                

                --
                SY
                Enfeet

                dbemowskD Offline
                dbemowskD Offline
                dbemowsk
                wrote on last edited by
                #39

                @Enfeet I was checking out your sketch and was confused on some of the numbers you had commented into your sketch. I am gathering that they are numbers you used to figure out your CALIBRATE_FACTOR number, but I am trying to understand them. These are the numbers I am referring to:

                //d=112 mm
                //11689.863832 mm2 =  116,89863832 cm2
                //42,77209787776081 mm
                //88 89 91 91 90 = 89,8
                //0,4763039852757329
                

                I am assuming that 112 mm is the diameter of your catchment funnel. I cannot however figure out your next number 11689.863832 mm2. What formula did you use to come up with that number? Knowing that may help me understand the rest of the numbers.

                Thanks

                Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                EnfeetE 1 Reply Last reply
                0
                • dbemowskD dbemowsk

                  @Enfeet I was checking out your sketch and was confused on some of the numbers you had commented into your sketch. I am gathering that they are numbers you used to figure out your CALIBRATE_FACTOR number, but I am trying to understand them. These are the numbers I am referring to:

                  //d=112 mm
                  //11689.863832 mm2 =  116,89863832 cm2
                  //42,77209787776081 mm
                  //88 89 91 91 90 = 89,8
                  //0,4763039852757329
                  

                  I am assuming that 112 mm is the diameter of your catchment funnel. I cannot however figure out your next number 11689.863832 mm2. What formula did you use to come up with that number? Knowing that may help me understand the rest of the numbers.

                  Thanks

                  EnfeetE Offline
                  EnfeetE Offline
                  Enfeet
                  wrote on last edited by
                  #40

                  @dbemowsk i use first found online calculator http://onlinemschool.com/math/assistance/figures_area/circle/
                  and... strange.... it gives other result ;-) So my calculations are incorrect ;-(
                  A = 1 4 π d2 = 1 4 π 1122 = 3136 π ≈ 9852.032512

                  SY
                  Sergey

                  EnfeetE dbemowskD 2 Replies Last reply
                  0
                  • EnfeetE Enfeet

                    @dbemowsk i use first found online calculator http://onlinemschool.com/math/assistance/figures_area/circle/
                    and... strange.... it gives other result ;-) So my calculations are incorrect ;-(
                    A = 1 4 π d2 = 1 4 π 1122 = 3136 π ≈ 9852.032512

                    SY
                    Sergey

                    EnfeetE Offline
                    EnfeetE Offline
                    Enfeet
                    wrote on last edited by
                    #41

                    @Enfeet o! d=122 not 112... uff correct ;-)

                    1 Reply Last reply
                    0
                    • EnfeetE Enfeet

                      @dbemowsk i use first found online calculator http://onlinemschool.com/math/assistance/figures_area/circle/
                      and... strange.... it gives other result ;-) So my calculations are incorrect ;-(
                      A = 1 4 π d2 = 1 4 π 1122 = 3136 π ≈ 9852.032512

                      SY
                      Sergey

                      dbemowskD Offline
                      dbemowskD Offline
                      dbemowsk
                      wrote on last edited by
                      #42

                      @Enfeet I have been trying to wrap my head around the formulas for this. I have been basing numbers off of the formulas on this instructables page and after looking at his numbers, I think he has them wrong too. He states :

                      rainfall height = volume of rain collected / catchment area

                      In my rain collector, the length and breadth were 11 cm by 5 cm respectively giving a catchment area of 55 sq.cm. So a collection of 9 milliliters of rain would mean 9 cc/55 sq.cm = 0.16363... cm = 1.6363... mm = 0.394 inches.

                      9cc/55 is 0.16363 cm, but 1.6363 mm does not equal 0.394 inches as stated in the article. According to the conversion I did it is 0.064421. Did I do a calculation wrong?

                      Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                      Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                      EnfeetE 1 Reply Last reply
                      0
                      • dbemowskD dbemowsk

                        @Enfeet I have been trying to wrap my head around the formulas for this. I have been basing numbers off of the formulas on this instructables page and after looking at his numbers, I think he has them wrong too. He states :

                        rainfall height = volume of rain collected / catchment area

                        In my rain collector, the length and breadth were 11 cm by 5 cm respectively giving a catchment area of 55 sq.cm. So a collection of 9 milliliters of rain would mean 9 cc/55 sq.cm = 0.16363... cm = 1.6363... mm = 0.394 inches.

                        9cc/55 is 0.16363 cm, but 1.6363 mm does not equal 0.394 inches as stated in the article. According to the conversion I did it is 0.064421. Did I do a calculation wrong?

                        EnfeetE Offline
                        EnfeetE Offline
                        Enfeet
                        wrote on last edited by
                        #43

                        @dbemowsk I think it's time to look in a book ;-) "The amount of precipitation is expressed in millimeters of a layer of water that would be formed from the precipitation, if they did not evaporate, did not seep into the soil and would not drain. Numerically, the amount of precipitation in millimeters is equal to the amount of kilograms of water left on the site in 1 sq.meter, i.e. 1 mm = 1 kg / 1 m2.

                        EnfeetE dbemowskD 2 Replies Last reply
                        0
                        • EnfeetE Enfeet

                          @dbemowsk I think it's time to look in a book ;-) "The amount of precipitation is expressed in millimeters of a layer of water that would be formed from the precipitation, if they did not evaporate, did not seep into the soil and would not drain. Numerically, the amount of precipitation in millimeters is equal to the amount of kilograms of water left on the site in 1 sq.meter, i.e. 1 mm = 1 kg / 1 m2.

                          EnfeetE Offline
                          EnfeetE Offline
                          Enfeet
                          wrote on last edited by
                          #44

                          @Enfeet Precipitation intensity
                          "Strong" is called rain, if it drops from 15 to 49 mm in 12 hours. Precipitation is also "very strong" when it falls from 50 mm in 12 hours.
                          "Strong snow" - the amount of precipitation from 7 to 19 mm for 12 hours. "Very heavy snow," when its amount exceeds 20 mm in 12 hours.

                          1 Reply Last reply
                          0
                          • EnfeetE Enfeet

                            @dbemowsk I think it's time to look in a book ;-) "The amount of precipitation is expressed in millimeters of a layer of water that would be formed from the precipitation, if they did not evaporate, did not seep into the soil and would not drain. Numerically, the amount of precipitation in millimeters is equal to the amount of kilograms of water left on the site in 1 sq.meter, i.e. 1 mm = 1 kg / 1 m2.

                            dbemowskD Offline
                            dbemowskD Offline
                            dbemowsk
                            wrote on last edited by
                            #45

                            @Enfeet I understand that, my point was I guess more that it gets confusing when the person that wrote the article gets the numbers wrong. The other part that can get a little confusing in this at times is the units of measure and the conversions. When you talk about mm (length) vs mm2 (area) vs mm3 (volume) and you start mixing these together in the calculations. I am in the US, so I work with imperial measures, so then there is the conversions from metric to imperial on top of that. The thing that I think the guy that wrote the article got wrong was his conversion to imperial measure (inches of rainfall). That is more what I was trying to wrap my head around.

                            Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                            Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                            EnfeetE 1 Reply Last reply
                            0
                            • dbemowskD dbemowsk

                              @Enfeet I understand that, my point was I guess more that it gets confusing when the person that wrote the article gets the numbers wrong. The other part that can get a little confusing in this at times is the units of measure and the conversions. When you talk about mm (length) vs mm2 (area) vs mm3 (volume) and you start mixing these together in the calculations. I am in the US, so I work with imperial measures, so then there is the conversions from metric to imperial on top of that. The thing that I think the guy that wrote the article got wrong was his conversion to imperial measure (inches of rainfall). That is more what I was trying to wrap my head around.

                              EnfeetE Offline
                              EnfeetE Offline
                              Enfeet
                              wrote on last edited by
                              #46

                              @dbemowsk Sorry, i m living in metric units ;-) But, i think it can be calculated logically. Just look at a DIY project: https://www.education.com/science-fair/article/DIY-rain-gauge/ The logic is to attach a scale to a bottle and measure the mm or inches of rain occured. Our goal is recalculate the number of impulses to the amount of precipitation depending on square of our bucket. So it's possible to take a bottle with the same square like our bucket, attach a scale (inches or mm does not matter) and let collect all water out of our measuring gauge i.e. take a litter or half flow it to a gauge and collect after. And finally just divide measured level of collected water to the number of impulses counted....
                              Sorry if method is not clear... ;-) I can draw an idea in a pictures ;-)

                              1 Reply Last reply
                              0
                              • EnfeetE Offline
                                EnfeetE Offline
                                Enfeet
                                wrote on last edited by
                                #47

                                Ups! After 3 days.....

                                0_1498752618409_20170629_1909.png

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  schmucke
                                  wrote on last edited by
                                  #48

                                  What kind of powersupply is a good one, if i have errors with bouncing/fakerain?

                                  EnfeetE 1 Reply Last reply
                                  0
                                  • S schmucke

                                    What kind of powersupply is a good one, if i have errors with bouncing/fakerain?

                                    EnfeetE Offline
                                    EnfeetE Offline
                                    Enfeet
                                    wrote on last edited by
                                    #49

                                    @schmucke I'm using 5V 1Amp from tiny mobile charger https://www.thingiverse.com/thing:2171813

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      schmucke
                                      wrote on last edited by
                                      #50

                                      I have the following problem:

                                      Every Time, if a normal switch with a led bulb is switching, the arduino is count one up...

                                      1 Reply Last reply
                                      0
                                      • mfalkviddM Online
                                        mfalkviddM Online
                                        mfalkvidd
                                        Mod
                                        wrote on last edited by
                                        #51

                                        Sounds like the hardware debouncing described in the troubleshooting section might be needed.

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          schmucke
                                          wrote on last edited by
                                          #52

                                          I have just one build, but i use 300ohm. I think, thats to small :/

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


                                          16

                                          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