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
theckoT

thecko

@thecko
About
Posts
6
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Humidity+Relay with button node
    theckoT thecko

    @BartE Adding the extra code done the job, now its working great. Thank you for your help!

    The final working code if someone wonders is:

    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>
    #include <Bounce2.h>
    
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    
    #define NODE_ID 1
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_RELAY 2
    #define RELAY_PIN 3
    #define BUTTON_PIN 4
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    
    MyHwATMega328 hw;
    
    MySensor gw(radio, hw);
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    MyMessage msg(CHILD_ID_RELAY,V_LIGHT);
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()
    {
      gw.begin(incomingMessage, AUTO, true);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
      gw.sendSketchInfo("Combo", "1.0");
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      pinMode(BUTTON_PIN,INPUT);
      digitalWrite(BUTTON_PIN,HIGH);
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      gw.present(CHILD_ID_RELAY, S_LIGHT);
      metric = gw.getConfig().isMetric;
      digitalWrite(RELAY_PIN, RELAY_OFF);
      pinMode(RELAY_PIN, OUTPUT);
      state = gw.loadState(CHILD_ID_RELAY);
      digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
      
    }
    
    
    unsigned long lastCheckTimestamp = 0;
    
    // setup stuff
    
    void incomingMessage(const MyMessage &message) 
    {
      if (message.type == V_LIGHT) 
      {
        digitalWrite(RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF);
        gw.saveState(1, message.getBool());
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    
    void loop()
    {
        gw.process();
        if (debouncer.update() && debouncer.read() == 0) {
           gw.send(msg.set(gw.loadState(1)?false:true), true); // Send new state and request ack back
        }
    
        // Check if the minimal sample period has been passed 
        if ((lastCheckTimestamp < (millis() - dht.getMinimumSamplingPeriod()) ) || lastCheckTimestamp > millis())
        {
          lastCheckTimestamp  = millis();
    
          // do the normal stuff after the delay
          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);
          }
       }
    }
    
    Development

  • Humidity+Relay with button node
    theckoT thecko

    When i try your sketch in this format:

    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>
    #include <Bounce2.h>
    
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    
    #define NODE_ID 1
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_RELAY 2
    #define RELAY_PIN 3
    #define BUTTON_PIN 4
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    
    MyHwATMega328 hw;
    
    MySensor gw(radio, hw);
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    MyMessage msg(CHILD_ID_RELAY,V_LIGHT);
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()
    {
      gw.begin(incomingMessage, AUTO, true);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
      gw.sendSketchInfo("Combo", "1.0");
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      pinMode(BUTTON_PIN,INPUT);
      digitalWrite(BUTTON_PIN,HIGH);
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      gw.present(CHILD_ID_RELAY, S_LIGHT);
      metric = gw.getConfig().isMetric;
      digitalWrite(RELAY_PIN, RELAY_OFF);
      pinMode(RELAY_PIN, OUTPUT);
      state = gw.loadState(CHILD_ID_RELAY);
      digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
      
    }
    
    
    unsigned long lastCheckTimestamp = 0;
    
    // setup stuff
    
    void loop()
    {
        gw.process();
        if (debouncer.update() && debouncer.read() == 0) {
           gw.send(msg.set(gw.loadState(1)?false:true), true); // Send new state and request ack back
        }
    
        // Check if the minimal sample period has been passed 
        if ((lastCheckTimestamp < (millis() - dht.getMinimumSamplingPeriod()) ) || lastCheckTimestamp > millis())
        {
          lastCheckTimestamp  = millis();
    
          // do the normal stuff after the delay
          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);
          }
       }
    }
    

    Forumhlp.ino: In function 'void setup()':
    Forumhlp:44: error: 'incomingMessage' was not declared in this scope
    'incomingMessage' was not declared in this scope

    Seems something is not right, tried deleting incomingMessage line, but no dice.

    Development

  • Humidity+Relay with button node
    theckoT thecko

    @BartE Is there any way to decrease the amount of time the button needs to be pushed ? Maybe my choice of the button is not good, will try another button when i come home?

    Development

  • Humidity+Relay with button node
    theckoT thecko

    Hi, thank you for the suggestions, its working now!
    The final code looks like this:

    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>
    #include <Bounce2.h>
    
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    
    #define NODE_ID 1
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_RELAY 2
    #define RELAY_PIN 3
    #define BUTTON_PIN 4
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    
    MyHwATMega328 hw;
    
    MySensor gw(radio, hw);
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    MyMessage msg(CHILD_ID_RELAY,V_LIGHT);
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()
    {
      gw.begin(incomingMessage, AUTO, true);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
      gw.sendSketchInfo("Combo", "1.0");
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      pinMode(BUTTON_PIN,INPUT);
      digitalWrite(BUTTON_PIN,HIGH);
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      gw.present(CHILD_ID_RELAY, S_LIGHT);
      metric = gw.getConfig().isMetric;
      digitalWrite(RELAY_PIN, RELAY_OFF);
      pinMode(RELAY_PIN, OUTPUT);
      state = gw.loadState(CHILD_ID_RELAY);
      digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
      
    }
    
    
    
    void loop()
    {
      gw.process();
       debouncer.update();
       int value = debouncer.read();
       if (value != oldValue && value==0) {
           gw.send(msg.set(gw.loadState(1)?false:true), true); // Send new state and request ack back
       }
       oldValue = value;
      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);
      }
    }
    
    void incomingMessage(const MyMessage &message) 
    {
      if (message.type == V_LIGHT) 
      {
        digitalWrite(RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF);
        gw.saveState(1, message.getBool());
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

    The only thing that remains is that the button needs to be pressed for about 2 secs to actuate. When measured with a multimeter, it takes about 2 secs to get from 1 to 0. Tried inserting a 4.7k resistor between PIN4 and the button, but still 2 sec for the button to actuate.

    Development

  • Humidity+Relay with button node
    theckoT thecko

    Thee sketch i used is:

    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>
    #include <Bounce2.h>
    
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    
    #define NODE_ID 1
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_RELAY 2
    #define RELAY_PIN 3
    #define BUTTON_PIN 4
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    
    MyHwATMega328 hw;
    
    MySensor gw(radio, hw);
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    MyMessage msg(CHILD_ID_RELAY,V_LIGHT);
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()
    {
      gw.begin(incomingMessage, AUTO, true);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
      gw.sendSketchInfo("Combo", "1.0");
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      pinMode(BUTTON_PIN,INPUT);
      digitalWrite(BUTTON_PIN,HIGH);
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      gw.present(CHILD_ID_RELAY, S_LIGHT);
      metric = gw.getConfig().isMetric;
      digitalWrite(RELAY_PIN, RELAY_OFF);
      pinMode(RELAY_PIN, OUTPUT);
      state = gw.loadState(CHILD_ID_RELAY);
      digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
      
    }
    
    
    
    void loop()
    {
      gw.process();
      debouncer.update();
      int value = debouncer.read();
      if (value != oldValue && value==0) {
          gw.send(msg.set(state?false:true), true); // Send new state and request ack back
      }
      oldValue = value;
      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);
      }
    }
    
    void incomingMessage(const MyMessage &message) 
    {
      if (message.type == V_LIGHT) 
      {
        digitalWrite(RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF);
        gw.saveState(1, message.getBool());
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

    With this sketch i can control the relay with domoticz, but i can only activate the relay, not deactivate.
    I connected the button to GND pin and PIN4 on the Arduino.

    Development

  • Humidity+Relay with button node
    theckoT thecko

    Hi,
    i started playing with Mysensors and Arduino and managed to make a Gateway and the relay/humidity node with the following code:

    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>
    
    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    
    #define NODE_ID 1
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_RELAY 2
    #define RELAY_PIN 3
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
    
    MyHwATMega328 hw;
    
    MySensor gw(radio, hw);
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()
    {
      gw.begin(incomingMessage, AUTO, true);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
      gw.sendSketchInfo("Combo", "1.0");
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      gw.present(CHILD_ID_RELAY, S_LIGHT);
      metric = gw.getConfig().isMetric;
      pinMode(RELAY_PIN, OUTPUT);
      digitalWrite(RELAY_PIN, gw.loadState(1) ? RELAY_ON : RELAY_OFF);
    }
    
    void loop()
    {
      gw.process();
      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);
      }
    }
    
    void incomingMessage(const MyMessage &message) 
    {
      if (message.type == V_LIGHT) 
      {
        digitalWrite(RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF);
        gw.saveState(1, message.getBool());
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

    Since this is copy/pasted from the forum, i am wondering if it is possible to incorporate a hardware button to control the relay. I tried adding code from the Relay with actuator example, but i failed to make it work, i can only turn the relay on with the button. I am using Domoticz as a controller. Any help would be welcome.

    Development
  • Login

  • Don't have an account? Register

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