Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. floris
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    floris

    @floris

    0
    Reputation
    21
    Posts
    763
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    floris Follow

    Best posts made by floris

    This user hasn't posted anything yet.

    Latest posts made by floris

    • Dallas temperature and button sensor and repeater function

      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

      posted in Hardware
      floris
      floris
    • RE: Multisensor_PIR_DHT_LDR_Battery

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

      posted in My Project
      floris
      floris
    • RE: Multisensor_PIR_DHT_LDR_Battery

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

      posted in My Project
      floris
      floris
    • RE: IR distance sensor with relay and repeater not working

      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));
            }
          }
      
      posted in Troubleshooting
      floris
      floris
    • RE: IR distance sensor with relay and repeater not working

      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));
            }
          }
      
      posted in Troubleshooting
      floris
      floris
    • RE: IR distance sensor with relay and repeater not working

      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));
           }
         }
      
      
      posted in Troubleshooting
      floris
      floris
    • RE: IR distance sensor with relay and repeater not working

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

      posted in Troubleshooting
      floris
      floris
    • IR distance sensor with relay and repeater not working

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

      posted in Troubleshooting
      floris
      floris
    • RE: Solar Powered Mini-Weather Station

      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

      posted in My Project
      floris
      floris
    • RE: Domoticz wont toggle light switch via ethernet gateway?

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

      posted in Domoticz
      floris
      floris