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. Troubleshooting
  3. This should be a simple one! Water level test (not on constantly)

This should be a simple one! Water level test (not on constantly)

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 3 Posters 1.6k Views 2 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.
  • P Offline
    P Offline
    punter9
    wrote on last edited by
    #1

    Ok I am working away steadily at my automatic garden. I could use some help figuring out how to power up, read, and then power down my water level sensors.

    Currently I have 4 bolts in a 5 gallon bucket for water (and a pump). The bottom bolt is ground and the top 3 are for various water level indications. Currently I have it set up to read from digital pins but these are on all the time and this will cause significant amounts of electrolysis. What I would like to do is utilize millis and pin settings to turn the pins on, take a reading, and turn them off. Due to the nature of my operation I only need to do this about 4 times a day.

    If anyone could help me out with my code I would really appreciate it!

    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define CHILD_ID3 3
    #define BUTTON_PIN1  3  // Arduino Digital I/O pin for button/reed switch
    #define CHILD_ID4 4
    #define BUTTON_PIN2  4  // Arduino Digital I/O pin for button/reed switch
    #define CHILD_ID5 5
    #define BUTTON_PIN3  5  // Arduino Digital I/O pin for button/reed switch
    
    long previousMillis = 0;
    long interval = (10000); //delay betweein readings - 1000 is 1 second
    
    MySensor gw;
    Bounce debouncer = Bounce(); 
    int oldValue1=-1;
    int oldValue2=-1;
    int oldValue3=-1;
    
    MyMessage msg1(CHILD_ID3,V_TRIPPED), msg2(CHILD_ID4,V_TRIPPED),msg3(CHILD_ID5,V_TRIPPED); // Change to V_LIGHT if you use S_LIGHT in presentation below
    
    void setup()  
    {  
      gw.begin();
    
     gw.sendSketchInfo("3 Binary Switches", "1.0");
      pinMode(BUTTON_PIN1,INPUT);
      pinMode(BUTTON_PIN2,INPUT);
      pinMode(BUTTON_PIN3,INPUT);
      
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN1,HIGH);
      digitalWrite(BUTTON_PIN2,HIGH);
      digitalWrite(BUTTON_PIN3,HIGH);
    
      gw.present(CHILD_ID3, S_DOOR);// Register binary input sensor to gw (they will be created as child devices)
      gw.present(CHILD_ID4, S_DOOR); // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
      gw.present(CHILD_ID5, S_DOOR);  // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.  
    }
    
    void loop() 
    {
      unsigned long currentMillis = millis();     
    
      if (currentMillis - previousMillis > interval) {
      debouncer.update();
      int value1 = debouncer.read();
      int value2 = debouncer.read();
      int value3 = debouncer.read();
      value1 = digitalRead(BUTTON_PIN1);
      value2 = digitalRead(BUTTON_PIN2);
      value3 = digitalRead(BUTTON_PIN3);
      gw.send(msg1.set(value1==HIGH ? 1 : 0));// Send in the new value
      oldValue1 = value1;
      gw.send(msg2.set(value2==HIGH ? 1 : 0));// Send in the new value
      oldValue2 = value2;
      gw.send(msg3.set(value3==HIGH ? 1 : 0));// Send in the new value
      oldValue3 = value3; 
    } 
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      sundberg84
      Hardware Contributor
      wrote on last edited by
      #2

      Hi!

      It might be possible to use gw.sleep(SLEEP_TIME); to power your node down when its not used?
      I dont know if you have to set the pins low before this but better safe... ?

      There are many examples, temp sketch, that uses this.

      I use sleep all the time to save battery on my nodes and that works great.

      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
      • P Offline
        P Offline
        punter9
        wrote on last edited by punter9
        #3

        Thanks for the help!

        I may be wrong but I believe that only sleeps the radio but wouldn't shut down the digital pins in the water (the electrolysis). I'm also a noob so that may be way off lol.

        I have a relay attached to it as well so I really need it to be running. With the help from this forum I am using digital pins to power my moisture sensors and turning them on and off to prevent electrolysis (take a reading on analog pin). Works great, I'd like a similar setup here if possible

        1 Reply Last reply
        0
        • mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

          Move

            // Activate internal pull-up
            digitalWrite(BUTTON_PIN1,HIGH);
            digitalWrite(BUTTON_PIN2,HIGH);
            digitalWrite(BUTTON_PIN3,HIGH);
          

          out from setup(), place them just after

          debouncer.update();
          

          instead, and add

            // Deactivate internal pull-up
            digitalWrite(BUTTON_PIN1,LOW);
            digitalWrite(BUTTON_PIN2,LOW);
            digitalWrite(BUTTON_PIN3,LOW);
          

          after

          oldValue3 = value3; 
          

          and you should be OK.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            punter9
            wrote on last edited by punter9
            #5

            @mfalkvidd said:

            thanks! That makes a ton of sense. These forums are awesome, I really appreciate everybody

            1 Reply Last reply
            1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            16

            Online

            12.0k

            Users

            11.2k

            Topics

            113.4k

            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