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.
  • 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 Offline
                mfalkviddM Offline
                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
                  • kotzerK Offline
                    kotzerK Offline
                    kotzer
                    wrote on last edited by
                    #53

                    nice idea, nice project, nice documentation, nice result :+1: :heart: :heart:
                    but i've a problem with the led. this is only HIGH when the arduino boots up for ~2 secs. then set to 0 (LOW).

                    i adjusted some debugging message to find out, what exactly happens, but am stucking here.. in the loop it goes into slowFlash(), but there nothing is called against the led_pin (because of if (millis() - pulseStart < 100UL))

                    what am i doing wrong?
                    why is the led only fired at startup, but not when trapped (manually closed the reed switch for short time to simulate some rain)?
                    what was the intension of the led? (nothing could be found in description & video of pete)
                    @petewill I don't see the led in your vid... where is it?

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      itbeyond
                      wrote on last edited by
                      #54

                      Folks, A question of interest. I have had my gauge working great for several months but it has just started to play up. It seems to crash after a few hours. I have not plugged in a debug/console or anything as yet but decided to have a good look at the code and I have noticed that every hour the system cycles through updating EPROM values to cascade the rain rates. I have also noted with interest a comment in the API that mentions some 300K updates as max for the EPROM - I just looked at the Ardunio documentation and it states 100K read/write cycles till EPROM failure. If I am reading this right then maybe my problems are related to dead EPROM storage caused after months of hourly write cycles - Is this a possibility and if yes should we not look at another method of update management for the gauge - I do not want to have to trash an Arduino every few months, I am looking at the code and need more time to get a full handle on it however there appears to be write cycles every hour even if the values have not changed. Is this something to investigate? Is there a way to know if an Arduino EPROM has failed due to excessive write cycles?

                      mfalkviddM 1 Reply Last reply
                      0
                      • I itbeyond

                        Folks, A question of interest. I have had my gauge working great for several months but it has just started to play up. It seems to crash after a few hours. I have not plugged in a debug/console or anything as yet but decided to have a good look at the code and I have noticed that every hour the system cycles through updating EPROM values to cascade the rain rates. I have also noted with interest a comment in the API that mentions some 300K updates as max for the EPROM - I just looked at the Ardunio documentation and it states 100K read/write cycles till EPROM failure. If I am reading this right then maybe my problems are related to dead EPROM storage caused after months of hourly write cycles - Is this a possibility and if yes should we not look at another method of update management for the gauge - I do not want to have to trash an Arduino every few months, I am looking at the code and need more time to get a full handle on it however there appears to be write cycles every hour even if the values have not changed. Is this something to investigate? Is there a way to know if an Arduino EPROM has failed due to excessive write cycles?

                        mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by mfalkvidd
                        #55

                        @itbeyond there are 8,760 hours in a year, so 100,000 writes should last more than 10 years.
                        MySensors does not re-write the same data if the data has not changed, so a save call does not always result in a write.
                        The code uses a ring buffer to lessen the risk of writing too much to a single eeprom position.

                        So eeprom writes should not be a problem. But maybe Arduino clones can't handle 100,000 writes?

                        I guess an alternative could be to store the data in ram and send it to the controller periodically so the data can be fetched when the Arduino (re)boots. Or do the aggregation on the controller, where ram and storage is plentiful.

                        The best way I know to detect eeprom failures is to repeatedly read and measure time for each read. On esp8266 I've seen reads that take more than 100x normal time when the eeprom was damaged.

                        I 1 Reply Last reply
                        1
                        • mfalkviddM mfalkvidd

                          @itbeyond there are 8,760 hours in a year, so 100,000 writes should last more than 10 years.
                          MySensors does not re-write the same data if the data has not changed, so a save call does not always result in a write.
                          The code uses a ring buffer to lessen the risk of writing too much to a single eeprom position.

                          So eeprom writes should not be a problem. But maybe Arduino clones can't handle 100,000 writes?

                          I guess an alternative could be to store the data in ram and send it to the controller periodically so the data can be fetched when the Arduino (re)boots. Or do the aggregation on the controller, where ram and storage is plentiful.

                          The best way I know to detect eeprom failures is to repeatedly read and measure time for each read. On esp8266 I've seen reads that take more than 100x normal time when the eeprom was damaged.

                          I Offline
                          I Offline
                          itbeyond
                          wrote on last edited by
                          #56

                          @mfalkvidd thanks for the important info on the saveState - I have not looked at the API code in this respect and if it does not write same data this is a very good. I have also looked into the code some more there are 4 possible writes per hour which using your maths is 35k write per year so it still should be good for a few years (clones well yes who knows). I may have another problem but I am not sure what - if I reboot it is runs fine for several hours and randomly seems to stop sending data however even if the EPROM is stuffed it should not affect the temp, hum and light level sensors. I may be seeing some funny humid reading so the DHT could be faulty also - I may replace this firstly and see what the result is. Thanks for the response.

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

                            Hi all,

                            finally i rewrite a code for myself. There is no More EEPROM usage at all.
                            I'm using MajorDoMo (http://majordomohome.com/) and it more suitable for me to have a 10 minutes counts from Rain Gauge.

                            Here is my new code:

                            #define MY_RFM69_ENABLE_ENCRYPTION
                            
                            /**
                             * 
                             Author: Sergey E. Yakovlev
                             Date: 2017/02/25 u001
                             
                             * The MySensors Arduino library handles the wireless radio link and protocol
                             * between your home built sensors/actuators and HA controller of choice.
                             * The sensors forms a self healing radio network with optional repeaters. Each
                             * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                             * network topology allowing messages to be routed to nodes.
                             *
                             * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                             * Copyright (C) 2013-2015 Sensnology AB
                             * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                             *
                             * Documentation: http://www.mysensors.org
                             * Support Forum: http://forum.mysensors.org
                             *
                             * This program is free software; you can redistribute it and/or
                             * modify it under the terms of the GNU General Public License
                             * version 2 as published by the Free Software Foundation.
                             *
                            */
                            
                            #define SKETCH_NAME "Enic Rain Gauge"
                            #define SKETCH_VERSION "0.1"
                            #define DWELL_TIME 40  // this allows for radio to come back to power after a transmission, ideally 0 
                            #define DHT_ON // uncomment out this line to enable DHT sensor
                            
                            
                            
                            // Enable debug prints to serial monitor
                            //#define MY_DEBUG
                            //#define MY_DEBUG_VERBOSE
                            //#define MY_NODE_ID AUTO
                            #define MY_NODE_ID 15
                            #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 <MySensors.h>
                            #include <Adafruit_Sensor.h>
                            #include <DHT_U.h>
                            #define CHILD_ID_HUM 0
                            #define CHILD_ID_TEMP 1
                            #define CHILD_ID_RAIN_LOG 3  // Keeps track of accumulated rainfall
                            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
                            #define DHTPIN       8         // Pin which is connected to the DHT sensor.
                            // Uncomment the type of sensor in use:
                            //#define DHTTYPE           DHT11     // DHT 11 
                            #define DHTTYPE           DHT22     // DHT 22 (AM2302)
                            //#define DHTTYPE           DHT21     // DHT 21 (AM2301)
                            char buff[10];
                            unsigned long SEND_FREQUENCY = 60000*10; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
                            DHT_Unified dht(DHTPIN, DHTTYPE);
                            #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
                            MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                            MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                            MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN);
                            
                            sensors_event_t event;
                            unsigned long lastSend;               //Last Send millis()
                            unsigned long lastTipTime=millis();
                            volatile unsigned int rainBucket=0;
                            
                            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);
                            
                            #ifdef DHT_ON
                              present(CHILD_ID_HUM, S_HUM);
                              wait(DWELL_TIME);
                              present(CHILD_ID_TEMP, S_TEMP);
                              wait(DWELL_TIME);
                            #endif
                            
                            
                            //  M_DEBUG_PRINTLN(F("Sensor Presentation Complete"));
                            }
                            
                            void setup()
                            {
                              // 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);
                            
                            }
                            
                            void loop(){
                              unsigned long now = millis();
                              if (now - lastSend > SEND_FREQUENCY) {
                              send(msgRain.set((float)rainBucket / 100, 1));
                              rainBucket=0;
                              wait(DWELL_TIME);
                            
                              // Get temperature event and print its value.
                              double t = -1;
                              dht.temperature().getEvent(&event);
                              if (isnan(event.temperature)) {
                                debug(PSTR("!USR:DHT:Error reading temperature!\n"));
                              } else {
                                  t = event.temperature;
                                  dtostrf(t,6,(uint8_t)2,buff); 
                                  debug(PSTR("USR:DHT:t=%s\n"),buff);
                                  send(msgTemp.set(buff)); 
                              }
                              // Get humidity event and print its value.
                              double h = -1;
                              dht.humidity().getEvent(&event);
                              if (isnan(event.relative_humidity)) {
                                debug(PSTR("!USR:DHT:Error reading humidity!\n"));
                              } else {
                                  h = event.relative_humidity;
                                  dtostrf(h,6,(uint8_t)2,buff); 
                                  debug(PSTR("USR:DHT:h=%s\n"),buff);
                                  send(msgHum.set(buff));        
                              }
                                lastSend=now;
                              }
                            }
                            void sensorTipped()
                            {
                              unsigned long thisTipTime = millis();
                              if (thisTipTime - lastTipTime > 100UL)
                              {
                                rainBucket += CALIBRATE_FACTOR; // adds CALIBRATE_FACTOR hundredths of unit each tip
                              }
                              lastTipTime = thisTipTime;
                            }
                            

                            0_1505816593504_RainGauge20170918.png

                            And now i able to see when it was a rain and how strong it was ;-)


                            SY
                            Sergey

                            1 Reply Last reply
                            1
                            • I itbeyond

                              @mfalkvidd thanks for the important info on the saveState - I have not looked at the API code in this respect and if it does not write same data this is a very good. I have also looked into the code some more there are 4 possible writes per hour which using your maths is 35k write per year so it still should be good for a few years (clones well yes who knows). I may have another problem but I am not sure what - if I reboot it is runs fine for several hours and randomly seems to stop sending data however even if the EPROM is stuffed it should not affect the temp, hum and light level sensors. I may be seeing some funny humid reading so the DHT could be faulty also - I may replace this firstly and see what the result is. Thanks for the response.

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

                              @itbeyond Like @mfalkvidd pointed out eeprom writes are done to multiple locations so it actually gets 120 hours before the same eeprom location is used. So, 120 X 100,000 is over 1,000 years (if my math is right). That should be enough :)

                              The good thing about using eeprom is that you won't loose any data if your gateway is down or the communication is lost for some reason.

                              I think you are correct debugging other areas like the DHT. Also, is there a chance your arduino got wet? That could also cause issues.

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

                              1 Reply Last reply
                              0
                              • H Offline
                                H Offline
                                haroon552
                                wrote on last edited by
                                #59

                                Hi, dear how can we connect with application or something to watch and to connect with nidemcu?

                                1 Reply Last reply
                                0
                                • sundberg84S Offline
                                  sundberg84S Offline
                                  sundberg84
                                  Hardware Contributor
                                  wrote on last edited by sundberg84
                                  #60

                                  Hello! This is my just revised rain gauge sensor. Working with Homeassistant and needs a tipping bucket which closes and opens a reed switch when tipping in the different directions. (Pro Mini 3.3v, Battery operated (voltage divider included in code) and NRF24 radio).

                                  // Enable debug prints to serial monitor
                                  #define MY_DEBUG
                                  
                                  #define MY_RADIO_RF24
                                  #define MY_NODE_ID 7
                                  #define MY_PARENT_NODE_ID 99
                                  
                                  #include <SPI.h>
                                  #include <MySensors.h>
                                  
                                  #define DIGITAL_INPUT_SENSOR 3                  // The reed switch you attached.  (Only 2 and 3 generates interrupt!)
                                  
                                  #define CHILD_ID 1                              // Id of the sensor child
                                  #define SKETCH_NAME "Rain Gauge"                // Change to a fancy name you like
                                  #define SKETCH_VERSION "1.2"                    // Your version
                                  
                                  unsigned long SLEEP_TIME = 18 * 60000;          // Sleep time (in milliseconds).
                                  //unsigned long SLEEP_TIME = 20000;             // use this instead for debug
                                  
                                  float hwRainVolume = 0;                         // Current rainvolume calculated in hardware.
                                  int pulseCount = 0;                             // Pulsecount recieved from GW
                                  float fullCounter = 0;                           // Counts when to send counter
                                  float bucketSize = 0.5;                           // Bucketsize mm, needs to be 1, 0.5, 0.25, 0.2 or 0.1
                                  boolean pcReceived = false;                     // If we have recieved the pulscount from GW or not
                                  int recrequestcount = 0;                        //Counter for how many times we request pulses before we reset it.
                                  boolean reedState;                              // Current state the reedswitch is in
                                  boolean oldReedState;                           // Old state (last state) of the reedswitch
                                  unsigned long lastSend = 0;                     // Time we last tried to fetch counter.
                                  
                                  MyMessage volumeMsg(CHILD_ID, V_RAIN);
                                  MyMessage lastCounterMsg(CHILD_ID, V_VAR1);
                                  
                                  //=========================
                                  // BATTERY MEASURER
                                  // VOLTAGE DIVIDER SETUP
                                  // 1M, 470K divider across battery and using internal ADC ref of 1.1V
                                  // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                                  // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
                                  // 3.44/1023 = Volts per bit = 0.003363075
                                  #define VBAT_PER_BITS 0.003363075
                                  #define VMIN 2.2                                  //  Vmin (radio Min Volt)=1.9V (564v)
                                  #define VMAX 3.1                                  //  Vmax = (2xAA bat)=3.0V (892v)
                                  int batteryPcnt = 0;                              // Calc value for battery %
                                  int batLoop = 0;                                  // Loop to help calc average
                                  int batArray[3];                                  // Array to store value for average calc.
                                  int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
                                  //=========================
                                  
                                  void presentation() {
                                  
                                    // Send the Sketch Version Information to the Gateway
                                    sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
                                  
                                    // Register this device as Rain sensor (will not show in Domoticz until first value arrives)
                                    present(CHILD_ID, S_RAIN);
                                  }
                                  
                                  
                                  void setup()
                                  {
                                  
                                    //=========================
                                    // BATTERY MEASURER
                                    //Set internal ref to internal to be able to measure bat 0-1v
                                    //Make sure this fits other sensors using analogRead()!
                                    //If you have a sensor reporting 0-5v you need to change analogReference() before reading that sensor.
                                  
                                    analogReference(INTERNAL);
                                    //DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
                                    //INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 (not available on the Arduino Mega)
                                    //EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
                                  
                                    //Battery inital calc
                                    Serial.print("With Battery VMax (100%) = "); Serial.print(VMAX); Serial.print("volts and Vmin (0%) = "); Serial.print(VMIN); Serial.println(" volts");
                                    Serial.print("Battery Percent 25%/50%/75% calculates to: "); Serial.print(((VMAX - VMIN) / 4) + VMIN); Serial.print("/"); Serial.print(((VMAX - VMIN) / 2) + VMIN); Serial.print("/"); Serial.println(VMAX - ((VMAX - VMIN) / 4));
                                    delay(1000);
                                    int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                    delay(50);
                                    float Vbat  = sensorValue * VBAT_PER_BITS;
                                    int batteryPcnt = static_cast<int>(((Vbat - VMIN) / (VMAX - VMIN)) * 100.);
                                    Serial.print("Current battery are measured to (please confirm!): "); Serial.print(batteryPcnt); Serial.print(" % - Or "); Serial.print(Vbat); Serial.println(" Volts");
                                    //=========================
                                  
                                    delay(500); // Allow time for radio if power used as reset
                                  
                                    pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);  // sets the reed sensor digital pin as input
                                  
                                    reedState = digitalRead(DIGITAL_INPUT_SENSOR); // Read what state the reedswitch is in
                                    oldReedState = reedState; // Set startup position for reedswitch
                                  
                                    Serial.println("Startup completed");
                                  }
                                  
                                  void loop()     {
                                  
                                    unsigned long currentTime = millis();
                                    //Read if the bucket tipped over
                                    reedState = digitalRead(DIGITAL_INPUT_SENSOR);
                                    Serial.println(reedState);
                                    Serial.println(oldReedState);
                                  
                                    boolean tipped = oldReedState != reedState;
                                  
                                    if (recrequestcount == 10 && !pcReceived) {
                                      //For some controllers, if you dont have any V_VAR1 stored node will not get an answer.
                                      //Try 10 times, then set V_VAR1 to 0 and update controller
                                      Serial.println("Set p-cnt and update controller");
                                      pcReceived = true;
                                      recrequestcount = 0;
                                      send(lastCounterMsg.set(pulseCount));  // Send pulse count 0 value to gw
                                      hwRainVolume = 0;
                                      send(volumeMsg.set((float)hwRainVolume, 1));
                                      lastSend = currentTime;
                                    }
                                  
                                    //See if we have the counter/pulse from Domoticz - and ask for it if we dont.
                                    if (!pcReceived && (currentTime - lastSend > 5000)) {
                                      request(CHILD_ID, V_VAR1);
                                  #ifdef MY_DEBUG
                                      Serial.println("Req p-cnt");
                                  #endif
                                      lastSend = currentTime;
                                      recrequestcount = recrequestcount + 1;
                                      return;
                                    }
                                    if (!pcReceived) {
                                      return;
                                    }
                                  
                                    //BUCKET TIPS!
                                    if (tipped == true) {
                                      Serial.println("The bucket has tipped over...");
                                      oldReedState = reedState;
                                      hwRainVolume = hwRainVolume + bucketSize;
                                      send(volumeMsg.set((float)hwRainVolume, 1));
                                      wait(500);
                                      fullCounter = fullCounter + bucketSize;
                                  
                                      //Count so we send the counter for every 1mm
                                      if (fullCounter >= 1) {
                                        pulseCount++;
                                        send(lastCounterMsg.set(pulseCount));
                                        wait(1000);
                                        fullCounter = 0;
                                      }
                                  
                                    }
                                  
                                    if (tipped == false) {
                                      //No bucket tipped over last sleep-period, check battery then...
                                      MeasureBattery();
                                    }
                                  
                                    lastSend = currentTime;
                                    sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); //The interupt can be CHANGE or FALLING depending on how you wired the hardware.
                                  }
                                  
                                  
                                  void receive(const MyMessage &message)
                                  {
                                    if (message.getType() == V_VAR1) {
                                      pulseCount = message.getLong();
                                      Serial.print("Received last pulse count value from gw:");
                                      Serial.println(pulseCount);
                                      pcReceived = true;
                                    }
                                  }
                                  
                                  //=========================
                                  // BATTERY MEASURER
                                  void MeasureBattery() {  //The battery calculations
                                    delay(500);
                                    // Battery monitoring reading
                                    int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                    delay(500);
                                  
                                    // Calculate the battery in %
                                    float Vbat  = sensorValue * VBAT_PER_BITS;
                                    int batteryPcnt = static_cast<int>(((Vbat - VMIN) / (VMAX - VMIN)) * 100.);
                                  #ifdef MY_DEBUG
                                    Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.print(" % - "); Serial.print("Battery Voltage: "); Serial.print(Vbat); Serial.println(" Volts");
                                  #endif
                                  
                                    // Add it to array so we get an average of 3 (3x20min)
                                    batArray[batLoop] = batteryPcnt;
                                  
                                    if (batLoop > 2) {
                                      batteryPcnt = (batArray[0] + batArray[1] + batArray[2]);
                                      batteryPcnt = batteryPcnt / 3;
                                  
                                      if (batteryPcnt > 100) {
                                        batteryPcnt = 100;
                                      }
                                  #ifdef MY_DEBUG
                                      Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
                                  #endif
                                      sendBatteryLevel(batteryPcnt);
                                      batLoop = 0;
                                    }
                                    else
                                    {
                                      batLoop++;
                                    }
                                  }
                                  //=========================
                                  

                                  Controller: Proxmox VM - Home Assistant
                                  MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                                  MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                                  RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                                  1 Reply Last reply
                                  0
                                  • D Offline
                                    D Offline
                                    djal
                                    wrote on last edited by
                                    #61

                                    Hi all,
                                    thanks for sharing the models for 3D printing. I built one 3 years ago and it is still running with one pair of AA batteries, MySensors and Arduino Pro Mini.
                                    Last year I needed some adjustments and adaptations for friends so I got inspired and remodeled the rain gauge for 3Dprinter.
                                    Maybe it could be usefull for someone so I decided to share it here (https://www.prusaprinters.org/prints/130513-rain-gauge)

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


                                    11

                                    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