This should be a simple one! Water level test (not on constantly)
-
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; } }
-
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.
-
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
-
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.
-
@mfalkvidd said:
thanks! That makes a ton of sense. These forums are awesome, I really appreciate everybody