soil moisture sensor sketch



  • Hi all,

    Just looking for some help here. I have uploaded the soil moisture sensor sketch, but when I look on the serial port, it is just a constant stream of messages alternating as below. Eventually the system fails.

    Even if if I disconnect the moisture sensor from the system it does the same thing, so not the sensor. If I upload a different sketch to the node (Dallas temp sensor for example) it does not have the issue, so I am thinking it is something in the moisture sensor sketch.

    Any suggestions on what is happening?

    Below are the messages that stream past in the serial monitor at high speed

    send: 1-1-0-0 s=0,c=1,t=16,pt=2,l=2,sg=0,st=ok:1
    1
    send: 1-1-0-0 s=0,c=1,t=16,pt=2,l=2,sg=0,st=ok:0
    0
    send: 1-1-0-0 s=0,c=1,t=16,pt=2,l=2,sg=0,st=ok:1
    1
    send: 1-1-0-0 s=0,c=1,t=16,pt=2,l=2,sg=0,st=ok:0
    0
    send: 1-1-0-0 s=0,c=1,t=16,pt=2,l=2,sg=0,st=ok:1
    1

    This is the standard sketch i am using

    /**

    • 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.

    #include <SPI.h>
    #include <MySensor.h>

    #define DIGITAL_INPUT_SOIL_SENSOR 3 // Digital input did you attach your soil sensor.
    #define INTERRUPT DIGITAL_INPUT_SOIL_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 0 // Id of the sensor child

    MySensor gw;
    MyMessage msg(CHILD_ID, V_TRIPPED);
    int lastSoilValue = -1;

    void setup()
    {
    gw.begin();

    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Soil Moisture Sensor", "1.0");
    // sets the soil sensor digital pin as input
    pinMode(DIGITAL_INPUT_SOIL_SENSOR, INPUT);
    // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID, S_MOTION);
    }

    void loop()
    {
    // Read digital soil value
    int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR); // 1 = Not triggered, 0 = In soil with water
    if (soilValue != lastSoilValue) {
    Serial.println(soilValue);
    gw.send(msg.set(soilValue==0?1:0)); // Send the inverse to gw as tripped should be when no water in soil
    lastSoilValue = soilValue;
    }
    // Power down the radio and arduino until digital input changes.
    gw.sleep(INTERRUPT,CHANGE);
    }


  • Contest Winner

    Are you sure you did connect the digital out pin of the moister sensor to D3 and not the analog pin of your sensor?

    You can set Arduino's internal pull up resistors to high so when the sensor is disconnected your system should be stable.
    To do so add this line

    digitalWrite(DIGITAL_INPUT_SOIL_SENSOR, HIGH);       // turn on pullup resistors
    

    below lines

    // sets the soil sensor digital pin as input
    pinMode(DIGITAL_INPUT_SOIL_SENSOR, INPUT);
    


  • @BartE Thanks for that. My issue ended up being with the signal lead from the sensor to the arduino. A bad connector. Your advice on the pull-up resistor was very useful.

    Thanks


Log in to reply
 

Suggested Topics

67
Online

11.4k
Users

11.1k
Topics

112.7k
Posts