Navigation

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

    Remco van Geel

    @Remco van Geel

    0
    Reputation
    2
    Posts
    279
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Remco van Geel Follow

    Best posts made by Remco van Geel

    This user hasn't posted anything yet.

    Latest posts made by Remco van Geel

    • combining scripts almost finished but with a fault I don't see.

      I tried to combine some scripts. first I had a 4 in 1: dht22, motion sensor and lux. Now I wanted to add a ds1820 for temperatur of warm water.

      the idea is to send every 2 a 3 minutes all readings to domoticz. execpt motion that must be immediately.

      this is my script:

      #include <SPI.h>
      #include <MySensor.h>  
      #include <DHT.h>  
      #include <BH1750.h>
      #include <Wire.h> 
        #include <DallasTemperature.h>
        #include <OneWire.h>
      
        #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
        #define ONE_WIRE_BUS 5
        #define MAX_ATTACHED_DS18B20 1
      
      #define CHILD_ID_LIGHT 0
      #define CHILD_ID_TEMP2 5
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_MOT 2   // Id of the sensor child
      
      #define HUMIDITY_SENSOR_DIGITAL_PIN 4
      #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)
      
      
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      
      BH1750 lightSensor;
        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. 
      MySensor gw;
      DHT dht;
      float lastTemperature[MAX_ATTACHED_DS18B20];
      int numSensors=0;
      boolean receivedConfig = false;
      boolean metric = true; 
      float lastTemp;
      float lastHum;
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      MyMessage msgTemperature(CHILD_ID_TEMP2,V_TEMP);
      uint16_t lastlux;
      
      void setup()  
      { 
      
        // Startup up the OneWire library
        sensors.begin();
        // requestTemperatures() will not block current thread
        sensors.setWaitForConversion(false);
        
        // Startup and initialize MySensors library. Set callback for incoming messages. 
        gw.begin();
        
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Temp/Temp/Humidity/Motion/Lux", "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_TEMP2, S_TEMP);
        gw.present(CHILD_ID_HUM, S_HUM);
        gw.present(CHILD_ID_TEMP, S_TEMP);
        gw.present(CHILD_ID_MOT, S_MOTION);
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
         
        metric = gw.getConfig().isMetric;
          lightSensor.begin();
      }
      
      void loop()      
      
      {  
        // Read digital motion value
        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
        Serial.println(tripped);
        gw.send(msgMot.set(tripped?"1":"0"));  // Send tripped value to gw 
        
        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("Temp: ");
          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("Hum: ");
            Serial.println(humidity);
        }
      
          uint16_t lux = lightSensor.readLightLevel();// Get Lux value
          if (lux != lastlux) {
            gw.send(msg.set(lux));
            lastlux = lux;
        Serial.print("lux: ");
          Serial.println(lux);
        }
        
        
        // Ds1820 
        // Process incoming messages (like config from server)
          gw.process(); 
        // 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)
          gw.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>((gw.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
                gw.send(msg.setSensor(i).set(temperature,1));
                // Save new temperatures for next compare
                lastTemperature[i]=temperature;
              Serial.print("DS1820: ");
              Serial.println(temperature);
          }
              }
        // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
        gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      }
      
      
      

      and this is the serial output:

      send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=ok:1.5
      send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
      read: 0-0-1 s=255,c=3,t=6,pt=0,l=1,sg=0:M
      sensor started, id=1, parent=0, distance=1
      send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=25,sg=0,st=ok:Temp/Temp/Humidity/Motion
      send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
      send: 1-1-0-0 s=5,c=0,t=6,pt=0,l=0,sg=0,st=ok:
      send: 1-1-0-0 s=0,c=0,t=7,pt=0,l=0,sg=0,st=ok:
      send: 1-1-0-0 s=1,c=0,t=6,pt=0,l=0,sg=0,st=ok:
      send: 1-1-0-0 s=2,c=0,t=1,pt=0,l=0,sg=0,st=ok:
      send: 1-1-0-0 s=0,c=0,t=16,pt=0,l=0,sg=0,st=ok:
      0
      send: 1-1-0-0 s=2,c=1,t=16,pt=0,l=1,sg=0,st=ok:0
      send: 1-1-0-0 s=1,c=1,t=0,pt=7,l=5,sg=0,st=ok:22.9
      Temp: 22.90
      send: 1-1-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:41.8
      Hum: 41.80
      send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,sg=0,st=ok:984
      lux: 984
      1
      send: 1-1-0-0 s=2,c=1,t=16,pt=0,l=1,sg=0,st=ok:1
      send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,sg=0,st=ok:977
      lux: 977
      0
      send: 1-1-0-0 s=2,c=1,t=16,pt=0,l=1,sg=0,st=ok:0
      send: 1-1-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:41.9
      Hum: 41.90
      send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,sg=0,st=ok:979
      lux: 979
      0
      send: 1-1-0-0 s=2,c=1,t=16,pt=0,l=1,sg=0,st=ok:0
      send: 1-1-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:41.8
      Hum: 41.80
      send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,sg=0,st=ok:978
      lux: 978
      0
      send: 1-1-0-0 s=2,c=1,t=16,pt=0,l=1,sg=0,st=ok:0
      send: 1-1-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:41.9
      Hum: 41.90
      send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,sg=0,st=ok:977
      lux: 977
      1
      send: 1-1-0-0 s=2,c=1,t=16,pt=0,l=1,sg=0,st=fail:1
      send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,sg=0,st=ok:660
      lux: 660
      0
      send: 1-1-0-0 s=2,c=1,t=16,pt=0,l=1,sg=0,st=ok:0
      send: 1-1-0-0 s=0,c=1,t=23,pt=3,l=2,sg=0,st=fail:593
      lux: 593
      1
      

      what is wrong?

      posted in Troubleshooting
      Remco van Geel
      Remco van Geel
    • Some Advice for my mysensor project please.

      my situation:

      I have a lot of questions and I need some advice to go futher. The questions are marked with a Q and number for easy replying.
      I have bought a few sensors, nano's and the esp07s are coming. Also soldering a voltmeter, wires, prototype boards, breadboard. (All bought thanks to mysensors 😛 )
      All the nano's and sensors I have tested with the example sketches and they are working stable in my domoticz.
      but I'm not sure of my ideas are possible and if this is the best way to accomplish my goals.
      My plan is to realise my project and update this on my topic. A little how to.

      cupboard:

      USB nano3 gateway with big antenna on my PI that is working fine.

      The gateway is 50 cm from my water meter and controller but a gateway can not ack as a sensor.
      Q1: is this true are there no options to have 1 device for multiple goals? a esp/mysensor gateway or something?
      That's a shame because I want to replace my working PI with Piface that is connected to:
      a pulse meter for water
      a switch to my buva remote controller

      =============================
      carport:

      I have a carport with an electric garagedoor.
      a few goals:
      1: control (up/down/stop)
      2: check (what is the current position?)
      3: parking sensor. So I know if I drive far enough so i can close the door.

      1: relay
      1 click on my remote is open another is stop and another is close.
      q2: I have an extra wireless remotecontroller, and a wired on and spare inputs on my Ecostar motor (hörnbach version of hormann)
      There are advantages to a certain way?
      Q3: - but when the door if fully opened it skips the stop function.
      Is this stable enough when it misses a switch or something?
      Q4: - when the sensor crashes of had no power the door must not change. I have metered the relay on my mysensors and when I power off the sensor it's always open.
      Q5: - Only the gateway must open the door. what kind of security is possible? so that not everyone with an NRF24L01+ something can open my door.

      2: distance meter1
      this measures where the door is in the rail. when distance is 250 the door is fully closed
      when lower then 250 for example 150 the door is opened a meter.

      3: distance meter2
      continue measurement when door status changed to open.
      (then I drive inside, so It must be measuring and controlling the led for a minute)
      when distance is less then 100cm the red LED is ON
      4: led
      I don't need this information sended to my gateway.

      Q6: is this possible on 1 nano 3? or can I better choose for esp07 ?
      Q7: wireless in my carport is very poor, But I don't know if NRF24L01+ is better. but they can repeat.
      Q8: Would the combination of the different sketches to big and complex for the nano?

      extra info and examples for myself.
      http://www.mysensors.org/build/parking
      http://www.mysensors.org/build/distance
      http://forum.mysensors.org/topic/1200/garage-door-controller-checker
      http://www.mysensors.org/build/relay

      =============================
      attic already working fine.
      temp-hum and motion sensor.

      only thing to do is (low prio):
      power usage from washing wasmachine
      and temperature of water to the douche from boiler.
      enable repeater mode
      and update mysensor version

      posted in My Project
      Remco van Geel
      Remco van Geel