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. Controllers
  3. Domoticz
  4. How to add a sensor to the serial gateway

How to add a sensor to the serial gateway

Scheduled Pinned Locked Moved Domoticz
25 Posts 6 Posters 27.5k 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.
  • S Offline
    S Offline
    sundberg84
    Hardware Contributor
    wrote on last edited by sundberg84
    #21

    @Bram81
    I would try (not at home and cant try):

    int Analog_Input_Soil_Sensor= A0;
    int Analog_Input_Soil_Sensor = 0;

    as you wrote before, and not #define interrupt analog_input_soil_sensor -2

    Also you get only 0 and 1 because this is what you send to the gateway: gw.send(Msg.set(soilva... 0?1:0)
    Either you have to define what 0 and 1 is (say dry = 0 moist = 1) or if you want to send it as % use another gw.send code.

    Controller: Proxmox VM - Home Assistant
    MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
    MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
    RFLink GW - Arduino Mega + RFLink Shield, 433mhz

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sundberg84
      Hardware Contributor
      wrote on last edited by sundberg84
      #22

      Here is an example of someone build a soil sensor using the light_sensor
      http://forum.mysensors.org/topic/1492/soil-moisture-analog-input-question
      If you remove the battery code this could be used if you connect to analog pin (Se code below)

      #include <SPI.h>
      #include <MySensor.h>
      
      #define CHILD_ID_LIGHT 0
      #define LIGHT_SENSOR_ANALOG_PIN 1
      
      MySensor gw;
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      int lastLightLevel;
      
      void setup()
      {
      gw.begin();
      
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");
      
      // Register all sensors to gateway (they will be created as child devices)
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      }
      
      void loop()
      {
      int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
      Serial.println(lightLevel);
      if (lightLevel != lastLightLevel) {
      gw.send(msg.set(lightLevel));
      lastLightLevel = lightLevel;
      }
      }
      
      

      if you want lightlevel in % with a Min and a Max then:

      #include <SPI.h>
      #include <MySensor.h>
      
      #define CHILD_ID_LIGHT 0
      #define LIGHT_SENSOR_ANALOG_PIN 1
      #define MIN 300  // Liquid
      #define MAX 1023 // Air
      
      MySensor gw;
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      int lastLightLevel;
      
      void setup()
      {
      gw.begin();
      
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");
      
      // Register all sensors to gateway (they will be created as child devices)
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      }
      
      void loop()
      {
      int lightLevel = static_cast<int>(((analogRead(LIGHT_SENSOR_ANALOG_PIN)-MIN)/(MAX-MIN))*100.);
      Serial.println(lightLevel);
      if (lightLevel != lastLightLevel) {
      gw.send(msg.set(lightLevel));
      lastLightLevel = lightLevel;
      }
      }
      
      

      I have read some more...
      About the digital pin and use (as you mentioned at first... )
      It looks like there is a switch/nob on the hardware you can turn.
      This will set the trigger point between dry and moist and send 1 or 0.
      I think thats why the scetches was using S_Motion... either its dry (untriggered) or wet (triggered).
      I dont know how to program or wire this though...

      Best of luck :) Hope i didnt just complicate things...

      Controller: Proxmox VM - Home Assistant
      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

      B 1 Reply Last reply
      0
      • S sundberg84

        Here is an example of someone build a soil sensor using the light_sensor
        http://forum.mysensors.org/topic/1492/soil-moisture-analog-input-question
        If you remove the battery code this could be used if you connect to analog pin (Se code below)

        #include <SPI.h>
        #include <MySensor.h>
        
        #define CHILD_ID_LIGHT 0
        #define LIGHT_SENSOR_ANALOG_PIN 1
        
        MySensor gw;
        MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        int lastLightLevel;
        
        void setup()
        {
        gw.begin();
        
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");
        
        // Register all sensors to gateway (they will be created as child devices)
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        }
        
        void loop()
        {
        int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
        Serial.println(lightLevel);
        if (lightLevel != lastLightLevel) {
        gw.send(msg.set(lightLevel));
        lastLightLevel = lightLevel;
        }
        }
        
        

        if you want lightlevel in % with a Min and a Max then:

        #include <SPI.h>
        #include <MySensor.h>
        
        #define CHILD_ID_LIGHT 0
        #define LIGHT_SENSOR_ANALOG_PIN 1
        #define MIN 300  // Liquid
        #define MAX 1023 // Air
        
        MySensor gw;
        MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        int lastLightLevel;
        
        void setup()
        {
        gw.begin();
        
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");
        
        // Register all sensors to gateway (they will be created as child devices)
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        }
        
        void loop()
        {
        int lightLevel = static_cast<int>(((analogRead(LIGHT_SENSOR_ANALOG_PIN)-MIN)/(MAX-MIN))*100.);
        Serial.println(lightLevel);
        if (lightLevel != lastLightLevel) {
        gw.send(msg.set(lightLevel));
        lastLightLevel = lightLevel;
        }
        }
        
        

        I have read some more...
        About the digital pin and use (as you mentioned at first... )
        It looks like there is a switch/nob on the hardware you can turn.
        This will set the trigger point between dry and moist and send 1 or 0.
        I think thats why the scetches was using S_Motion... either its dry (untriggered) or wet (triggered).
        I dont know how to program or wire this though...

        Best of luck :) Hope i didnt just complicate things...

        B Offline
        B Offline
        Bram81
        wrote on last edited by
        #23

        @sundberg84 Hey! Thank you verry much for your help and suggestions!!
        I actually got it working combining your sketch witch my simple one resulting in this:

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

        #define CHILD_ID_LIGHT 0
        #define LIGHT_SENSOR_ANALOG_PIN 1
        #define MIN 300 // Liquid
        #define MAX 1023 // Air

        int sensorPin = A0; // select the input pin for the potentiometer
        int sensorValue = 0; // variable to store the value coming from the sensor

        MySensor gw;
        MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        int lastLightLevel;

        void setup(){

        Serial.begin(9600);

        gw.begin();

        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");

        // Register all sensors to gateway (they will be created as child devices)
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        }

        void loop(){
        // read the value from the sensor:
        sensorValue = analogRead(sensorPin);
        delay(1000);
        Serial.print("sensor = " );
        Serial.println(sensorValue);
        gw.send(msg.set(sensorValue));
        }

        The sensor shows up in Domoticz as a light sensor meassuring in lux, but the numbers do match the output of the sensor.

        Another thing is that after about 15 min the gateway started functioning. Seems like a problem that I had last week returned...
        Loading the board with the pingpongtest shows that suddenly my radio chip is recognized as NRF24L01 instead of the + version, although the label on te chips shows NRF24L01+
        Changing radios doesn't help, I'm completely in the dark... maybe just shitty radios..?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mortommy
          wrote on last edited by
          #24

          Hi @hek , the link above it's broken. Is it yet available anywhere?
          Thank you.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hek
            Admin
            wrote on last edited by
            #25

            It has been merged now. Available here:
            https://github.com/mysensors/Arduino

            1 Reply Last reply
            0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            14

            Online

            12.0k

            Users

            11.2k

            Topics

            113.4k

            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