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
F

floris

@floris
About
Posts
21
Topics
5
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Dallas temperature and button sensor and repeater function
    F floris

    Hello,

    after 2 years i started again with mysensors, specially for my sons aquarium. i have a temp-sketch working and a button-sketch-with red and green leds working (a reed contact float for water level, and green and red LED for indicate the level near the aquarium, besides a switch signal to the controller (domoticz)). i want to combine both sketches and i came up with this sketch. compiling works fine, but before im broke up my 2 working sketches, will this sketch work? or am i missing something or did i make some mistakes?

    /**
     * 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
     *
     * Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
     * http://www.mysensors.org/build/temp
     */
    
    
    // Enable debug prints to serial monitor
    //#define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DallasTemperature.h>
    #include <OneWire.h>
    #include <Bounce2.h>
    
    
    #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
    
    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
    #define MAX_ATTACHED_DS18B20 16
    
    #define CHILD_ID 6
    #define BUTTON_PIN  6  // Arduino Digital I/O pin for button/reed switch
    
    Bounce debouncer = Bounce(); 
    int oldValue=-1;
    int reading;     // the current reading from the input pin
    int GreenLedPin = 4;  // the number of the Green LED output pin
    int RedLedPin = 5;    // the number of the Red LED output pin
    
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    bool receivedConfig = false;
    bool metric = true;
    // Initialize temperature message
    MyMessage msg(0,V_TEMP);
    
    
    void before()
    {
      // Startup up the OneWire library
      sensors.begin();
    }
    
    void setup()  
    { 
      // requestTemperatures() will not block current thread
      sensors.setWaitForConversion(false);
     // Setup the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
      
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
    
      pinMode (GreenLedPin, OUTPUT);
      pinMode (RedLedPin, OUTPUT);
      Serial.begin(9600);
    
      }
    
    
    
    
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Aquarium Ben", "1.1");
    
      // Fetch the number of attached temperature sensors  
      numSensors = sensors.getDeviceCount();
    
      // Present all sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
         present(i, S_TEMP);
      }
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      present(CHILD_ID, S_DOOR);  
    
    
    }
    
    void loop()     
    {     
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      // query conversion time and sleep until conversion completed
      int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
      sleep(conversionTime);
    
      // Read temperatures and send them to controller 
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
        #endif
    
          // Send in the new temperature
          send(msg.setSensor(i).set(temperature,1));
          // Save new temperatures for next compare
          lastTemperature[i]=temperature;
        }
       debouncer.update();
      // Get the update value
      int value = debouncer.read();
    
      if (value != oldValue) {
         // Send in the new value
         send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
         reading = digitalRead(BUTTON_PIN);
      if (reading == 1) {
        digitalWrite(RedLedPin, HIGH);   // if tilted, turn the red LED ON
        digitalWrite(GreenLedPin, LOW);
       delay(500);
       
      } else {
        digitalWrite(RedLedPin, LOW);
        digitalWrite(GreenLedPin, HIGH);    // if not tilted, turn the green LED ON
      }
      }
      
      }
     // sleep(SLEEP_TIME);
    }
    

    thanks already, FLoris

    Hardware

  • Multisensor_PIR_DHT_LDR_Battery
    F floris

    @n3ro I Mean the sensors advised by the Mysensors store...

    My Project

  • Multisensor_PIR_DHT_LDR_Battery
    F floris

    maybe a stupid question, but can i use this sketch for the recommenced sensors ?
    it's just exactly the sketch im looking for thanks!!

    My Project

  • IR distance sensor with relay and repeater not working
    F floris

    well.. i guess not..... It seems that its working for a short while. after that 1 of the relays does not respond anymore, when i set on relay on, both of the relays are going on? any help where my sketch is wrong?

    Floris

        // Example sketch showing how to control physical relays.
        // This example will remember relay state even after power failure.
    
        #include <MySensor.h>
        #include <SPI.h>
        #include <DistanceGP2Y0A21YK.h>
    #define CHILD_ID_DISTANCE 100
    DistanceGP2Y0A21YK Dist;
    
        #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
        #define NUMBER_OF_RELAYS 2 // Total number of attached relays
        #define RELAY_ON 0  // GPIO value to write to turn on attached relay
        #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
        MySensor gw;
        int numSensors=0;
    boolean receivedConfig = true;
    boolean metric = true;
    int distance;
    int lastDistance=0;
    int loopCounter=0;
        MyMessage msg(1,V_LIGHT);
        MyMessage msgdist(CHILD_ID_DISTANCE,V_DISTANCE);
        
        void setup() 
        {
       Dist.begin(0);
          // Initialize library and add callback for incoming messages
          gw.begin(incomingMessage, AUTO, true);
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("RelayDistanceRepeaterFloris", "1.0");
    
          // Fetch relay status
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
            // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID_DISTANCE,S_DISTANCE);
    gw.present(sensor, S_LIGHT);
            // Then set relay pins in output mode
            pinMode(pin, OUTPUT);   
            // Set relay to last known state (using eeprom storage)
            boolean savedState = gw.loadState(sensor);
            digitalWrite(pin, savedState?RELAY_ON:RELAY_OFF);
            gw.send(msg.set(savedState? 1 : 0));
          }
        }
    
    
        void loop()
        {
          // Alway process incoming messages whenever possible
          gw.process();
                  static unsigned long lastTime = millis();
      if (millis() - lastTime >= 5000UL) // update the distance every 5 seconds
      {
        distance = Dist.getDistanceCentimeter();
    if (distance != lastDistance)
    {
    lastDistance = distance;
    gw.send(msgdist.set(distance));
    }
        lastTime = millis();
        }
        }
    
        void incomingMessage(const MyMessage &message) {
          if (message.type==V_LIGHT) {
             boolean relayState = message.getBool();
            digitalWrite(message.sensor-1+RELAY_1, relayState?RELAY_ON:RELAY_OFF);
             gw.saveState(message.sensor, relayState);
            gw.send(msg.set(relayState? 1 : 0));
          }
        }
    
    Troubleshooting

  • IR distance sensor with relay and repeater not working
    F floris

    Yessss. i guesss i have got it working!!!! thanks for the help! Floris

       // Example sketch showing how to control physical relays.
       // This example will remember relay state even after power failure.
    
        #include <MySensor.h>
        #include <SPI.h>
        #include <DistanceGP2Y0A21YK.h>
    #define CHILD_ID_DISTANCE 100
    DistanceGP2Y0A21YK Dist;
    
        #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
        #define NUMBER_OF_RELAYS 2 // Total number of attached relays
        #define RELAY_ON 0  // GPIO value to write to turn on attached relay
        #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
        MySensor gw;
        int numSensors=0;
    boolean receivedConfig = true;
    boolean metric = true;
    int distance;
    int lastDistance=0;
    int loopCounter=0;
        MyMessage msg(1,V_LIGHT);
        MyMessage msgdist(CHILD_ID_DISTANCE,V_DISTANCE);
        
        void setup() 
        {
       Dist.begin(0);
          // Initialize library and add callback for incoming messages
          gw.begin(incomingMessage, AUTO, true);
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("RelayDistanceRepeaterFloris", "1.0");
    
          // Fetch relay status
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
            // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID_DISTANCE,S_DISTANCE);
    gw.present(sensor, S_LIGHT);
            // Then set relay pins in output mode
            pinMode(pin, OUTPUT);   
            // Set relay to last known state (using eeprom storage)
            boolean savedState = gw.loadState(sensor);
            digitalWrite(pin, savedState?RELAY_ON:RELAY_OFF);
            gw.send(msg.set(savedState? 1 : 0));
          }
        }
    
    
        void loop()
        {
          // Alway process incoming messages whenever possible
          gw.process();
                  static unsigned long lastTime = millis();
      if (millis() - lastTime >= 5000UL) // update the distance every 5 seconds
      {
        distance = Dist.getDistanceCentimeter();
    if (distance != lastDistance)
    {
    lastDistance = distance;
    gw.send(msgdist.set(distance));
    }
        lastTime = millis();
        }
        }
    
        void incomingMessage(const MyMessage &message) {
          if (message.type==V_LIGHT) {
             boolean relayState = message.getBool();
            digitalWrite(message.sensor-1+RELAY_1, relayState?RELAY_ON:RELAY_OFF);
             gw.saveState(message.sensor, relayState);
            gw.send(msg.set(relayState? 1 : 0));
          }
        }
    
    Troubleshooting

  • IR distance sensor with relay and repeater not working
    F floris

    Hi, ok. now i have changed it to this: But my relays doest react...

       // Example sketch showing how to control physical relays.
       // This example will remember relay state even after power failure.
    
       #include <MySensor.h>
       #include <SPI.h>
    #include <DistanceGP2Y0A21YK.h>
    
       #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
       #define NUMBER_OF_RELAYS 2 // Total number of attached relays
       #define RELAY_ON 0  // GPIO value to write to turn on attached relay
       #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    #define CHILD_ID_DISTANCE 100
    DistanceGP2Y0A21YK Dist;
    //    unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
    
       
       MySensor gw;
       int numSensors=0;
    boolean receivedConfig = true;
    boolean metric = true;
    int distance;
    int lastDistance=0;
    int loopCounter=0;
       MyMessage msg(1,V_LIGHT);
       MyMessage msgdist(CHILD_ID_DISTANCE,V_DISTANCE);
    
    
       void setup() 
       {   
    
    Dist.begin(0);
         // Initialize library and add callback for incoming messages
         gw.begin(NULL, AUTO, true);
         // Send the sketch version information to the gateway and Controller
         gw.sendSketchInfo("RelayDistanceFloris", "1.0");
    gw.present(CHILD_ID_DISTANCE,S_DISTANCE);
         // Fetch relay status
         for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
           // Register all sensors to gw (they will be created as child devices)
           gw.present(sensor, S_LIGHT);
           // Then set relay pins in output mode
           pinMode(pin, OUTPUT);   
           // Set relay to last known state (using eeprom storage)
           boolean savedState = gw.loadState(sensor);
           digitalWrite(pin, savedState?RELAY_ON:RELAY_OFF);
           gw.send(msg.set(savedState? 1 : 0));
         }
       }
    
    
       void loop()
       {
         // Alway process incoming messages whenever possible
         gw.process();
           static unsigned long lastTime = millis();
     if (millis() - lastTime >= 5000UL) // update the distance every 5 seconds
     {
       distance = Dist.getDistanceCentimeter();
    if (distance != lastDistance)
    {
    lastDistance = distance;
    gw.send(msgdist.set(distance));
    }
       lastTime = millis();
       }
       }
       void incomingMessage(const MyMessage &message) {
         if (message.type==V_LIGHT) {
            boolean relayState = message.getBool();
           digitalWrite(message.sensor-1+RELAY_1, relayState?RELAY_ON:RELAY_OFF);
            gw.saveState(message.sensor, relayState);
           gw.send(msg.set(relayState? 1 : 0));
         }
       }
    
    
    Troubleshooting

  • IR distance sensor with relay and repeater not working
    F floris

    Hi, thanks. if i disable that sleep, than i get a flipstorm from the distanceinfo. (and i still cant control my relay) i thought i would let send the distanceinfo each 5 seconds (for testing) and for the rest a no sleep mode for repeating and receiving for the relay...

    Troubleshooting

  • IR distance sensor with relay and repeater not working
    F floris

    Hi,
    i cant make my IR distance-repeater-relay sensor to work. It doesnt go into the repeatermode and i cant switch the relays. the distancesensor does work.. anyone any idea?

    // Example sketch showing how to control physical relays.
    // This example will remember relay state even after power failure.
    
    #include <MySensor.h>
    #include <SPI.h>
    

    #include <DistanceGP2Y0A21YK.h>

    #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 2 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    

    #define CHILD_ID_DISTANCE 100
    DistanceGP2Y0A21YK Dist;
    // unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)

    MySensor gw;
    int numSensors=0;
    

    boolean receivedConfig = true;
    boolean metric = true;
    int distance;
    int lastDistance=0;
    int loopCounter=0;
    MyMessage msg(1,V_LIGHT);
    MyMessage msgdist(CHILD_ID_DISTANCE,V_DISTANCE);

    void setup() 
    {   
    

    Dist.begin(0);
    // Initialize library and add callback for incoming messages
    gw.begin(NULL, AUTO, true);
    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("RelayDistanceFloris", "1.0");
    gw.present(CHILD_ID_DISTANCE,S_DISTANCE);
    // Fetch relay status
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    gw.present(sensor, S_LIGHT);
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    boolean savedState = gw.loadState(sensor);
    digitalWrite(pin, savedState?RELAY_ON:RELAY_OFF);
    gw.send(msg.set(savedState? 1 : 0));
    }
    }

    void loop()
    {
      // Alway process incoming messages whenever possible
      gw.process();
    distance = Dist.getDistanceCentimeter();
    

    if (distance != lastDistance) {
    lastDistance = distance;
    gw.send(msgdist.set(distance));
    gw.sleep(50000);
    }
    }
    void incomingMessage(const MyMessage &message) {
    if (message.type==V_LIGHT) {
    boolean relayState = message.getBool();
    digitalWrite(message.sensor-1+RELAY_1, relayState?RELAY_ON:RELAY_OFF);
    gw.saveState(message.sensor, relayState);
    gw.send(msg.set(relayState? 1 : 0));
    }
    }

    Troubleshooting

  • Solar Powered Mini-Weather Station
    F floris

    Hi, I have my weatherstation up and running. The only problem is my rainsensor. It's totally not accurate. Do you have the same?

    Floris

    My Project

  • Domoticz wont toggle light switch via ethernet gateway?
    F floris

    http://www.domoticz.com/forum/viewtopic.php?f=42&t=5784
    Look for gizmoguz 6april, 11:54. :)

    Domoticz

  • Domoticz wont toggle light switch via ethernet gateway?
    F floris

    My ethernetgateway didn't work also. my usb gateway does work. GizMoGuz has replied couple of weeks ago at the domoticz forum about the ethernetgateway with some modifications. Maybe they will work. (did't try it because i'm happy with my usbgateway) wondering if it is working.

    Floris

    Domoticz

  • distance led bar
    F floris

    Hi,

    i want to measure the level of my pellets in my pelletstove. The ultrasonic meter is not working well, so i hope that the infrared will do. I want a led-bar near my stove so i can see what's the level of my pellets. ( 10 cm- green, 20 cm green and orange, 25 cm orange, 30 cm orange, 35 cm orange and red, 40+ cm red). But i really don't know how to fix this. :) My controller (domoticz) can sent me an notification when the level is, for example 35 cm. anybody who can help me?

    Floris

    Troubleshooting

  • Motion and lux meters combined in a single device
    F floris

    Thanks! just what i was looking for!
    Floris

    Hardware

  • Hum temp rain sensor help
    F floris

    @Dwalt thanks, that did the trick. now it's working! thanks!

    Floris

    Troubleshooting

  • Hum temp rain sensor help
    F floris

    Hi Totche, thanks for reaction.

    this is the serial print;
    sensor started, id 11
    send: 11-11-20-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
    send: 11-11-20-0 s=255,c=3,t=6,pt=1,l=1,st=ok:20
    send: 11-11-20-0 s=255,c=3,t=11,pt=0,l=21,st=ok:Floris Multi Rain+Hum
    send: 11-11-20-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 11-11-20-0 s=0,c=0,t=7,pt=0,l=5,st=ok:1.4.1
    send: 11-11-20-0 s=1,c=0,t=6,pt=0,l=5,st=ok:1.4.1
    send: 11-11-20-0 s=3,c=0,t=1,pt=0,l=5,st=ok:1.4.1
    1
    send: 11-11-20-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 11-11-20-0 s=1,c=1,t=0,pt=7,l=5,st=ok:22.3
    T: 22.30
    send: 11-11-20-0 s=0,c=1,t=1,pt=7,l=5,st=ok:59.0
    H: 59.00

    and after using the rain sensor:

    sensor started, id 11
    send: 11-11-20-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
    send: 11-11-20-0 s=255,c=3,t=6,pt=1,l=1,st=ok:20
    send: 11-11-20-0 s=255,c=3,t=11,pt=0,l=21,st=ok:Floris Multi Rain+Hum
    send: 11-11-20-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 11-11-20-0 s=0,c=0,t=7,pt=0,l=5,st=ok:1.4.1
    send: 11-11-20-0 s=1,c=0,t=6,pt=0,l=5,st=ok:1.4.1
    send: 11-11-20-0 s=3,c=0,t=1,pt=0,l=5,st=ok:1.4.1
    1
    send: 11-11-20-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 11-11-20-0 s=1,c=1,t=0,pt=7,l=5,st=ok:22.3
    T: 22.30
    send: 11-11-20-0 s=0,c=1,t=1,pt=7,l=5,st=ok:59.0
    H: 59.00
    0
    send: 11-11-20-0 s=3,c=1,t=16,pt=2,l=2,st=ok:1
    send: 11-11-20-0 s=0,c=1,t=1,pt=7,l=5,st=ok:59.1
    H: 59.10
    1
    send: 11-11-20-0 s=3,c=1,t=16,pt=2,l=2,st=ok:0
    send: 11-11-20-0 s=0,c=1,t=1,pt=7,l=5,st=ok:59.4
    H: 59.40

    Then i get a update from my hum/sensor....(so after activity from the rainsensor, there is an update for hum/rain, and not automagicly). For the moment i want to keep it to 30 seconds, for testing.
    i changed the gw.sleep;
    gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME);
    but no luck so far.

    Troubleshooting

  • Hum temp rain sensor help
    F floris

    Hi,

    i merged 2 sketches and hoped that it would work. but not. the node sends only the temp when there is a change at the rain-sensor. and i want the temp/hum be send each couple of minutes. can anyone help? here is my sketch;.

    [code]
    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_RAIN 3

    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    #define DIGITAL_INPUT_SOIL_SENSOR_PIN 4
    #define INTERRUPT DIGITAL_INPUT_SOIL_SENSOR_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)

    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

    MySensor gw;
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msg(CHILD_ID_RAIN, V_TRIPPED);
    int lastSoilValue = -1;

    void setup()
    { 
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);

    // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Floris Multi Rain+Hum", "1.0");

    // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);

    pinMode(DIGITAL_INPUT_SOIL_SENSOR_PIN, INPUT); // sets the motion sensor digital pin as input
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_RAIN, S_MOTION);
      
     metric = gw.getConfig().isMetric; 
    }

    void loop()
    {

    // Read digital soil value
      int soilValue = digitalRead(DIGITAL_INPUT_SOIL_SENSOR_PIN); // 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;

    delay(dht.getMinimumSamplingPeriod());

    float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
      
      gw.sleep(SLEEP_TIME);
    }
    }

    [/code]

    Troubleshooting

  • relay motion domoticz help
    F floris

    @floris I have got it working!!!!!using a motion/relay sketch from the forum.

    Floris

    Development

  • relay motion domoticz help
    F floris

    Hi,

    i ḿ trying to make my own sketch. using a sketch form domoticz.com has a working relay. i'm trying to implement a motion sensor with no luck so far. can anybody help me?
    here s my sketch;

    // Example sketch showing how to control physical relays.
    // This example will remember relay state even after power failure.

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

    #define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 0 // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    #define CHILD_ID 1 // Id of the sensor child
    #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)

    bool state;
    bool value;

    MySensor gw;
    MyMessage msg(1,V_LIGHT);

    void setup()
    {
    // Initialize library and add callback for incoming messages
    gw.begin(incomingMessage, AUTO, true);
    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("RelayDoMoticz", "1.0");

    // Fetch relay status
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    gw.present(sensor, V_LIGHT);
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    gw.send(msg.set(value==HIGH ? 1 : 0));

      // Send the sketch version information to the gateway and Controller
    

    gw.sendSketchInfo("Motion Sensor", "1.0");

    pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
    // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID, S_MOTION);

    }
    }

    void loop()
    {
    // Alway process incoming messages whenever possible
    gw.process();
    }

    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.type==V_LIGHT) {
    // Change relay state
    digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
    gw.saveState(message.sensor, message.getBool());
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    // Read digital motion value
    boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;

    Serial.println(tripped);
    gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw

    }
    }

    Development

  • Solar Powered Mini-Weather Station
    F floris

    Great, thanks.

    My Project

  • Solar Powered Mini-Weather Station
    F floris

    you are welcome, thank you for sharing! I'm going to use a waterproof box with a transparent cover. did you connect your hum/temp to d4, rain to d3 and lux to a4 and a5? ( i dont have the barometer yet)

    My Project
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular