Skip to content

Commit 3733750

Browse files
Capacitive plant moisture sensor
A simple node to check on your plants. It can check on 6 plants. It uses cheap capacitive sensors, which don't rust and are less affected by soil minerals. Optionally, the user can connect 6 warning LED's (or 6 solenoids to give each plant water). - Non-blocking - Low memory use, to allow encryption on an Arduino Nano.
1 parent 5e9233f commit 3733750

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* The MySensors Arduino library handles the wireless radio link and protocol
3+
* between your home built sensors/actuators and HA controller of choice.
4+
* The sensors forms a self healing radio network with optional repeaters. Each
5+
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
6+
* network topology allowing messages to be routed to nodes.
7+
*
8+
* Created by Henrik Ekblad <[email protected]>
9+
* Copyright (C) 2013-2015 Sensnology AB
10+
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
11+
*
12+
* Documentation: http://www.mysensors.org
13+
* Support Forum: http://forum.mysensors.org
14+
*
15+
* This program is free software; you can redistribute it and/or
16+
* modify it under the terms of the GNU General Public License
17+
* version 2 as published by the Free Software Foundation.
18+
*
19+
*******************************
20+
*
21+
* DESCRIPTION
22+
*
23+
* This node can measure the moisture of 6 different plants. It uses the cheap 'capacitive analog
24+
* moisture sensor' that you can get for about 3 dollars an Aliexpress or eBay. For example:
25+
* https://www.aliexpress.com/item/Analog-Capacitive-Soil-Moisture-Sensor-V1-2-Corrosion-Resistant-Z09-Drop-ship/32858273308.html
26+
*
27+
* Each plant' moisture value can also be responded to individually, either by turning on an LED (wire that to the plan, and you can see which one is thirsty) or, if you want, per-plant automated irrigation by connecting a little solenoid..
28+
*
29+
* Todo: Allow the controller to set the threshold values for each plant individually. Unfortunately, Domoticz doesn't support this yet :-(
30+
*
31+
*/
32+
33+
//#define MY_SIGNING_SIMPLE_PASSWD "changeme" // Useful if your MySensors network is encrypted.
34+
#define MY_SPLASH_SCREEN_DISABLED // saves a little memory.
35+
//#define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE // saves a little memory.
36+
37+
//#define MY_NODE_ID 60 // Optional. Sets fixed id with controller.
38+
//#define MY_PARENT_NODE_ID 0 // Optional. Sets fixed id for controller.
39+
//#define MY_PARENT_NODE_IS_STATIC // Optional. Sets fixed id for controller.
40+
41+
#define MY_TRANSPORT_WAIT_READY_MS 10000 // try connecting to the gateway for 10 seconds. Otherwise just continue.
42+
43+
// Enable debug prints to serial monitor
44+
// #define MY_DEBUG
45+
46+
// Enable and select radio type attached
47+
#define MY_RADIO_NRF24
48+
//#define MY_RADIO_NRF5_ESB
49+
//#define MY_RADIO_RFM69
50+
//#define MY_RADIO_RFM95
51+
52+
#define MY_RF24_PA_LEVEL RF24_PA_LOW // Low power radio setting works better with cheap Chinese radios.
53+
54+
#include <MySensors.h>
55+
56+
#define NUMBEROFSENSORS 6 // How many sensors are connected?
57+
#define DRYNESSTHRESHOLD 45 // minimum moisture level that is still ok. A lower value will trigger LED/irrigation.
58+
59+
#define SLEEPTIME 60 // sleep time between the sending of data (in SECONDS). Maximum is 254 seconds. Change "byte" to "int" further down in the code if you want more time between sending updates.
60+
unsigned long lastTimeChecked = 0; // used by the measurement timer.
61+
62+
MyMessage msg(0, V_LEVEL); // used to send data to the gateway.
63+
64+
void before()
65+
{
66+
for (byte i = 3; i < NUMBEROFSENSORS + 3; i++){ // Set the LED (or irrigation valves) to their initial position. Because Mysensors uses pin 2, we use pin 3 till 8 as output.
67+
pinMode(i, OUTPUT);
68+
digitalWrite(i, LOW);
69+
}
70+
}
71+
72+
void presentation()
73+
{
74+
// send the sketch version information to the gateway and Controller
75+
sendSketchInfo(F("Plant Sensorium"), F("1.0"));
76+
// present the sensors
77+
for (byte i=0; i<NUMBEROFSENSORS ; i++) {
78+
present(i, S_MOISTURE);
79+
}
80+
}
81+
82+
void setup()
83+
{
84+
Serial.begin(115200);
85+
delay(1000);
86+
Serial.println(F("Hello world. Warming up the sensors (15 seconds).")); // to avoid weird measurements
87+
delay(15000);
88+
}
89+
90+
void loop()
91+
{
92+
93+
static byte measurementCounter = 0; // Counts the measurements. Internally the node measures once per second.
94+
95+
if (millis() - lastTimeChecked > 1000) {
96+
lastTimeChecked = millis();
97+
98+
Serial.println(F("__________"));
99+
100+
for (int i=0; i<NUMBEROFSENSORS; i++) { // loop over all the sensors.
101+
byte shiftedDigitalPin = i + 3; // uses pin 3 till 8 as output. Connect some LED's.
102+
int16_t moistureLevel = (1023-analogRead(i))/10.23;
103+
Serial.print(i);
104+
Serial.print(F(" mosture level: "));
105+
Serial.println(moistureLevel);
106+
107+
if (moistureLevel < DRYNESSTHRESHOLD){ // if the plant doesn' have enough water, turn on the LED/water.
108+
Serial.print(F("- moisture level is below "));
109+
Serial.println(DRYNESSTHRESHOLD);
110+
digitalWrite(shiftedDigitalPin, HIGH);
111+
}else if (moistureLevel >= DRYNESSTHRESHOLD + 10){ // turn of the water/led if the plant is wet enough.
112+
digitalWrite(shiftedDigitalPin, LOW);
113+
}
114+
115+
if(measurementCounter < NUMBEROFSENSORS){ // During the first 6 seconds the script will send updated data.
116+
if(measurementCounter == i){ // it sends sensor 0 at second 0. Sensor 1 at second 1, etc. This keeps the radio happy.
117+
send(msg.setSensor(i).set(moistureLevel));
118+
}
119+
}
120+
if(measurementCounter > SLEEPTIME){ // If enough time has passed, the counter is reset, and new data is sent.
121+
measurementCounter = 0;
122+
}else{
123+
measurementCounter++;
124+
}
125+
}
126+
127+
}
128+
}

0 commit comments

Comments
 (0)