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. 💬 Soil Moisture Sensor

💬 Soil Moisture Sensor

Scheduled Pinned Locked Moved Announcements
99 Posts 33 Posters 31.6k Views 32 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.
  • alowhumA alowhum

    @ul7aajr said in 💬 Soil Moisture Sensor:

    Try to never try resistive sensors. It is reaaly wrong way. I try to bult few resistive. No way.
    I try to buld some inductive. Yes, it's possible, but lot of analog parts, difficult to calibrate. No way too.
    Capacitive senors is most reliable and has a simple digital schematics.

    Good luck you on your way)

    PS: here is my own sensor http://vegimatics.com/products/current/
    want do discuss - wellcome)

    I'm currently building a sensor that uses the Chirp devices. I want to chain them together. You can get them for 4 dollars each.

    UL7AAjrU Offline
    UL7AAjrU Offline
    UL7AAjr
    wrote on last edited by
    #50

    @alowhum
    Not sure I2C is a good idea excepting case all sensors inside one room. It can be used just for testing to make it easy. As usual RS485 used to connect any sensors to nework. And there is Modbus protocol over RS485 that enable to use not only custom sensors, but kind of devices can be usefull in automatic systems. For example pump controllers, valve controllers....

    So.. no good perspecrives to go

    1 Reply Last reply
    0
    • alowhumA Offline
      alowhumA Offline
      alowhum
      Plugin Developer
      wrote on last edited by
      #51

      Well, the Chirp doesn't support that protocol, so..
      It does have a mini arduino inside. Perhaps you could reprogram it. Then I will happily have a look ;-)

      https://wemakethings.net/chirp/

      1 Reply Last reply
      0
      • UL7AAjrU Offline
        UL7AAjrU Offline
        UL7AAjr
        wrote on last edited by
        #52

        No reason to reprogramm. There is I2C wired outside of sensor instead of UART. And some IC necessary to drive RS485.

        Would be easy to use custom adapter over the sensor with only two IC on board, some MCU and MAX485 (or analog).

        1 Reply Last reply
        0
        • alowhumA Offline
          alowhumA Offline
          alowhum
          Plugin Developer
          wrote on last edited by
          #53

          I found another, simpler sensor on Aliexpress.

          https://www.aliexpress.com/item/NEW-Capacitive-soil-moisture-sensor-not-easy-to-corrode-wide-voltage-wire-for-arduino/32832538686.html

          1 Reply Last reply
          1
          • R RobKuipers

            My two cents. A soil moisture sensor that requires no extra hardware (not counting electric wire). Highly inspired by everything I've read in this thread. Comments welcome.
            Excuse the long post.

            /*
             Name:		MYS_MoistureSensor.ino
             Created:	5/25/2017 1:04:35 PM
             Author:	Rob
            
             Soil moisture measuring by using stainless steel rods (or any other conductor).
             Probably the simplest project ever, since only a MySensors-node and some wire is needed to set things up.
             
             The sketch alternates current during measuring to prevent corrosion of the rods due to electrolyses.
             Odd readings may occur when starting (eg. increasing soil moisture for no apparent reason), please just allow the electrodes to settle down in the soil.
             No extra hardware needed. 
             
             I use an Arduino Mini 3V3, powered on two AA cells. It is suggested you set the fuses for a lower Brown Out Detection (BOD). But anything goes.
            
             Just tie D4 and A0 together to one rod, and D5 and A1 to another rod. This is sensor one.
             For the second sensor tie D6 and A2 together to one rod, and D7 and A3 to another rod.
             Connect a pushbutton between GND and D3 if you need a button that makes the node report immediately (can be omitted)
            
             Measurement are taken every minute and send to the gateway if different from the previous reading.
             In case of no changes, the node reports itself every four hours.
             The output is between 0 (dry) and 100 (wet).
            
             Can also be used as a depth moisture sensor with three sensor zones; in that case use one (common) long rod and three smaller sensors along
             the height of the rod and configure the sketch accordingly.
            	 sensors[0] = { 4, A0, 5, A1, -1, false };
            	 sensors[1] = { 4, A0, 6, A2, -1, false };
            	 sensors[2] = { 4, A0, 7, A3, -1, false };
            
            */
            
            #include "Header.h"
            
            // Enable debug Serial.prints to serial monitor
            //#define MY_DEBUG 
            
            #if defined MY_DEBUG
            #define Sprintln(a) (Serial.println(a))
            #define Sprint(a) (Serial.print(a))
            #else 
            #define Sprintln(a)
            #define Sprint(a)
            #endif
            
            // Enable and select radio type attached
            #define MY_RADIO_RFM69
            #define MY_RFM69_FREQUENCY RF69_868MHZ
            #define MY_IS_RFM69HW
            
            // Use PA_LOW for RF24+PA (Power Amplifier)
            //#define MY_RF24_PA_LEVEL RF24_PA_LOW
            //#define MY_RF24_PA_LEVEL RF24_PA_MAX
            
            #define MY_NODE_ID 4
            
            #include <MySensors.h>
            
            #define ACK 0        // = false
            #define CHILD_ID 1
            #define REPORTNOWSWITCH_PIN 3    // Arduino Digital I/O pin for button/reed switch (must be an interrupt pin!)
            
            #define NUM_MOISTURE_SENSORS 2
            #define CHILD_ID_TEMPERATURE (CHILD_ID+NUM_MOISTURE_SENSORS+1)
            
            #define SENSOR1_ROD1_DIGITAL 4
            #define SENSOR1_ROD1_ANALOG A0
            #define SENSOR1_ROD2_DIGITAL 5
            #define SENSOR1_ROD2_ANALOG A1
            
            #define SENSOR2_ROD1_DIGITAL 6
            #define SENSOR2_ROD1_ANALOG A2
            #define SENSOR2_ROD2_DIGITAL 7
            #define SENSOR2_ROD2_ANALOG A3
            
            #define SLEEP_IN_MS 60000		// every minute a new measurement
            #define EVERY_15_MINUTES (3600000/4/SLEEP_IN_MS)
            #define EVERY_4_HOURS (3600000*4/SLEEP_IN_MS) 
            #define NUM_READS (int)10		// Number of sensor reads for filtering
            
            int countLoops;
            int8_t interruptedBy = -1;
            int oldBatLevel;
            float oldTemperature;
            
            int output_value;
            
            /// Included in Header.h:
            //typedef struct {
            //	int digital_input_a;
            //	int analog_input_a;
            //	int digital_input_b;
            //	int analog_input_b;
            //	int level;
            //	bool connected;
            //} sensorWiring;
            
            sensorWiring sensors[NUM_MOISTURE_SENSORS];
            
            MyMessage msgMoistureSensor(CHILD_ID, V_LEVEL);
            MyMessage msgChipTemp(CHILD_ID_TEMPERATURE, V_TEMP);
            
            
            void before()
            {
            	// All buttons as input-pullup as per ATMEGA recommendation to use less power (and more safety) 
            	// (http://electronics.stackexchange.com/questions/43460/how-should-unused-i-o-pins-be-configured-on-atmega328p-for-lowest-power-consumpt)
            	for (int i = 1; i <= 8; i++)
            	{
            		pinMode(i, INPUT_PULLUP);
            	}
            
            	// Now explicity set pins as needed
            
            	// Setup report-now switch, activate internal pull-up
            	pinMode(REPORTNOWSWITCH_PIN, INPUT_PULLUP);
            
            	// Initialize sensor variables
            
            	// Connect Digital pin 4 to Analog input A0 and a metal rod
            	// Connect Digital pin 5 to Analog input A1 and another metal rod.
            	sensors[0] = { SENSOR1_ROD1_DIGITAL, SENSOR1_ROD1_ANALOG, SENSOR1_ROD2_DIGITAL, SENSOR1_ROD2_ANALOG, -1, false };
            
            	// Connect Digital pin 6 to Analog input A2 and a metal rod
            	// Connect Digital pin 7 to Analog input A3 and another metal rod.
            	sensors[1] = { SENSOR2_ROD1_DIGITAL, SENSOR2_ROD1_ANALOG, SENSOR2_ROD2_DIGITAL, SENSOR2_ROD2_ANALOG, -1, false };
            
            	for  (int i = 0; i<NUM_MOISTURE_SENSORS; i++)
            		sensors[i].connected = testSensorConnections(sensors[i]);
            }
            
            void setup()
            {
            
            }
            
            
            void presentation() {
            	sendSketchInfo("Moisture Sensor", "1.1", ACK);
            
            	for (int i = 0; i < NUM_MOISTURE_SENSORS; i++)
            	{
            		if (sensors[i].connected) present(CHILD_ID+i, S_MOISTURE, ACK);
            	}
            	present(CHILD_ID_TEMPERATURE, S_TEMP);
            }
            
            void loop()
            {
            	bool reportNow = (interruptedBy == digitalPinToInterrupt(REPORTNOWSWITCH_PIN));
            
            	if (reportNow)
            	{
            		// Little trick for debouncing the switch
            		attachInterrupt(digitalPinToInterrupt(REPORTNOWSWITCH_PIN), debounce, RISING);
            		wait(500);
            
            		Sprintln(F("Report now switch pressed"));
            		countLoops = 0;
            
            	}
            
            	for (int i = 0; i < NUM_MOISTURE_SENSORS; i++)
            	{
            		if (sensors[i].connected)
            		{
            			output_value = measure(sensors[i]);
            			if ((sensors[i].level != output_value) || reportNow)
            			{
            				sensors[i].level = output_value;
            				send(msgMoistureSensor.setSensor(CHILD_ID+i).set(output_value), ACK);
            			}
            		}
            	}
            
            	// Every fifteen minutes; poll temperature
            	if (countLoops%EVERY_15_MINUTES==0 || reportNow) 
            	{
            		float newTemp = readTemp();
            		if (oldTemperature != newTemp || reportNow)
            		{
            			send(msgChipTemp.set(newTemp, 1), ACK);
            			oldTemperature = newTemp;
            		}
            
            		int batLevel = getBatteryLevel();
            		if ((oldBatLevel != batLevel) || reportNow) // ...but only when changed, or when button is pressed; 
            		{
            			sendBatteryLevel(batLevel, ACK);
            			oldBatLevel = batLevel;
            		}
            	}
            
            	// So you know I'm alive
            	if (countLoops == EVERY_4_HOURS)
            	{
            		sendHeartbeat(ACK);
            		countLoops = 0;
            	}
            
            	countLoops++;
            
            	interruptedBy = sleep(digitalPinToInterrupt(REPORTNOWSWITCH_PIN), FALLING, SLEEP_IN_MS);
            }
            
            // Connect Digital pin 'digital_input_a' to Analog input 'analog_input_a' and a metal rod,
            // do the same for b
            long measure(sensorWiring sensor)
            {
            	long total = 0;
            	int reading_a = 0;
            	int reading_b = 0;
            
            	for (int i = 0; i<NUM_READS; i++) {
            		// Left to right
            		reading_a = measureOneDirection(sensor.digital_input_a, sensor.digital_input_b, sensor.analog_input_a);
            		// Right to left
            		reading_b = measureOneDirection(sensor.digital_input_b, sensor.digital_input_a, sensor.analog_input_b);
            
            		total += reading_a + reading_b;
            	}
            	return map(total / (2 * NUM_READS), 1023, 0, 0, 100);
            }
            
            long measureOneDirection(int digital_input_1, int digital_input_2, int analog_input_1)
            {
            	pinMode(digital_input_2, OUTPUT);
            	digitalWrite(digital_input_2, LOW);
            	pinMode(digital_input_1, INPUT_PULLUP);
            	delayMicroseconds(100);
            	long reading = analogRead(analog_input_1);
            	//delayMicroseconds(25);
            	pinMode(digital_input_1, INPUT);     // High impedance                 
            	pinMode(digital_input_2, INPUT);     // High impedance                 
            	delay(1);
            
            	Sprint(F("measureOneDirection - Reading "));
            	Sprintln(reading);
            
            	return reading;
            }
            
            // test the connections of both rods of a sensor
            boolean testSensorConnections(sensorWiring moistureSensor)
            {
            	return (testSensorConnection(moistureSensor.digital_input_a, moistureSensor.analog_input_a) && testSensorConnection(moistureSensor.digital_input_b, moistureSensor.analog_input_b));
            }
            
            //  test if digital pin is connected to correct analog pin
            boolean testSensorConnection(int digital_input, int analog_input)
            {
            	pinMode(digital_input, OUTPUT);
            	digitalWrite(digital_input, HIGH);                        
            	delayMicroseconds(100);
            	long reading_1 = analogRead(analog_input);   
            	digitalWrite(digital_input, LOW);                      
            	delayMicroseconds(100);
            	long reading_2 = analogRead(analog_input);   
            	pinMode(digital_input, INPUT);     // High impedance                 
            	delay(1);
            
            	Sprint(F("testSensorConnection - Reading1 "));
            	Sprintln(reading_1);
            	Sprint(F("testSensorConnection - Reading2 "));
            	Sprintln(reading_2);
            
            	bool correct = ((reading_1 == 1023) && (reading_2 == 0));
            	return correct;
            }
            
            float readTemp() 
            {
            #if defined (xxMY_RADIO_RFM69) && !defined(MY_RFM69_NEW_DRIVER)
            	return _radio.readTemperature(-3);
            #else
            	// Read 1.1V reference against MUX3  
            	return (readMUX(_BV(REFS1) | _BV(REFS0) | _BV(MUX3)) - 125) * 0.1075f;
            #endif
            }
            
            long readMUX(uint8_t aControl) 
            {
            	long result;
            
            	ADMUX = aControl;
            	delay(20); // Wait for Vref to settle
            	noInterrupts();
            	// start the conversion
            	ADCSRA |= _BV(ADSC) | _BV(ADIE);
            	set_sleep_mode(SLEEP_MODE_ADC);    // sleep during sample
            	interrupts();
            	sleep_mode();
            	// reading should be done, but better make sure
            	// maybe the timer interrupt fired 
            	while (bit_is_set(ADCSRA, ADSC));
            	// Reading register "ADCW" takes care of how to read ADCL and ADCH.
            	result = ADCW;
            
            	return result;
            
            }
            
            
            // Battery measure
            int getBatteryLevel()
            {
            	int results = (readVcc() - 2000) / 10;
            
            	if (results > 100)
            		results = 100;
            	if (results < 0)
            		results = 0;
            	return results;
            } // end of getBandgap
            
            // when ADC completed, take an interrupt 
            EMPTY_INTERRUPT(ADC_vect);
            
            long readVcc() {
            	long result;
            	// Read 1.1V reference against AVcc
            	result = readMUX(_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1));
            
            	result = 1126400L / result; // Back-calculate AVcc in mV (1024 steps times 1100 mV (1.1V) = 1126400L)
            
            	return result;
            }
            
            
            // Utter nonsense, but needed for attaching an interrupt to...
            void debounce() {
            }
            
            
            
            
            ร Offline
            ร Offline
            รอเรือ
            wrote on last edited by รอเรือ
            #54

            @robkuipers

            Your code will fail compiling in Arduino 1.8.5 (mysensors 2.2.0) with the following errors:

            /mnt/data/Dropbox/UTV/Arduino/SoilMoisture/SoilMoisture.ino: In function 'void before()':
            /mnt/data/Dropbox/UTV/Arduino/SoilMoisture/SoilMoisture.ino:112:114: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
               sensors[0] = { SENSOR1_ROD1_DIGITAL, SENSOR1_ROD1_ANALOG, SENSOR1_ROD2_DIGITAL, SENSOR1_ROD2_ANALOG, -1, false };
                                                                                                                              ^
            /mnt/data/Dropbox/UTV/Arduino/SoilMoisture/SoilMoisture.ino:112:14: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
               sensors[0] = { SENSOR1_ROD1_DIGITAL, SENSOR1_ROD1_ANALOG, SENSOR1_ROD2_DIGITAL, SENSOR1_ROD2_ANALOG, -1, false };
                          ^
            /mnt/data/Dropbox/UTV/Arduino/SoilMoisture/SoilMoisture.ino:116:114: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
               sensors[1] = { SENSOR2_ROD1_DIGITAL, SENSOR2_ROD1_ANALOG, SENSOR2_ROD2_DIGITAL, SENSOR2_ROD2_ANALOG, -1, false };
                                                                                                                              ^
            /mnt/data/Dropbox/UTV/Arduino/SoilMoisture/SoilMoisture.ino:116:14: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
               sensors[1] = { SENSOR2_ROD1_DIGITAL, SENSOR2_ROD1_ANALOG, SENSOR2_ROD2_DIGITAL, SENSOR2_ROD2_ANALOG, -1, false };
                          ^
            

            So the following code need tobe changed to something valid

            sensors[0] = { SENSOR1_ROD1_DIGITAL, SENSOR1_ROD1_ANALOG, SENSOR1_ROD2_DIGITAL, SENSOR1_ROD2_ANALOG, -1, false };
            
            	sensors[1] = { SENSOR2_ROD1_DIGITAL, SENSOR2_ROD1_ANALOG, SENSOR2_ROD2_DIGITAL, SENSOR2_ROD2_ANALOG, -1, false };
            
            

            I'm not a c++ guy so I can't tell what needs to be done. Maybe you or someone else would like to help out?

            Cheers!

            EDIT: After removing the file platform.txt for solving another problem (as suggested here) The problem above vanished. So strange. But it works now so... :sunglasses: :sunglasses: :sunglasses:

            1 Reply Last reply
            1
            • ร Offline
              ร Offline
              รอเรือ
              wrote on last edited by
              #55

              I've found that measuring soil moisture by the electrical resistance is not a trivial task.

              If the probe is put into compact soil containing no mold, you'll typically get a high reading even at very low moisture levels. It will most likely always stay within the span of 90-100%.

              However if the probe is put into pure mold, the readings will range between 0% to 100%.

              My conclusion is that measuring directly in the soil is very unpredictable. A better solution might be to surround the probe with some material that adapts the ambient humidity from whatever kind of soil it's put into.

              1 Reply Last reply
              0
              • alowhumA Offline
                alowhumA Offline
                alowhum
                Plugin Developer
                wrote on last edited by
                #56

                Perhaps the capacitive sensors are more useful.

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

                  I guess it depends on the soil. Resistive measurements works well for all my plants.

                  UL7AAjrU 2 Replies Last reply
                  0
                  • mfalkviddM mfalkvidd

                    I guess it depends on the soil. Resistive measurements works well for all my plants.

                    UL7AAjrU Offline
                    UL7AAjrU Offline
                    UL7AAjr
                    wrote on last edited by
                    #58
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • mfalkviddM mfalkvidd

                      I guess it depends on the soil. Resistive measurements works well for all my plants.

                      UL7AAjrU Offline
                      UL7AAjrU Offline
                      UL7AAjr
                      wrote on last edited by
                      #59

                      @mfalkvidd It depends from mineral composition of soil. I buld capacitive sensor with additional electrodes to measure salinity of soil with resistive method (it measures the resistance of soil to alternating current). So, while value of capacitive sensor stable and let say 50%, value of resistive can be critically changed by adding few milliliters of water with fertilizer. Capacitive value will be chaged only to 60% e.g.

                      It's not a good idea to use resistive sensor, especcialy measuring resistance to direct current.

                      mfalkviddM 1 Reply Last reply
                      0
                      • UL7AAjrU UL7AAjr

                        @mfalkvidd It depends from mineral composition of soil. I buld capacitive sensor with additional electrodes to measure salinity of soil with resistive method (it measures the resistance of soil to alternating current). So, while value of capacitive sensor stable and let say 50%, value of resistive can be critically changed by adding few milliliters of water with fertilizer. Capacitive value will be chaged only to 60% e.g.

                        It's not a good idea to use resistive sensor, especcialy measuring resistance to direct current.

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

                        @ul7aajr could you expand on why is it not a good idea? I've been using my sensors for almost 3 years without noticing any problem.

                        ร 1 Reply Last reply
                        0
                        • UL7AAjrU Offline
                          UL7AAjrU Offline
                          UL7AAjr
                          wrote on last edited by
                          #61

                          Sure. At first, I'm very surprised that your resistive sensor in soil still not destroyed under corrosion especially when the current flows. All my experiments with such sensors have been stuck many years ago. May be a miss sometihing, just show me your sensors after three years in soil? And again, it's a basic phisical things, that the conductivity of the soil depends on the mineral composition. I have already said more than once that there is possible to get a "negative" conductivity of the soil, something like effect of the battery.

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mathieu44444
                            wrote on last edited by
                            #62

                            Hello,
                            I start with mysensors and I do not know much about programming. Is there a possibility to have 7 soil moisture sensor on one or two arduino mini pro.
                            Thank you

                            1 Reply Last reply
                            0
                            • alowhumA Offline
                              alowhumA Offline
                              alowhum
                              Plugin Developer
                              wrote on last edited by alowhum
                              #63

                              My sketch handles 6. Feel free to use it. It uses analog capacitive sensors. They cost about 3 euro.

                              I would recommend getting an Arduino Nano with an Expansion board. Then you don't need to solder anything.
                              https://www.aliexpress.com/item/Free-shipping-Nano-328P-IO-wireless-sensor-expansion-board-for-XBEE-and-NRF24L01-Socket-for-arduino/32298692903.html

                              /**
                               * 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.
                               *
                               *******************************
                               *
                               * DESCRIPTION
                               * 
                               * This node can measure the moisture of 6 different plants. It uses the cheap 'capacitive analog 
                               * moisture sensor' that you can get for about 3 dollars an Aliexpress or eBay. For example:
                               * https://www.aliexpress.com/item/Analog-Capacitive-Soil-Moisture-Sensor-V1-2-Corrosion-Resistant-Z09-Drop-ship/32858273308.html
                               * 
                               * 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..
                               * 
                               * Todo: Allow the controller to set the threshold values for each plant individually. Unfortunately, Domoticz doesn't support this yet :-(
                               * 
                               */
                              
                              //#define MY_SIGNING_SIMPLE_PASSWD "changeme"
                              #define MY_SPLASH_SCREEN_DISABLED                       // saves a little memory.
                              //#define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE          // saves a little memory.
                              
                              #define MY_NODE_ID 60                                   // Optional. Sets fixed id with controller.
                              #define MY_PARENT_NODE_ID 0                             // Optional. Sets fixed id for controller.
                              #define MY_PARENT_NODE_IS_STATIC                        // Optional. Sets fixed id for controller.
                              
                              #define MY_TRANSPORT_WAIT_READY_MS 5000                 // try connecting for 5 seconds. Otherwise just continue.
                              
                              // Enable debug prints to serial monitor
                              //#define MY_DEBUG
                              
                              // Enable and select radio type attached
                              #define MY_RADIO_NRF24
                              //#define MY_RADIO_NRF5_ESB
                              //#define MY_RADIO_RFM69
                              //#define MY_RADIO_RFM95
                              
                              #define MY_RF24_PA_LEVEL RF24_PA_LOW                    // Low power radio setting works better with cheap Chinese radios.
                              
                              #include <MySensors.h>
                              
                              #define NUMBEROFSENSORS 6                               // How many sensors are connected?
                              
                              #define DRYNESSTHRESHOLD 45                             // minimum moisture level that is still ok. A lower value will trigger LED/irrigation.
                              
                              uint32_t 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.
                              unsigned long lastTimeChecked = 0;
                              
                              MyMessage msg(0, V_LEVEL);
                              
                              void before()
                              {
                              
                                for (byte i = 3; i < NUMBEROFSENSORS + 3; i++){             // Set the LED (or irrigation vales) to their initial position.
                                  pinMode(i, OUTPUT);
                                  digitalWrite(i, LOW);
                                }
                                
                              }
                              
                              
                              void presentation()
                              {
                              	// Send the sketch version information to the gateway and Controller
                              	sendSketchInfo(F("Plant Sensorium"), F("1.2"));
                              
                                // present the sensors
                                for (byte i=0; i<NUMBEROFSENSORS ; i++) {
                                  present(i, S_MOISTURE, i); // the last i gives the controller a name, in this case the number of the sensor.
                                }
                              
                              }
                              
                              void setup()
                              {
                                Serial.begin(115200);
                                delay(1000);
                                
                                Serial.println(F("Hello world. Warming up the sensors (15 seconds)."));
                              
                                delay(15000);
                                
                              }
                              
                              void loop()
                              {
                              
                                static byte measurementCounter = 0;                     // Counts the measurements that are done, once per second.
                                uint32_t currentMillis = millis();                      // The millisecond clock in the main loop.
                              
                                if (currentMillis - lastTimeChecked > 1000) {           // Internally, the moisture values are checked every second.
                                  lastTimeChecked = currentMillis;
                                  
                                  Serial.println(F("__________"));
                                  
                                  for (int i=0; i<NUMBEROFSENSORS; i++) {               // loop over all the sensors.
                                    byte shiftedDigitalPin = i + 3;
                                  	int16_t moistureLevel = (1023-analogRead(i))/10.23;
                                    Serial.print(i);
                                    Serial.print(F(" mosture level: "));
                                  	Serial.println(moistureLevel);
                                    Serial.print(F("- output pin: "));
                                    Serial.println(shiftedDigitalPin);      
                                    Serial.print(F("- irrigation/LED state is "));
                                    Serial.println(digitalRead(shiftedDigitalPin));
                              
                                    if(digitalRead(shiftedDigitalPin) == HIGH){                         // outputs the LED/irrigation status via serial. This code can be removed.
                                      Serial.print(F("- currently watering until "));
                                      Serial.println(DRYNESSTHRESHOLD + 10);
                                    }
                              
                                    if (moistureLevel < DRYNESSTHRESHOLD){              // if the plant doesn' have enough water, turn on the LED/water.
                                      Serial.print(F("- moisture level is below "));
                                      Serial.println(DRYNESSTHRESHOLD);
                                      digitalWrite(shiftedDigitalPin, HIGH);
                                    }else if (moistureLevel >= DRYNESSTHRESHOLD + 10){   // turn of the water/led if the plant is wet enough.
                                      digitalWrite(shiftedDigitalPin, LOW);
                                    }
                              
                                    if(measurementCounter < NUMBEROFSENSORS){           // During the first 6 seconds the script will send updated data.
                                      if(measurementCounter == i){                      // it sends sensor 0 at second 0. Sensor 1 at second 1, etc. This keeps the radio happy.
                                        Serial.println(F("- sending data."));
                                        send(msg.setSensor(i).set(moistureLevel));
                                      }
                                    }
                                    if(measurementCounter > SLEEPTIME){ // If enough time has passed, the counter is reset, and new data is sent.
                                      measurementCounter = 0;
                                    }else{
                                      measurementCounter++;
                                    }
                                  }
                                  
                                }
                              }
                              
                              ร 1 Reply Last reply
                              2
                              • M Offline
                                M Offline
                                mathieu44444
                                wrote on last edited by
                                #64

                                I command and I try. Thank you very much

                                alowhumA 1 Reply Last reply
                                1
                                • M mathieu44444

                                  I command and I try. Thank you very much

                                  alowhumA Offline
                                  alowhumA Offline
                                  alowhum
                                  Plugin Developer
                                  wrote on last edited by
                                  #65

                                  @mathieu44444 My pleasure. Good luck.

                                  1 Reply Last reply
                                  0
                                  • mfalkviddM mfalkvidd

                                    @ul7aajr could you expand on why is it not a good idea? I've been using my sensors for almost 3 years without noticing any problem.

                                    ร Offline
                                    ร Offline
                                    รอเรือ
                                    wrote on last edited by
                                    #66

                                    @mfalkvidd , maybe you are using your resistive sensors indoors in soil consisting of 100% mold. (blomjord). I guess it works great. However I'm just curious if your sensors are also working on soil from outdoors. I guess not very well.

                                    M 1 Reply Last reply
                                    0
                                    • ร รอเรือ

                                      @mfalkvidd , maybe you are using your resistive sensors indoors in soil consisting of 100% mold. (blomjord). I guess it works great. However I'm just curious if your sensors are also working on soil from outdoors. I guess not very well.

                                      M Offline
                                      M Offline
                                      manutremo
                                      wrote on last edited by
                                      #67

                                      @รอเร-อ I have resistive sensors (YL-69 type) both indoors and outdoors. Both have been working correctly for months now. I'm using a direct-reverse polarization sketch to minimize corrosion and it seems to work well. What I found to be very important in outdoors sensors is the isolation of the connector between the probe and the cable; if rain water or watering stays into there, they tend to corrode and their resistance increases, therefore fooling the sensor into thinking that the soil is drier than it really is. I have a couple of capacitive sensors somewhere but haven't felt the need to try them since the resistive ones are working well.

                                      ร 1 Reply Last reply
                                      1
                                      • alowhumA alowhum

                                        Perhaps the capacitive sensors are more useful.

                                        ร Offline
                                        ร Offline
                                        รอเรือ
                                        wrote on last edited by รอเรือ
                                        #68

                                        @alowhum

                                        I've ordered 5 capacitive sensors from Aliexpress now. I need to find a way to protect them so I can bury them into the soil in the garden at different depths.

                                        What sketch are you using for capacitive sensors?

                                        EDIT: I just saw your sketch posted above. I will try it out. Thanks!

                                        1 Reply Last reply
                                        0
                                        • M manutremo

                                          @รอเร-อ I have resistive sensors (YL-69 type) both indoors and outdoors. Both have been working correctly for months now. I'm using a direct-reverse polarization sketch to minimize corrosion and it seems to work well. What I found to be very important in outdoors sensors is the isolation of the connector between the probe and the cable; if rain water or watering stays into there, they tend to corrode and their resistance increases, therefore fooling the sensor into thinking that the soil is drier than it really is. I have a couple of capacitive sensors somewhere but haven't felt the need to try them since the resistive ones are working well.

                                          ร Offline
                                          ร Offline
                                          รอเรือ
                                          wrote on last edited by
                                          #69

                                          @manutremo

                                          thanks

                                          here with my soil, it's different. Even at very little moisture it shows 100%. Maybe I have a lot of iron in the soil.

                                          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