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. Hardware
  3. soil moisture sensor sketch

soil moisture sensor sketch

Scheduled Pinned Locked Moved Hardware
3 Posts 2 Posters 2.2k Views 1 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.
  • D Offline
    D Offline
    diggs
    wrote on last edited by
    #1

    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.

    • REVISION HISTORY
    • Version 1.0 - Henrik Ekblad
    • DESCRIPTION
    • Example sketch sending soil moisture alarm to controller
    • http://www.mysensors.org/build/moisture
      */

    #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);
    }

    1 Reply Last reply
    0
    • BartEB Offline
      BartEB Offline
      BartE
      Contest Winner
      wrote on last edited by
      #2

      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);
      
      1 Reply Last reply
      0
      • D Offline
        D Offline
        diggs
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        23

        Online

        11.7k

        Users

        11.2k

        Topics

        113.0k

        Posts


        Copyright 2019 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