Navigation

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

    Best posts made by TheoL

    • Gesture controlled Floor Lamp

      After playing around with my first Arduino, a couple of years ago, I knew I wanted to use it to create a Gesture controlled Japanese Floor lamp. Like one on this picture.
      alt text

      At the time I knew little to nothing about how to design the schematics or how I'd would be able to hook that lamp in to a Home Automation system. Hence I didn't even know what a Home Automation was at the time. Well luckily thanx to MySensors I don't need to know it. I just have to hookup an antenna, and add the correct code into my sketch.

      So that problem was tackled. I think it was about a year ago, that I came across this little gesture sensor. It's sparkfun's APDS-9960. It's a rather expensive sensor used in the Samsung galaxy S5. Now I know that there are cheaper alternatives, but at the time I bought one and it ended up in one of my desk drawers.

      Since I can't do my woodworking during winters, I design the electronics I use in my woodworking projects in the winter. And embed them in my woodworking projects when the temperature is high enough. When I begin thinking about the woodworking projects I want to build this woodworking season, I remembered the little gesture sensor.

      So much for the intro. But if you're still reading, you're probably interested in the real deal. I had a hard time using the APDS-9960. So it took me a lot of hours the get it to work. But I'll share my workarounds with you. The MySensors community has done a lot for me, so I think it's about time to do something back.

      I started with adjusting the cheap white strip I specially bought for this project. It contained a 5 meter white LED strip, a power adapter and some reusable parts.

      alt text

      The tine plastic housing can easily be opened with a small screw driver.

      alt text

      And now I have acces to some goodies (IR receiver - allways useful, the power plug I'll be using in the final product, and a connector for connecting the LED strip ;-))

      alt text

      It took a just a couple of minutes to desolder all the parts.
      alt text

      And the complete circuit looks like this on my breadboard (small note the 7805CV is not mounted on this picture. I'm using two power adapters during development. One 5V for powering the Arduino circuit and one 12V for powering the LED strip).

      alt text

      Since most project descriptions don't go in much details about the schematics, some of them are just out of my league. That's why I decided to add everything in this post. This project was really complex for me, because the circuit uses 12V, 5V and 3.3V. But besides for the part that I don't think that I use the right capacitors (it works though) the completed circuit looks like this.

      Circuit

      There are a couple of things I want to point out. According to Sparkfun the Pro Mini 3.3V can be fed with 12V. But I blew up my raw pin during the design that's why I added the 7805CV power regulator. I'm using a Wite LED strip, which came with a 12V 1500 milli amp power adapter. At the moment I'm able to use that adapter for feeding both the Arduino circuit and the LED strip. But the adapter gets warm. For me that's okay. I'll be using one meter of the 5 meter led strip at the most. So I'm pretty confident that the original power adapter will provide enough amperage for the complete circuit.

      I've measured the usage of the arduino circuit and it uses about 380 milli amps. Which is stable until the circuit communicates with the gateway - sending new brightness level to the gateway. At that point the circuits absorbs about above 500 milli amp. Again measured without the LED strip consumption.

      I use an N channel Mosfet for controlling the LED strip. That is necessary because LED strips share a common anode. This regarding to most RGB Led's that share a common cathode. (But I'm not an electronics specialist so correct me if I'm wrong.)

      Here's the shopping list:
      Amount Part Type
      1 Electrolytic Capacitor 35V; 4.7µF;
      4 Electrolytic Capacitor 50V; 10µF;
      1 12V White LED strip with power Adapter ( you can use an RGB led strip, but you'll be needing 2 extra MOSFETS in that case)
      1 NRF24L01+
      1 Pro Mini 3.3V (You can use Pro Mini 5V, but you'll have to use a logical level converter, the APDS can only handle 3.3V)
      1 APDS-9960 RGB (you can use the cheaper APSD-9930 you can find on e-bay, but you'll need an altered library!)
      1 Power plug (I salvaged mine from the, from the LED strip package I bought)
      1 IRL B8721 N-channel mosfet (when using a short piece of led strip, a 2N2222 might do. But I had this one lying around and it's able to control high amperage (6 Amp if I'm not mistaken)
      1 LD33 Low-Dropout Voltage Regulator
      1 7805CV Voltage Regulator - 5V (other types of 7805 might do, but I have this ones on spare)

      For the Sketch you'll be needing the Spark fun APDS-9960 library. It can be downloaded here. It's not the best library I've ever used though. But I couldn't find another one.

      After you've hooked up all the electronics the real fun starts (we'll actually it doesn't, playing with the final project is even more fun). One note. The original author of Spark fun, probably had a less sensitive sensor than the one I have. After a long search I've found the solution to get my sensor the work which is:

          apds.setGestureGain( 1 );
      

      You might need to change that value to your sensor. Valid values can be found in the library, but for convenience they are in the range of 0-3. 0 is very sensitive and 3 is less sensitive.

      The lamp can be controlled from your Home Automation system, as well with gestures. The gestures are:

      • Left swipe turns the lamp off
      • Right swipe turns the lamp on
      • Up swipe raises brightness. If the brightness is already at the max it will indicate this by turning the lamp of for a short moment and back on again.
      • Down swipe lowers the brightness. If the brightness can't be lowered it'll turn the lamp off.

      You can use the gesture sensor in a stand alone sketch as well. After playing with the gesture controlled Lamp I've discovered some use cases in which a gesture controlled lamp or switch is really handy:

      1. Controlling lights under kitchen cabinets. When preparing a meal it's not hygienic to turn on/off a normal switch. With a gesture controlled switch you don't have to touch the switch.
      2. Mount one in your workshop. When working on your car or motor cycle, it'll be certain that you get grease or oil on your hands. When needing light you don't have to touch the switch just use a gesture and you can turn on or off your lighting. That way you don't have to clean the switch after you're done working on your car or whatever it is you are working on.

      If you've reached this point. My appologies for this long post. Thank you that you've found it worth reading. I'll post a follow up after the Japanse Lamp is finished - incl. the mounting of the electronics.

      Here's the Sketch.

      /****************************************************************
        Gesture controlled lamp
        MySensors enabled, gesture controlled lamp.
        
        March 2016 by Theo
        
        This lamp can be turned on/off, and dimmed by gestures. And it can be controlled by any Home Automation
        system, that can talk with MySensors.
        
        The gesture sensor used in this Sketch is an APDS-9960 RGB and Gesture Sensor, sold by SparkFun.
      
        This Sketch is based upon the GestureTest exampl developped by,
        Shawn Hymel @ SparkFun Electronics on May 30, 2014. See https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor
      
        Hardware Connections (APDS-9960):
        IMPORTANT: The APDS-9960 can only accept 3.3V!
       
         Arduino Pin  APDS-9960 Board  Function
       
         3.3V         VCC              Power
         GND          GND              Ground
         A4           SDA              I2C Data
         A5           SCL              I2C Clock
         2            INT              Interrupt
      
        The lamp itself is a white LED strip, controlled by an N channel MOSFET.
      ****************************************************************/
      #include <SPI.h>
      #include <MySensor.h>  
      #include <Wire.h>
      #include <SparkFun_APDS9960.h>
      
      // Pins
      #define APDS9960_INT                      2   // Needs to be an interrupt pin
      #define LED_PIN                           3   // The led PWM pin, that drives the LED strip
      #define MAXDIMLEVELS                     100  // The maximum number of dim levels
      #define BRIGHTNESS_INCREMENT             15   // Dimmer increment for gesture(s)
      #define MAX_LEVEL_REACHED_DELAY          150  // Short blinking delay when increasing the dimmer while the dimmer is already at max
      #define MAX_LEVEL_REACHED_SIGNAL_COUNT   1    // The amount of blinks, when the max dim level already has been reached
      #define CHILD_ID_LIGHT                   1    // The child id of the Node. Only one Node on this sensor though.
      #define LIGHT_OFF                        0    // Constant indicating the lamp on state
      #define LIGHT_ON                         1    // cConstant indicationg light off state
      #define SN "Gesture controlled lamp" // Description of this sketch. 
      #define SV                               "1.1" // The version of the Sketch
      
      
      // Global Variables
      SparkFun_APDS9960 apds = SparkFun_APDS9960();
      int isr_flag = 0;                // interrupt flag, triggered when a gesture has been dectected
      
      int LastLightState=LIGHT_OFF;
      int LastDimValue=100;
      
      int dimlevels[ MAXDIMLEVELS ] =  // PWM values used for translating home automation dimmer levels. This gives smoother transations
        {   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
           10,  11,  12,  13,  14,  15,  16,  17,  18,  19,
           20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
           30,  31,  32,  35,  39,  42,  46,  49,  52,  56,
           59,  62,  66,  69,  73,  76,  79,  83,  86,  89,
           93,  96, 100, 103, 106, 110, 113, 116, 120, 123,
          126, 130, 133, 137, 140, 144, 147, 150, 154, 157,
          160, 164, 167, 171, 174, 177, 181, 184, 187, 191,
          194, 197, 201, 204, 208, 211, 215, 218, 221, 225,
          228, 231, 235, 238, 242, 245, 246, 250, 251, 255 };
      
      MySensor gw;
      MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT);
      MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
      
      void setup() {
        gw.begin(incomingMessage, AUTO, false);
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo(SN, SV);
      
        gw.present(CHILD_ID_LIGHT, S_DIMMER, "floor lamp", true );
        
        // declare output pin for PWM control of the MOSFET
        pinMode( LED_PIN, OUTPUT );
        
        // Set interrupt pin as input
        pinMode(APDS9960_INT, INPUT);
        
        // Initialize interrupt service routine
        attachInterrupt(0, interruptRoutine, FALLING);
      
        // Initialize APDS-9960 (configure I2C and initial values)
        if ( apds.init() ) {
          // original value is two. But it looks like the modern gesture sensor or more sensitive. 1 does it for me
          apds.setGestureGain( 1 );
        }
        
        // Start running the APDS-9960 gesture sensor engine
        if ( apds.enableGestureSensor(true) ) {
          LastLightState=LIGHT_OFF;
          LastDimValue=0;
          analogWrite( LED_PIN, 0 );
          gw.request( CHILD_ID_LIGHT, V_PERCENTAGE );
          gw.request( CHILD_ID_LIGHT, V_STATUS );
        }
        //Here you actualy switch on/off the light with the last known dim level
      }
      
      // The Sketh's main loop
      void loop() {
        if( isr_flag == 1 ) {
          detachInterrupt(0);
          handleGesture();
          isr_flag = 0;
          attachInterrupt(0, interruptRoutine, FALLING);
        }
        gw.process();
      }
      
      // interrupt handler. Is being traggerd by the gesture sensor whenever a gesture has been detected.
      void interruptRoutine() {
        isr_flag = 1;
      }
      
      // Determine gesture and handle accordingly.
      void handleGesture() {
        if ( apds.isGestureAvailable() ) {
          switch ( apds.readGesture() ) {
            case DIR_UP:
              if ( LastDimValue + BRIGHTNESS_INCREMENT > ( MAXDIMLEVELS - 1 ) ) {
                for ( int i = 0; i < MAX_LEVEL_REACHED_SIGNAL_COUNT; i++ ) {
                  analogWrite( LED_PIN, dimlevels[ 0 ] );
                  gw.wait( MAX_LEVEL_REACHED_DELAY );
                  analogWrite( LED_PIN, dimlevels[ MAXDIMLEVELS - 1 ] );
                  gw.wait(MAX_LEVEL_REACHED_DELAY );
                }
                LastDimValue = ( MAXDIMLEVELS - 1 );
              }
              else {
                 LastDimValue += BRIGHTNESS_INCREMENT;
              }
              LastLightState = LIGHT_ON;
              SetCurrentState2Hardware();
              break;
            case DIR_DOWN:
              if ( LastDimValue - BRIGHTNESS_INCREMENT <= 0 ) {
                LastDimValue = 0;
              }
              else {
                 LastDimValue -= BRIGHTNESS_INCREMENT;
              }
              if ( LastDimValue == 0 ) {
                LastLightState = LIGHT_OFF;
              }
              else {
                LastLightState = LIGHT_ON;
              }
              SetCurrentState2Hardware();
              break;
            case DIR_LEFT:
              LastLightState = LIGHT_OFF;
              SetCurrentState2Hardware();
              break;
            case DIR_RIGHT:
              LastLightState = LIGHT_ON;
              SetCurrentState2Hardware();
              break;
          }
        }
      }
      
      void incomingMessage(const MyMessage &message) {
        if (message.type == V_LIGHT) {
          int lstate= atoi( message.data );
          if ((lstate<0)||(lstate>1)) {
            return;
          }
          LastLightState=lstate;
          if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) {
             //In the case that the Light State = On, but the dimmer value is zero,
             //then something (probably the controller) did something wrong,
             //for the Dim value to 100%
            LastDimValue=100;
          }
          
          //When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value
          //This means if you previously set the lights dimmer value to 50%, and turn the light ON
          //it will do so at 50%
        }
        else if (message.type == V_DIMMER) {
          int dimvalue= atoi( message.data );
          if ((dimvalue<0)||(dimvalue>100)) {
            return;
          }
          if (dimvalue==0) {
            LastLightState=LIGHT_OFF;
          }
          else {
            LastLightState=LIGHT_ON;
            LastDimValue=dimvalue;
          }
        }
      
        //Here you set the actual light state/level
        SetCurrentState2Hardware();
      }
      
      void SetCurrentState2Hardware() {
        if (LastLightState==LIGHT_OFF) {
           analogWrite( LED_PIN, dimlevels[0] );
        }
        else {
           analogWrite( LED_PIN, dimlevels[ LastDimValue - 1 ] );
        }
      
        //Send current state to the controller
        SendCurrentState2Controller();
      }
      
      void SendCurrentState2Controller()
      {
        if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
          gw.send(dimmerMsg.set(0));
        }
        else {
          gw.send(dimmerMsg.set(LastDimValue));
        }
      }
      
      posted in My Project
      TheoL
      TheoL
    • Free MySensors 2.0 workshop, Friday 9 September in Amersfoort (The Netherlands)

      I’m organizing an entry-level MySensors 2.0 workshop/ master class for those who would like to kick-start in creating MySensors 2.0 based nodes and have little experience in electronics. The workshop will be held on Friday the 9th of September as a side track during Trivento’s annual Summercamp. The theme of this year’s Summercamp is Fast Data and let’s be honest: What is Fast Data without IoT?

      During this 3 hour workshop/ master class you’ll learn:

      • How the MySensors eco-system works and which role a gateway plays in the eco-system.
      • How to connect simple electronic components to an Arduino
      • The difference between AC and DC and why this is important when you connect electronics that have a polarity. (This is just enough to give you a kick-start, because we can not go deeply into electronics during a 3 hour workshop).
      • The anatomy of a sketch for a MySensors node.
      • How to create some simple MySensors nodes (temperature sensor/ light sensor/ RGB light).
      • How you can combine multiple sensors into one node. We’ll be making a temperature/ light level node.
      • Get an overview of the different gateways that are supported by MySensors.
      • How you can secure your nodes by adding signing (and why everyone should do that).

      In order for you to be able to participate you need have some basic knowledge of writing software. Because we unfortunately don't have time during this event to learn you how to write your software.

      If you don't live in the Netherlands, but just happen to be in the neighborhood. The language for the Summercamp and workshop is all English and we're happy to welcome you.

      So if you want to learn about MySensors, want to have some fun and maybe drink a beer after the workshop please don’t hesitate to register for this fun event. This is a BYOL event, which means that you’ll bring your laptop and I’ll provide the Arduinos and the other electronic components you’ll need.

      There’s no fee for participating in this workshop. However, there is a limited number of places available, so please register as soon as possible if you want to participate.

      Finally, the keynote for the Summercamp is also worth mentioning. This will be ‘Challenges and opportunities around elastic data pipelines’ by Jorg Schad, (Distributed Systems Engineer at Mesosphere, Inc.).

      posted in General Discussion
      TheoL
      TheoL
    • MySensorfying a cheap moodlight

      It might be just me, but since I discovered my Sensors, I look at the world differently. I want to put MySensors in everything. So last week I came across some cheap mood-lights in a shop. They're 3 euro's a piece. Before I bought them I checked if they can be opened easy and that was the case.

      The mood-light is a 3 AAA powered diffused 5mm LED with one resistor. The diffused LED only has to pens and in it is an IC that loops through a mood-light program. But I couldn't use the LED, because in the future I want to control the mood-light as an RGB lamp as well. So I stripped the electronics out of the mood-light to see if there's enough space to put in a Arduino Pro Mini 3.3V and a Antenna. It looked like it would fit.

      I ordered a couple Pro Mini 3.3V and ordered a couple of diffused 5mm RGB leds. I put everything on a breadboard and developed a sketch.
      image1.JPG

      I had a hard time finding a good Mood-light example. Most of the examples on instructables.com didn't have a smooth transition between the different colors. But luckily I found a good library called MoodLight by Kasper Kamperman. You can download the library from his blog http://www.kasperkamperman.com/blog/arduino-moodlight-library/

      The first version implements only a Mood-light. I tried to add the S_RGB but my Domoticz version doesn't support it. So I will put that in the sketch as well. I plan to use that light as a mood-light, but also as warning lamp. E.g. if someone is comming to my front door it will show a green color.

      /**
       * MySensors Moodlight
       * Version 1.0
       * created September 22nd 2015
       * by Theo
       *
       * Change log:
       * 27-09-2015 Stable version released after a couple days of testing.
       * 
       * Description:
       *   Sketch for creating a cheap MySensors controlled MoodLight which also can be controlled as an dimmable RGB light.
       *
       * Future plans:
       * - enable it as an RGB lamp as well. Have to wait until Domoticz supports it. Which will probably be in the next stable version.
       *
       * Dependencies:
       *   MoodLight.h
       *
       * Hardware used:
       *   Arduino Pro Mini 3.3V
       *   Difused 5mm RGB led
       *   LR2401 Antenna
       *   one 4.7Uf capacitor
       *   three 220 Ohm resistors, to prevent the RGB led from burning out, but might be lower because we're feeding it only 3.3V instead of 5V
       *   A really cheap 3 AAA battery powered moodLight (found it in a store for around 3 euros)
       * 
       * Total costs without the regulator circuit (also adapter not included, used an old phone power adapter)
       *   Arduino 6.00 euro
       *   RGB led 0.60 euro
       *   antenna 2.00 euro
       *   4.7 uF  0.30 euro
       *   resistors 0.00 euro had them laying around doing nothing
       *   moodlight housing 3.00 euro
       *   wires and solder etc. 0.00 euro had that laying around ass well
       *   
       * Sums up to 11.90 euro add 2 euro to it for wires etc and it's still below 15 euro. Nice!!! ;-)
       */
      
      /**
       * Include libraries.
       */
      #include <MoodLight.h>  // great library for moodlight implementations.
      #include <SPI.h>        // needed for the Antenna
      #include <MySensor.h>   // include the real magic.
       
      /**
       * declare Pins used by the sketch. Use #define because that the compiler will replace it so it saves a bit of memory
       */
      #define REDPIN 3              // pwm pin with red led (Only use a PWM that is not being occupied by the antenna)
      #define GREENPIN 5            // pwm pin with green led (Only use a PWM that is not being occupied by the antenna)
      #define BLUEPIN 6             // pwm pin with blue led (Only use a PWM that is not being occupied by the antenna)
      #define MOODLIGHTDELAY 175    // the amount of time a particular moodlight value is being shown before the next one will be shown
      #define SATURATION 255        // use value between 0 - 255 <--- This is a candidate to remove
      #define BRIGHTNESS 255        // use value between 0 - 255 <--- This is a candidate to remove
      #define MLHUEUPPERLEVEL 359   // The higher bound of the ml's hue factor
      #define SN "Moodlight"        // Define the Sketch's name
      #define SV "1.0"              // Define the sketch's version 
      #define CHILD_ID_MOODLIGHT 0  // Define the child ID of the moodlight
      
      /**
       * Declare new data types, enum etc
       */
      // Light program modes
      enum LIGHTMODE {
        LIGHTOFF = 0,
        MOODLIGHT = 1,
        RGBVALUE = 2   // reserved for future useage
      };
      
      /**
       * Declare global variables (haven't looked into what saturation and brightness will do for the moodlight)
       */
      int hue = 0; // use value between 0 - 359
      MoodLight ml = MoodLight(); // create MoodLight object
      int currentLightMode = LIGHTOFF;
      long RGB_values[3] = {0,0,0};
      
      MySensor gw;
      MyMessage lightMsg( CHILD_ID_MOODLIGHT, V_LIGHT);
      
      /**
       * Initialize Sketch. Declare pins and MySensors etc.
       */
      void setup() {
        // Serial.begin( 115200 );
        // Setup PWM pins for output
        pinMode( REDPIN, OUTPUT );
        pinMode( GREENPIN, OUTPUT );  
        pinMode( BLUEPIN, OUTPUT ); 
      
         // initialize ml for first time display.
         ml.setHSB(hue, SATURATION , BRIGHTNESS );
       
        // Initialize mySensor gateway
        gw.begin( incomingMessage );
        gw.sendSketchInfo(SN, SV);  
      
        // Register the LED Dimmable Light with the gateway
        gw.present( CHILD_ID_MOODLIGHT, S_LIGHT );
        // It just me being neurotic, but inform controller that power level is 100%
        gw.sendBatteryLevel( 100 );
      
        // Request the current Moodlight status from the controller.
        gw.request( CHILD_ID_MOODLIGHT, V_LIGHT );
      }
      
      /*
       * Calculate red, green, blue values based upon current hue, saturation and brightness.
       * Display the new values and adjust the hue to the next step.
       */
      void setAndShowNextMoodlightValue() {
        // assign current values to the ml object
        ml.setHSB( hue, SATURATION, BRIGHTNESS );
      
        // read the Red, Green and Blue values and assign them to the led pins
        analogWrite( REDPIN, ml.getRed() );
        analogWrite( GREENPIN, ml.getGreen() );
        analogWrite( BLUEPIN, ml.getBlue() );
        
        hue++; // set the next moodlight step
        if ( hue > MLHUEUPPERLEVEL ) { // adjust if we've reached the upperlevel
          hue = 0;
        } 
      }
      
      /**
       * Main loop of the Sketch
       */
      void loop() {
        if ( currentLightMode == MOODLIGHT ) {
          setAndShowNextMoodlightValue();
        }
        gw.wait( MOODLIGHTDELAY ); 
      }
      
      /**
       * Callback function for handling messages received from the gateway.
       */
      void incomingMessage(const MyMessage &message) {
        if ( message.sensor == CHILD_ID_MOODLIGHT && message.type == V_LIGHT ) { // received a Light Status from the gateway
          currentLightMode = message.getBool() == 1 ? MOODLIGHT : LIGHTOFF;
          // adjust the RGB led to the (new) light state
          if ( currentLightMode == MOODLIGHT ) { 
            analogWrite( REDPIN, ml.getRed() );
            analogWrite( GREENPIN, ml.getGreen() );
            analogWrite( BLUEPIN, ml.getBlue() );
          }
          else {
            analogWrite( REDPIN, 0 );
            analogWrite( GREENPIN, 0 );
            analogWrite( BLUEPIN, 0 );
          }    
        }
      }
      

      So after playing with the mood-light on the breadboard for a couple of days. Just to see if it's stable. I finally found some time to solder the Arduino and the Antenna and mount everything in the mood-light.

      I cut some dupont cables in half and soldered them directly on the proMini. I was lucky that I had the same colors as used in the connecting the radio article on the mysensor build site. So it'll be very easy to replace the radio when needed. There's also a 4,7 uf cap that I stuck directly in the VCC and ground pins of the dupont cables.

      It was really hard to mount the electronics in the light, because you have all most no working space. But I managed to do it.
      image2.JPG

      Also I soldered the 220 ohm resistors directly on the ProMini and soldered the LED wires to the resistor. I used double sided carpenters tape to stick the arduino on the lamp. Double sided tape is really strong. I use it to put my templates on wood, if I want to route a pattern in the wood. Believe me it's strong.

      So here are some photo's of the mood-light in action.
      image3.JPG

      image4.JPG

      Sorry I wasn't able to rotate the photo's. The circuit is really easy. I power the NRF24L01 directly from the ProMini 3.3V. Each pin that is connected to the RGB led, connects through a 220Ohm resistor. I used pins 3, 5 and 6 to control the LED, because they're PWM pins.

      I'll have to learn Fritzing. I've been playing with it, but I couldn't find the NRF24L01 component.

      posted in My Project
      TheoL
      TheoL
    • Library for thresholded readings of sensors

      Since this is not really a hardware project, Ive decided to post this just on the forum.

      I bought the Sense Bender a couple of months ago. I'm not only happy with the Sense Bender itself, but also by the example Sketch. It changed the way I'm thinking about sending sensor values to the gateway. There's absolutely no need to send the values immediately when the change. I really love the threshold way of sending values.

      For those of you who don't know the Sense Bender sketch. It sends the temp and humidity values only every 5 minutes or if their values have changed a threshold value after the last value send. To simplify things for my self and to be able to reuse it, I've created a library for this. It really makes the sketch part easy. You just register the sensors, add some callback functions, call the check threshold method in the loop and the library will:

      • ask for a sensor's value when it needs it;
      • tell you when you need to send a value to the library.

      Here's the sketch I've created today. It combines a Si7021 Temp + humidity sensor, a BMP180 pressure sensor and a cheap photo diode LM393 light level sensor. And only reports their values by using the ThresholdUtil library. It makes creating thresholded sensor nodes so easy, that I'm happy to share it with everyone.

      Note: I'm testing this library right now. It looks bug free. So I've released it as a buy me a beer if you happen to meet me and like this library. Or throw it away if you don't like it.

      /**
         Room conditions node. Measure temperature, humidity, lightlevel and pressure.
      
         Copyright (c) ByTheo
      
         Description:
         This Node demonstrates the useage of the ThresholdUtil library, by combining a temperature, humidity, lightlevel and barometric sensors
         It also utilizes the Forecast algorithm from the MySensors build page, which for this purpose has been put in a separate library
      
         Developped on a ProMini 3.3V. Sensors used:
         - BMP180 Pressure sensor (can also read temperature but not used by this Node)
         - SI7021 Humidity and temperature sensor
         - Photo Diode LM393 sensor (bought an Aliexpress
      
         History
           August 20th 2016 - Initial version
      
         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.
      
       *******************************
      */
      
      #include <SPI.h>
      #include <MySensor.h>
      #include <Wire.h>
      #include <SI7021.h>
      #include <Adafruit_BMP085.h>
      #include "ThresholdUtil.h"
      #include "WeatherForecast.h"
      
      // Uncomment when debugging
      // #define RC_DEBUG
      
      // Define Arduino Pins used by sensors A4 and A5 are also used for i2c bus
      #define LIGHT_SENSOR_ANALOG_PIN A0
      #define LIGHT_SENSOR_DIGITAL_PIN 3
      
      // The altitude of the location where the sensor is being placed. Adjust to your location
      #define ALTITUDE 33.0
      
      // Define constants for children used by Node
      #define TEMPEARTURE_SENSOR_CHILD_ID  0
      #define HUMIDITY_SENSOR_CHILD_ID     1
      #define LIGHTLEVEL_SENSOR_CHILD_ID   2
      #define PRESSURE_SENSOR_CHILD_ID     3
      
      // Declare Sensor ID's used for ThresholdUtil library
      #define TEMPEARTURE_SENSOR_ID 1
      #define HUMIDITY_SENSOR_ID    2
      #define LIGHTLEVEL_SENSOR_ID  3
      #define PRESSURE_SENSOR_ID    4
      
      // Declare Sketch Name and Version
      #define MYS_SKETCH_NAME "Improved room conditions"
      #define MYS_SKETCH_VERSION "1.0"
      
      // Variabe used for remembering lastForeCast send to the gateway
      int lastForecast = -1;
      
      // Create objecs for i2c sensors
      Adafruit_BMP085 bmp = Adafruit_BMP085();
      SI7021 sensor;
      
      // Declare MySensors class and messages
      MySensor gw;
      MyMessage tempMsg( TEMPEARTURE_SENSOR_CHILD_ID, V_TEMP );
      MyMessage pressureMsg( PRESSURE_SENSOR_CHILD_ID, V_PRESSURE);
      MyMessage forecastMsg( PRESSURE_SENSOR_CHILD_ID, V_FORECAST);
      MyMessage msgHum(HUMIDITY_SENSOR_CHILD_ID, V_HUM);
      MyMessage lightLevelMsg(LIGHTLEVEL_SENSOR_CHILD_ID, V_LIGHT_LEVEL);
      
      /**
       * Setup method. This will initialize the i2c sensors, register Thresholds. Initializes MySensors and presents the children of the node. Finally the initial values are being send
       * to the gateway
       */
      void setup() {
      #ifdef RC_DEBUG
        Serial.begin( 115200 );
      #endif
        // initialize I2C sensors
        sensor.begin();
        bmp.begin();
      
        // register sensors and their thresholds
        registerThresholdedSensor( TEMPEARTURE_SENSOR_CHILD_ID, TEMPEARTURE_SENSOR_ID, TEMPERATURE_SENSOR, 0.5,  5, 60  ); // read every 5 sec and report at least every 5 minute
        registerThresholdedSensor( HUMIDITY_SENSOR_CHILD_ID,    HUMIDITY_SENSOR_ID,    HUMIDTY_SENSOR,     1.0, 10, 30  ); // read every 5 sec and report at least every 5 minute
        registerThresholdedSensor( LIGHTLEVEL_SENSOR_CHILD_ID,  LIGHTLEVEL_SENSOR_ID,  LIGHTLEVEL_SENSOR,  2.0,  1, 300 ); // read every 5 sec and report at least every 5 minute
        registerThresholdedSensor( PRESSURE_SENSOR_CHILD_ID,    PRESSURE_SENSOR_ID,    PRESSURE_SENSOR,    0.5, 60, 10  ); // every minute. report at least every 10. Forecast algorithm wants new value every minute
      
        // Register the node to the gateway
        gw.begin();
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo( MYS_SKETCH_NAME, MYS_SKETCH_VERSION );
        gw.wait( 50 ); // give radio the time to register the child
      
        gw.sendBatteryLevel( 100, true );
        gw.wait( 50 ); // give radio the time to register the child
      
        // Register sensors to gw (they will be created as child devices)
        gw.present( PRESSURE_SENSOR_CHILD_ID, S_BARO, "Barometer", true );
        gw.wait( 50 ); // give radio the time to register the child
        gw.present( TEMPEARTURE_SENSOR_CHILD_ID, S_TEMP, "Temperature", true );
        gw.wait( 50 ); // give radio the time to register the child
        gw.present( HUMIDITY_SENSOR_CHILD_ID, S_HUM, "Humidity", true );
        gw.wait( 50 ); // give radio the time to register the child
        gw.present( LIGHTLEVEL_SENSOR_CHILD_ID, S_LIGHT_LEVEL, "Light level", true );
        gw.wait( 50 ); // give radio the time to register the child
      
        checkThresholdedSensors( readSensorValue, reportSensorValue ); // Send initial values to the gateway
      }
      
      /*
       * Call back method for ThresholdUtil library, will ask for sensor values when the library needs them
       * 
       * ps. don't forget to put a * in front of the value inside the method. The library will not receive any
       * values if you forget the *
       */
      void readSensorValue( uint8_t aSensorId, ThreshHoldedSensorType aType, float *value ) {
        switch ( aSensorId ) {
          case TEMPEARTURE_SENSOR_ID:
            if ( aType == TEMPERATURE_SENSOR ) {
              *value = sensor.getCelsiusHundredths() / 100.0;
            }
            break;
          case HUMIDITY_SENSOR_ID:
            if ( aType == HUMIDTY_SENSOR ) {
              *value = sensor.getHumidityPercent() * 1.0;
            }
            break;
          case LIGHTLEVEL_SENSOR_ID:
            if ( aType == LIGHTLEVEL_SENSOR ) {
              *value = (float)( 1023 - analogRead( LIGHT_SENSOR_ANALOG_PIN ) ) / 10.23;
            }
            break;
          case PRESSURE_SENSOR_ID:
            if ( aType == PRESSURE_SENSOR ) {
              float pressure = bmp.readSealevelPressure( ALTITUDE ) / 100.0;
              *value = pressure;
              int forecast = sample( pressure );
              if (forecast != lastForecast) {
                gw.send( forecastMsg.set( weather[ forecast ] ), true );
                gw.wait( 50 );
                lastForecast = forecast;
      #ifdef RC_DEBUG
                Serial.print( "New forecast " ); Serial.println( forecast );
      #endif
              }
            }
            break;
        }
      }
      
      /**
       * Call back function being called by the thresholdUtil library whenever a threshold or forced transmit has been detected
       */
      void reportSensorValue( uint8_t child_id, uint8_t sensor_id, ThreshHoldedSensorType sensor_type, float value ) {
        switch ( child_id ) {
          case TEMPEARTURE_SENSOR_CHILD_ID:
      #ifdef RC_DEBUG
            Serial.print( "Temperature " ); Serial.print( value, 1 ); Serial.println( "C" );
      #endif
            gw.send(tempMsg.set(value, 1), true ); // Send temperature with 1 decimal precision
            break;
          case HUMIDITY_SENSOR_CHILD_ID:
      #ifdef RC_DEBUG
            Serial.print( "Humidity " ); Serial.print( value, 0 ); Serial.println( "%" );
      #endif
            gw.send(msgHum.set( value, 1 ), true ); // Send temperature with 1 decimal precision
            break;
          case LIGHTLEVEL_SENSOR_CHILD_ID:
      #ifdef RC_DEBUG
            Serial.print( "Light level " ); Serial.print( value, 0 ); Serial.println( "%" );
      #endif
            gw.send( lightLevelMsg.set( value, 0 ), true );
            break;
          case PRESSURE_SENSOR_CHILD_ID:
      #ifdef RC_DEBUG
            Serial.print( "Pressure " ); Serial.print( value, 1 ); Serial.println( " hPa" );
      #endif
            gw.send( pressureMsg.set( value, 0 ), true );
            break;
        }
        gw.wait( 50 );
      }
      
      /**
       * loop method. Basically we only call the checkTresholdedSensor method of the ThresholdUtil library
       */
      void loop() {
        checkThresholdedSensors( readSensorValue, reportSensorValue );
        gw.wait( 50 );
      }
      

      Here is the fritzing. I forgot the lightlevel sensor, but you can find how to wire it on the MySensors main page. For stability I power nothing from the Arduino. I use a Pro Mini 3.3V which I power with 5V from an adapter. I've used a cheap aliexpress buck converter and set it to 3.3V. That's my 3.3V power for the sensors and the radio.

      Fritzing

      Library and examples can be downloaded from my github ThresholdUtil.h For the code above you'll also need the WeatherForecast.h libraty, which is just the forecast algorithm from the MySensors build page that I've refactored to a separate .h file.

      posted in My Project
      TheoL
      TheoL
    • RE: 💬 Sensebender Gateway

      It's has been a long time since I've posted on this forum.Today I received a note form the postal service that a package from a foreign country has arrived at my local postal office. Can't wait until tomorrow, just to see this beauty.

      Now I have to find some time to get it running ;-(

      posted in OpenHardware.io
      TheoL
      TheoL
    • RE: Sensebender Micro

      I just received two sensebenders. I'm really impressed by the great engineering behind the board. I can't wait to heat up my soldering iron. I love them!

      posted in Announcements
      TheoL
      TheoL
    • RE: Multimeter recommendation?

      I volunteered to teach some of my colleagues how to create projects with an Arduino. The final lesson will be creating MySensors based projects. At the moment there are 20 people who assigned for my course. If only the half of them wants to continue creating MySensors and other cool projects, I have a group of people that'll br big enough to order things with discount. That's why I follow topics like this with much interest.

      posted in General Discussion
      TheoL
      TheoL
    • Reinventing the motion controlled outside lamp

      The former owners of my house installed a PIR sensors on my front door and the PIR motion controller is connected directlty to a lamp that's mounted next to my frontdoor. The thing that always bugged me, is that it turns on the light for the amount of minutes that it's set for. That causes the lamp to burn longer then necessary most of time, or that I have to wave my hand in front of the sensor whenever I'm talking to someone while standing in front of my door.

      This weekend I designed a new node that I'll be using instead of the current PIR motion sensor. I'm still thinking about how I can mount the PIR sensor in a waterproof housing. But the sensor works as follows:

      1. It will keep the light on for 20 seconds after the last movement has been detected. The PIR sensor has been set to smallest movement detection time, which is about 2 seconds. This knowledge is programmed into the sensor, because there was always a short amount of delay between motion detection and turning on the relay. This is an improvement on how a motion sensor normally functions. Which is an amount of time after the first motion detection I've tested it and the light is on when I need it and off when I don't need it.
      2. Whether the relay that's controlling the light has to be turned on when motion is detected, will be controlled by Domoticz. I have a different use case for this kind of sensor where I want to able to turn on the relay on only when I'm a sleep or not at home. A kind of surveillance light.
      3. A doorsensor - since I have enough pins and memory left, I might as well monitor when the door is opened and closed
      4. A DS18b20 sensor. This is also for future useage. For now I just measure the outside temperature. But I've not included this temp sensor in Domoticz.
      5. Each movement is reported to the Domotica controller.

      I'll add a Fritzing schema in a couple of days. I'm learning a lot about Fritzling lately. Here is how it looks on a PCB (not the best quality PCB). All used pin's can be looked up in the Sketch for now.

      Bewegingmelder_608.JPG

      Parts used:

      • Arduino Nano I power the relay and the PIR directly from the Nano's 5V output;
      • A NRF24L01+ radio powered directly from the 3.3v output of the nano
      • 4,7 uf capacitor for stabilizing the radio
      • PIR motion sensor
      • relay board
      • DS18B20 temperature sensor with a 4K7 Ohm resistor over VCC and data pin
      • a red 5mm led for motion indication, this will light up regardless of the fact that the relay has to be turned on or not.
      • 220 ohm resister between digital out and the VCC of the led

      I'll post a follow up of how I mounted this in a Waterproof box and how I mounted the PIR sensor in a waterproof housing.

      This is the Sketch:

      /**
       * Door, movement and temperature switch.
       *
       * This sensor has three main functions:
       * - A PIR Sensor for sensing movement around my front door. Each detected movement is being reported to the MySensors gateway.
       *   if the NIGHTMODE switch is on, it will also turn on the relay when a movement is being detected. (See design decisions)
       * - A door sensor for monitoring when the door of my little workshop is open or closed. Will use this in the future to trigger
       *   an alarm if the door is opened when we do not want it to be opened. E.g. when I'm a sleep at night.
       * - Since we've got some extra pins that are not in use, we might as well monitor the workshop's temperature.
       *
       * Created: September 26th 2015
       * Version: 1.1
       * Author:  by Theo
       * Website: http://www.houtbewerken-voor-dummies.com/domotica-beweging-in-je-tuin-meten
       *
       * Changelog:
       * 02-10-2015 - V1.1 Added function to leave the relay on for a while after the last detected movement.
       * 26-09-2015 - V1.0 initial version
       *
       * Design decision(s):
       * - Use a Dalas DS18b20 as a temperature sensor. It's much faster than a DHT11 or DHT22. We don't need a super accurate sensor, we're not
       *   going to control anything based upon the temperature in the Workshop.
       * - Add a dummy Light node for letting the PIR sensor controlling a relay. The switch needs to be turned on and off by the domotica controller
       *   when it's dark or not. In an earlier version I controlled the relay from my Domotica Controller, but I had a delay of about 1 second before the
       *   relay was switched on. Which was unacceptable to me. It would have been nice to read the delay value from Domoticz, but Domoticz doesn't allow  user variables for MySensors nodes. Vera does, but I don't have Vera so I can't test and develop it.
       */
      
      // Import the necessary libraries
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #include <DallasTemperature.h>
      #include <OneWire.h>
      
      // define constants. #define is more memory friendly than using static variables.
      #define TEMP_CHILD_ID 0
      #define MOTION_CHILD_ID 1
      #define SUNSET_CHILD_ID 2
      #define DOOR_CHILD_ID 3
      #define DOORSENSOR_PIN  4  // Arduino input pin for button/reed switch
      #define MOTIONSENSOR_PIN 5 // Arduino input pin for PIR motion sensor
      #define MOTIONLED_PIN 6    // Arduino output pun for visualization of detecting motion
      #define RELAY_PIN 7    // Arduino output pun for visualization of detecting motion
      #define ONE_WIRE_BUS 3     // Pin where dallas Ds18b20 sensor is connected
      #define TEMPERATURE_READING_INTERVAL 600000 // temperature reading interval in ms (min * 60000) in production we'll use 10 minutes
      #define LIGHTOFFDELAY 20000 // The amount of milliseconds the relay will be switched off after the last movement has been deteced (We'll use 20 seconds). Vera users can use a Vera variable for this. But I can not test this with Domoticz.
      
      // define sketch name and version
      #define SN "FrontdoorMotionDetection"
      #define SV "1.1"
      
      // Declare and initialize objects.
      MySensor gw;
      OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
      DallasTemperature dt_sensor(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
      Bounce doorDebouncer = Bounce();   // declare a software debounce for debouncing the door reed relay switch 
      Bounce motionDebouncer = Bounce(); // declare a software debounce for debouncing the PIR motion sensor
      
      // declare and initialize global variables. Used to store old sensor and interval readings.
      int oldDoorSensorValue = -1;    // remember the door sensor's current state for detecting changes
      int oldMotionSensorValue = -1;  // remember the PIR motion sensor's current state for detecting changes
      float lastTemperature = 0.0;    // remember the temperature for detecting changes
      bool sunsetActive = false;      // state for indicating whether the relay has to be controllered by motion (domotica controller should set this to on after sunset and off after sunrise
      unsigned long previousMillis = 0; // interval variable for temperature sensor reading
      unsigned long scheduledRelayOffMillis = 0; // Scheduler for determining when the relay has to be switched off
      
      // Declare messages that will be sent to the MySensor's gateway.
      MyMessage doorMsg( DOOR_CHILD_ID, V_TRIPPED );
      MyMessage tempMsg( TEMP_CHILD_ID, V_TEMP );
      MyMessage motionMsg( MOTION_CHILD_ID, V_TRIPPED );
      
      // Initialization code for the sketch
      void setup() {  
      //  Serial.begin( 115200 ); // uncomment during debugging.
      
        // setup a connection to the MySensor's gateway and request an ID if we do not have one yet.
        gw.begin(incomingMessage);
        gw.sendSketchInfo(SN, SV);
        
        // Initialize Dalles temp sensor
        dt_sensor.begin();
        dt_sensor.setWaitForConversion( false );
        
        // initialize the door sensor so that the arduino can read it's value. And use internal 
        // pullup
        pinMode( DOORSENSOR_PIN, INPUT_PULLUP );
        // setup debouncer
        doorDebouncer.attach( DOORSENSOR_PIN );
        doorDebouncer.interval( 5 );
        
        // initialize PIR motion sensor
        pinMode( MOTIONSENSOR_PIN, INPUT_PULLUP );
        // setup debouncer
        motionDebouncer.attach( MOTIONSENSOR_PIN );
        motionDebouncer.interval( 5 );
        
        // initialize PIR visualization LED
        pinMode( MOTIONLED_PIN, OUTPUT );
        
        // initialize RELAY
        pinMode( RELAY_PIN, OUTPUT );
       //  Serial.println( "Testing relay" );
        // Testing relay just to let to knew everything is allright.. Used to test turnRelayOn and turnRelayOff method development. I liked it and kept it.
        for ( int i=0; i <3; i++ ) {
          turnOnRelay();
          gw.wait( 2000 );
      // delay(2000);
          turnOffRelay();
          gw.wait( 2000 );
      //delay(2000);
        }
         
        // Register binary input sensors to gw (they will be created as child devices)
        gw.present( DOOR_CHILD_ID, S_DOOR);
        gw.present( MOTION_CHILD_ID, S_MOTION );
        gw.present( TEMP_CHILD_ID, S_TEMP  );
        gw.present( SUNSET_CHILD_ID, S_LIGHT );
        gw.sendBatteryLevel( 100, false ); // Let the Domotica controller no that we're a 100%
                                                                     // powered sensor.
        gw.request( SUNSET_CHILD_ID, V_LIGHT ); // request current sunset state from
                                                                   // controller
        
        // check temperature. Next reading will occur after first interval has been reached. 
        // so check the temperature as an initial reading
        checkTemperature();
      }
      
      /**
       * Turn off the relay to which a light will be connected
       */
      void turnOnRelay() {
        digitalWrite( RELAY_PIN, 0 ); // Relay needs inverted input. HIGH meaning off and LOW meaning ON
      }
      
      /**
       * Turn on the relay to which a light will be connected
       */
      void turnOffRelay() {
        digitalWrite( RELAY_PIN, 1 ); // Relay needs inverted input. HIGH meaning off and LOW meaning ON
      }
      
      /**
       * Check current temperature and send changes to the MySensors gateway
       */
      void checkTemperature() {
      //  Serial.println( "Checking temp" );
        // Fetch and round temperature to one decimal
        // Fetch temperatures from Dallas sensors
        dt_sensor.requestTemperatures();
        // query conversion time and sleep until conversion completed
        int16_t conversionTime = dt_sensor.millisToWaitForConversion( dt_sensor.getResolution() );
        // use gw.wait instead of Arduino's delay. That way the gw.process() is still working in the background
        // and we'll be able te receive messages from the Domotica controller.
        gw.wait(conversionTime);
      // delay(conversionTime);
        float temperature = static_cast<float>(static_cast<int>((dt_sensor.getTempCByIndex(0)) * 10.)) / 10.;
        if ( temperature < 85.0 && temperature > -127.0 && temperature != lastTemperature ) {
          lastTemperature = temperature;
          gw.send( tempMsg.set( temperature, 1 ) );
      // Serial.println( temperature );
        }
      }
      
      /**
       * Check the door sensor for state changes and send the state to the MySensor gateway of the state has been changed
       */
      void checkDoorSensor() {
        doorDebouncer.update();
       
        // Get the update value
        int value = doorDebouncer.read();
       
        if (value != oldDoorSensorValue ) {
           // Notify the gateway of the new door status
           gw.send( doorMsg.set( value==HIGH ? 1 : 0 ) );
      // Serial.println( (String)value + " door state " );
           oldDoorSensorValue = value;
        }
      }
      
      /**
       * Check the motion sensor for state changes and send the state to the MySensor gateway of the state has been changed
       */
      void checkMotionSensor() {
        motionDebouncer.update();
       
        // Get the update value
        int value = motionDebouncer.read();
        if (value != oldMotionSensorValue ) {
           // Notify the gateway of the new door status
           gw.send( motionMsg.set( value==HIGH ? 1 : 0 ) );
      // Serial.println( (String)value + " motion state" );
           oldMotionSensorValue = value;
           digitalWrite( MOTIONLED_PIN, value );
           if ( sunsetActive == true ) { // check whether the active motion mode is set on to turn on relay and schedule for next relay off time
             // check whether motion has been detected
             if ( value ==   1 ) {
               digitalWrite( RELAY_PIN, LOW ); // activate relay. But only when the OUTDOORLIGHT mode is active.
               // calculate next off interval if motion has been detected
               scheduledRelayOffMillis = millis() + LIGHTOFFDELAY;
             }
           }
        }
      }
      
      /**
       * Main loop.
       */
      void loop() {
        // check if the temperature needs to be read.
        unsigned long currentMillis = millis();
        if (currentMillis - previousMillis >= TEMPERATURE_READING_INTERVAL ) {
          previousMillis = currentMillis;
          checkTemperature();
        }
        checkDoorSensor();
        checkMotionSensor();
        // check if the relay has to be turned off. Which will be LIGHTOFFDELAY milliseconds after last detected movement.
        currentMillis = millis();
        if ( digitalRead( RELAY_PIN ) == LOW && currentMillis >= scheduledRelayOffMillis ) {
          turnOffRelay();
        }
        gw.process(); // No delaying this needs to be a real-time sensor. At least for the door and motion sensor.
      } 
      
      /**
       * Call back handler, for handling messages send by the MySensors gateway
       */
      void incomingMessage(const MyMessage &message) {
        if ( message.type == V_LIGHT ) {
          // check if the SUNSET mode's state changed
          if ( message.sensor == SUNSET_CHILD_ID ) {
            sunsetActive = message.getBool();
            // check if light needs to be turned on or off.
            bool relayOn = ( digitalRead( RELAY_PIN ) == LOW );
      //       Serial.println( (String)relayOn + " relais status" );
            if ( sunsetActive == true && relayOn == false ) {
               turnOnRelay();
            }
            else if ( sunsetActive == false && relayOn == true ) {
               turnOffRelay();
            }
          }
        }
      }
      
      posted in My Project
      TheoL
      TheoL
    • RE: Free MySensors 2.0 workshop, Friday 9 September in Amersfoort (The Netherlands)

      @tbowmo We had German, Belgium, Dutch and visitors from Belarus. That got me thinking we might be able to organize an international meeting next year. Would be great to do this in one weekend. Start on Friday with some beers. Have some presentations and do some projects during Saturdays and Sundays. 😉

      posted in General Discussion
      TheoL
      TheoL
    • RE: My experiences with MySensors

      @felix-haverkamp I'm sorry to hear that Felix. In my own experience MySensors works fine with the NRF24L01+ sensors. I have full range throughout my entire house. For my it wasn't a frustrating experience. I followed the instructions and it worked in most cases directly. Good to hear that you have found something that suits your needs.

      posted in My Project
      TheoL
      TheoL
    • Merry X-mas

      Hey all,

      I wanna wish you all the best X-mas - I know it's a little but early - and I wish you all some awesome projects in 2022. I hope we can get a creative spirit in 2022 and create cool things together.

      posted in My Project
      TheoL
      TheoL
    • RE: Domotiocz + Rain gauge

      @sundberg84 Using a real pulse counter instead of a 1mm pulse counter seems to work perfectly. Luckily it makes the sketch a bunch easier to implement and read. And there will also be no loss of 0.2 or 0.5 mm rain fall whenever you reset the node while it didn't have a .0 value.

      posted in Domoticz
      TheoL
      TheoL
    • RE: Many nodes with simple sketches or less nodes with complex sketches?

      @barduino Of course you're right. You have to use the arduino that fits the node the best. For a non MySensors arduino project, I'm using a second arduino as an I2C slave to my main controller. That way I can have enough pins and memory. The master Arduino is the controller, the slave is just guarding and controlling the stepper motor in this case. But I wouldn't do that a lot. In this case the ProMini 3.3V is the i2c master and contains the LCD display and triggers an IR led for sending the trigger signal to my Nikon D60. It also tells the second Arduino when it has to move the camera (turn the motor).

      The second Arduino will be a Pro Mini 5.5V, I'm not ready for this part yet. I'll be using a i2c level shifter to connect the arduino's through i2c.

      posted in General Discussion
      TheoL
      TheoL
    • RE: Combined MySensor Gateway with 433Mhz transmitter (HomeEasy/Klik-Aan-Klik-uit)

      @mvader Since it's just a Sensor it should work on any Gateway. After it's running you should see a new device in Domoticz with 5 sub nodes. They's all of the type lightning 2. Each sub device represents one of the swicthes on the impuls remote controller. The system code has to be adjusted to your own system code. On my outlets the dipswitches are all on, see the byte is 31.

       * MySensors node for switching on/of cheap 433Mhz based Power outlets from the Action
       * Author  Theo Leloux
       * Created 05-09-2015
       * Version 0.1alpha
       */
      
      /**
       * Import the libraries needed by the Sketch
       */
      #include <MySensor.h>  
      #include <SPI.h>
      #include <RemoteTransmitter.h>
       
      /**
       * Declare constants like pin settings etc.
       */
      #define TRANSMITTERPIN 6 // documentation doesn't see anything if the needs to be a PWM, but why take the risk?
      #define CHILD_ID_ACTION_SWITCH_A 1 // Declare the DEVICE A as a separate switch
      #define CHILD_ID_ACTION_SWITCH_B 2 // Declare the DEVICE B as a separate switch -- In my situation I configured all outlet's as DEVICE A, so reserved for future useage 
      #define CHILD_ID_ACTION_SWITCH_C 3 // Declare the DEVICE B as a separate switch -- In my situation I configured all outlet's as DEVICE A, so reserved for future useage 
      #define CHILD_ID_ACTION_SWITCH_D 4 // Declare the DEVICE B as a separate switch -- In my situation I configured all outlet's as DEVICE A, so reserved for future useage 
      #define CHILD_ID_ACTION_SWITCH_E 5 // Declare the DEVICE B as a separate switch -- In my situation I configured all outlet's as DEVICE A, so reserved for future useage 
      const char SYSTEMCODE = char(31); // cast the integer byte value to a char should do the trick. Adjust this to your own SYSTEMCODE see RemoteTransmitter.h
       
      /*
       * Declare variables
       */
      ActionTransmitter switchTransmitter = ActionTransmitter( TRANSMITTERPIN ); 
      unsigned long SLEEP_TIME = 5000; // the main loop will probably won't do a thing if we only attach a transmitter.
      MySensor gw;
       
      /*
       * Declare MySensors Messages
       */
      MyMessage msgDeviceA( CHILD_ID_ACTION_SWITCH_A, V_LIGHT );
      MyMessage msgDeviceB( CHILD_ID_ACTION_SWITCH_B, V_LIGHT );
      MyMessage msgDeviceC( CHILD_ID_ACTION_SWITCH_C, V_LIGHT );
      MyMessage msgDeviceD( CHILD_ID_ACTION_SWITCH_D, V_LIGHT );
      MyMessage msgDeviceE( CHILD_ID_ACTION_SWITCH_E, V_LIGHT );
      
      /**
       * Preparation code during initialization of the Arduino
       */
      void setup() {
        // put your setup code here, to run once:
        // Serial.begin( 115200 );
        gw.begin( incomingMessage ); // attach a message handler for handling commands transmitted by the controller.
      
        gw.sendSketchInfo("433Mhz bridge", "1.0");       // Send the sketch version information to the gateway and Controller
        gw.present( CHILD_ID_ACTION_SWITCH_A, S_LIGHT ); // Present Device A to the gateway
        gw.present( CHILD_ID_ACTION_SWITCH_B, S_LIGHT ); // Present Device B to the gateway
        gw.present( CHILD_ID_ACTION_SWITCH_C, S_LIGHT ); // Present Device C to the gateway
        gw.present( CHILD_ID_ACTION_SWITCH_D, S_LIGHT ); // Present Device D to the gateway
        gw.present( CHILD_ID_ACTION_SWITCH_E, S_LIGHT ); // Present Device E to the gateway
        
        gw.sendBatteryLevel(100); // It just looks better in Domoticz if we let Domoticz no we're running on 100% power.
      
      }
      
      /**
       * The Sketch's main loop.
       */
      void loop() {
        // I have nothing to do if only attach a transmitter. 
        gw.wait( SLEEP_TIME ); // call the wait routine, which will allow for incomming messages during the waiting
      }
      
      void incomingMessage(const MyMessage &message) {
        Serial.println("message");
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LIGHT) {
          char device = 64 + message.sensor; // translate child id to device ID. A = 65 so if we take off one and add the received sensor ID we get the correct device
        //  Serial.println( "Command received for Device " + (String)device + " on id " + (String)message.sensor + " request to turn " + (message.getBool()?"on":"off") );
          if ( device >= 'A' && device <= 'E' ) { // Impuls/Action system only allows device 'A' to 'E'
            switchTransmitter.sendSignal(SYSTEMCODE, device, message.getBool() );
          }
        }
      }
      

      I attached the 433 Mhz data line to pin 6 of the arduino. Not sure if it needs PWM. But I just started an hour ago and haven't had the time yet to look that up. For around 15 euro I'm able to control all my cheap 433Mhz outlets with Domoticz. I feel like a little kid in a candy shop 😉

      Next thing to do is to hook up the receiver. So that I can receive the commands from the remote controller and send them to Domoticz. Work in progress hope to finish it this evening. But the reciever library has no support for impuls, so it might take a while.

      posted in My Project
      TheoL
      TheoL
    • RE: Your workshop :)

      @Samuel235 I almost feel ashamed. I have a relative cheap soldering iron and a cheap multi-meter. But like I always tell people, when they ask me about the best tools for woodworking. It's not about the tools, it's what you do with it 😉

      posted in General Discussion
      TheoL
      TheoL
    • RE: Combined Sensor RepeaterNode and sleep(SLEEP_TIME) in MySensors 2.0.0

      @sincze Since sleep will put your Arduino to sleep, it will not be able to receive messages. So you shouldn't use sleep on a repeater node. You should use wait instead.

      posted in My Project
      TheoL
      TheoL
    • Free analog electronics course for everyone who understands Dutch

      Since I wanted to know more about electronics, than just how to hookup components, I started looking for a course. I found a couple but they are all very expensive (1000 euro plus) and their purpose is more to train people as electronics professionals.

      I thought about that, but I'm pretty sure that I'll keep this is a hobby. I like my current job too much. After looking a bit further I came across this website hobby-electronics.info. This website is registered by a mr van den Heuvel (I checked that, because I'm always suspicious about free content in PDF files). I haven't scanned the PDF files for virus, that's because I don't have a virus scanner installed on my Mac (Which I probably should be doing). But if someone wants to do this, I'd be much obliged.

      I watched the lessons on his youtube channel, and they look more than pretty okay to me. At least I remember the things I was taught at school again. So if you want to know more about electronics and you understand Dutch, this is a great youtube channel The course seems pretty complete to me, but maybe someone with more electronics knowledge can confirm this.

      Please give the man thumbs up if you like his video. He spends a lot of time recording this free content. I don't know him, but I appreciate people who share things out of passion, instead of wanting to earn money with it.

      posted in General Discussion
      TheoL
      TheoL
    • RE: Has anyone made a 2 or 4 channel relay , and is that worked correct ?

      @Reza

      So I took your Sketch and refactored it. Just to be sure that nothing strange is in the code. I don't think there was anything strange in it. I just don't like the ID of defining one relay and calculate the others. But that's just me. I'd like to be able to debug, but with the way this sketch is set-up, checking what might be wrong is just harder to do.

      Haven't tested it on an Arduino, don't have any empty breadboard at the moment.

      #include <MySensor.h>
      #include <SPI.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         HIGH  // GPIO value to write to turn on attached relay
      #define RELAY_OFF        LOW   // GPIO value to write to turn off attached relay
      #define SKETCH_NAME      "Relay"
      #define SKETCH_VERSION   "1.0"
      
      // Construct MySensors library
      MySensor gw; // don't bother with singing yet. First get the sketch and hardware to work...!!!!
      
      void setup() {
        gw.begin( incomingMessage, AUTO, true ); // Initialize library and add callback for incoming messages
        gw.sendSketchInfo( SKETCH_NAME, SKETCH_VERSION); // Send the sketch version information to the gateway and Controller
      
        for ( int sensor = 0; sensor < NUMBER_OF_RELAYS; sensor++ ) {
          gw.present( sensor + 1, S_LIGHT );           // Present the actuator to the GW
          pinMode( RELAY_1 + sensor, OUTPUT );         // Assign Relay_pin as output
          digitalWrite( RELAY_1 + sensor, RELAY_OFF ); // turn of the relay (some relay need inverted value. You'll have to check yours.). Turning it of is for safety!!!
          gw.wait( 50 );                               // my gateway sometimes just can't handle to much child presents after each other
          gw.request( sensor + 1, V_LIGHT );           // Request current state from Home Automation controller. I just don't see any reason to store it in the EPROM
          gw.wait( 50 );                               // my gateway sometimes just can't handle to much child presents after each other
        }
      }
      
      
      void loop() {
        // Alway process incoming messages whenever possible
        gw.process();
      }
      
      void incomingMessage(const MyMessage &message) {
        if ( message.type==V_LIGHT ) { // We only expect one type of message from controller. But we better check anyway.
           int relayPin = RELAY_1 + message.sensor - 1;
           if ( message.sensor >= 1 && message.sensor <= NUMBER_OF_RELAYS ) { // make sure message is for a known pin. You wouldn't want to write to a pin that's being used for the radio.
             digitalWrite( relayPin, message.getBool() ? RELAY_ON : RELAY_OFF ); // Change relay state
      
             // Write some debug info
             Serial.print("Incoming change for sensor:");
             Serial.print(message.sensor);
             Serial.print( ", relay_pin: " );
             Serial.print( relayPin );
             Serial.print(", New status: ");
             Serial.println(message.getBool());
           }  
         } 
      }
      

      Sketch should work. Please post the serial output of this sketch.

      My first steps would be:

      1. Use the sketch I provided (should work, or I missed something).
      2. Disconnect RELAY from Arduino.
      3. Connect LEDs to the arduino with resistor (330 Ohm should be just fine)

      Test this. The reason I would remove the relay is to be sure there's no power issue. The arduino should be able to provide enough power for driving a simple LED.

      If this works you know that it's a hardware problem and from there on, you can investigate what the problem is.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: gw send, how to do in my combination of sensors

      @Dick added some comments in the code. And made some changes. It compiles. But I can't test it for you..

      #include <MySensor.h>
      #include <SPI.h>
      #include "Bounce2.h"
      #define USE_MOTION_SENSOR
      #define MOTION_SENSOR_PIN    3          //physical number of PIR
      #define LIGHT_SENSOR_ANALOG_PIN A0      //physical number of LDR
      #define CHILD_ID_LIGHT 6
      #define RELAY_ON 0                      // switch around for realy HIGH/LOW state
      #define RELAY_OFF 1
      
      Bounce motionsDebouncer = Bounce();
      
      MySensor gw;
      
      #define RADIO_ID 11                    // radio Id, whatever channel you assigned to
      #define noRelays 5                     //number of relais in use
      const int relayPin[] = {A1, A2, A3, A4, A5}; //  switch around pins to your desire number of relais
      const int buttonPin[] = {4, 5, 6, 7, 8   }; //  switch around pins to your desire number of buttons
      
      // <-- byTheo since you don't have any methods in your class, a simple C struct made be
      //                    more resource friendly
      class Relay             // relay class, store all relevant data (equivalent to struct)
      {
        public:
          int buttonPin;                    // physical pin number of button
          int relayPin;                     // physical pin number of relay
          byte oldValue;                    // last Values for key (debounce)
          boolean relayState;               // relay status (also stored in EEPROM)
      };
      
      Relay Relays[noRelays];
      Bounce debouncer[noRelays];
      MyMessage msgRelay[noRelays];
      MyMessage msgLDR(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      
      
      #define MOTION_CHILD_ID 8 // <-- byTheo
      MyMessage motionMsg( MOTION_CHILD_ID, V_TRIPPED ); // <-- byTheo
      
      int lastLightLevel;
      unsigned long SLEEP_TIME = 6000; // Sleep time between reads (in milliseconds)
      
      void setup()
      {
        gw.begin(incomingMessage, RADIO_ID, true);
        //  delay(250); // <-- byTheo
        gw.wait( 250 ); // <-- byTheo
        gw.sendSketchInfo("Multy-Relay&button-PIR&LDR", "0.2");
        //  delay(250); // <-- byTheo
        gw.wait( 250 ); // <-- byTheo
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      
        pinMode( MOTION_SENSOR_PIN, INPUT_PULLUP );
        motionsDebouncer.attach(MOTION_SENSOR_PIN); // <---- byTheo I believe PIR sensors don't need debouncing
        motionsDebouncer.interval(50); // <---- byTheo I believe PIR sensors don't need debouncing
      
        // Initialize Relays with corresponding buttons
        for (int i = 0; i < noRelays; i++)
        {
          Relays[i].buttonPin = buttonPin[i];              // assign physical pins
          Relays[i].relayPin = relayPin[i];
          msgRelay[i].sensor = i;                                   // initialize messages
          msgRelay[i].type = V_LIGHT;
          debouncer[i] = Bounce();                        // initialize debouncer
          debouncer[i].attach(buttonPin[i]);
          debouncer[i].interval(5);
          pinMode(Relays[i].buttonPin, INPUT_PULLUP);
          pinMode(Relays[i].relayPin, OUTPUT);
          Relays[i].relayState = gw.loadState(i);                               // retrieve last values from EEPROM
          digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
          gw.send(msgRelay[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
          gw.present(i, S_LIGHT);                               // present sensor to gateway
          //  delay(250); // <-- byTheo
          gw.wait( 250 ); // <-- byTheo
      
        }
      
        gw.present( MOTION_CHILD_ID, S_MOTION, "Motion needs presentation", true ); // byTheo
        gw.wait( 250 ); // <-- byTheo
      }
      
      void loop()
      {
        if ( motionsDebouncer.update()) {
          int value = motionsDebouncer.read();
          Serial.println( "PIR " + (String)value );
          gw.send( motionMsg.set( value ), true ); // <-- byTheo : Also it might need inverted value
      
        }
        //  { <--- byTheo
        gw.process();
        for (byte i = 0; i < noRelays; i++)
        {
          debouncer[i].update();
          byte value = debouncer[i].read();
          if (value != Relays[i].oldValue && value == 0)
          {
            Relays[i].relayState = !Relays[i].relayState;
            digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF);
            gw.send(msgRelay[i].set(Relays[i].relayState ? true : false));
            gw.saveState( i, Relays[i].relayState );
          }                 // save sensor state in EEPROM (location == sensor number)
      
          Relays[i].oldValue = value;
        }
        int lightLevel = (1023 - analogRead(LIGHT_SENSOR_ANALOG_PIN)) / 10.23;
        //Serial.println(LDR);
        if ((lightLevel > 1.05 * lastLightLevel) || (lightLevel < 0.95 * lastLightLevel))  //5% difference will send
        {
          gw.send(msgLDR.set(lightLevel));
      
          lastLightLevel = lightLevel;
          Serial.print("LDR");
      
          Serial.println(lightLevel);
      
        }
        // } // <---- byTheo
      }
      // process incoming message
      void incomingMessage(const MyMessage &message)
      {
      
        if (message.type == V_LIGHT)
        {
          if (message.sensor < noRelays)            // check if message is valid for relays..... previous line  [[[ if (message.sensor <=noRelays){ ]]]
          {
            Relays[message.sensor].relayState = message.getBool();
            digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
            gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
          }
        }
        // delay( 50 ); // give the input pins some rest. Incomming messages are still being processed.
      //  gw.wait(50); // <-- byTheo don't use delays in message handler. Message handler needs the shortest execution time is possible
      
      }
      
      posted in General Discussion
      TheoL
      TheoL
    • RE: Trying to build a Door and Sound sensors

      @chatainsim 5ms for debouncer might be a bit low. I use 50ms without any problems

      Have you added a pullup resistor to the door sensor? If not try changing this in your sketch:

      //  pinMode(BUTTON_PIN,INPUT);
       pinMode(BUTTON_PIN,INPUT_PULLUP);
        debouncer.attach(BUTTON_PIN);
      
      posted in Troubleshooting
      TheoL
      TheoL
    • RE: Stand alone lighting control system

      @dakipro I'll try to add an MQTT tutorial within a couple of weeks. I want to do an MQTT presentation for my colleagues so why not combine it with a tutorial for the MySensors community. It's a bit hard to understand in the beginning, but once you understand the basics, you wonder why you not have used it before.

      But again, there should be no need for an master/slave controller implementation. The only thing I can't prevent is an power outage. Everything else runs very stable in my house at least. And if I don't want to control my lighting with my Home Automation controller, I'm still able to use manually operated switches, which is one of my main design principles when designing new MySensors actuators.

      Most important for each Node is that you simply don't used the Arduino as a power supply. I found that out the hard way. I now power everything from an power adapter, incl. the Antenna.

      posted in General Discussion
      TheoL
      TheoL
    • RE: [Solved] API 2.0 void receive(const MyMessage& message) Problem

      @paqor I wouldn't put sensor readings in a message handler. Could you try this, just to test the messages?

      wait(SLEEP_TIME); //sleep for: sleepTime // byTheo: Changed
      }
      //incomingMessage_____________________________________________________
      void receive(const MyMessage& message)
      {
      //  gasSensor.setR0(R0C);  // byTheo: Changed
      // Serial.println(F("Incoming Message:")); // byTheo: Changed
      Serial.println("Incoming Message:");
      }
      

      And I also advice not to use sleep when having a node that can receive messages.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: are there a full smart home ( controller and app and devices) Made by mysensors team ? :)

      @Reza I think there are already a lot of open source controllers available that only require some affordable hardware like a raspberry pi for instance. I'm not gonna name one in particular, but you could check the supported controlles topic/page.

      In my opinion MySensors should stay the way that it is. Being an open source platform for inter device communication. That way MySensors is independent from any controller and stays available to a broad public. But that's my 50 cents,

      posted in General Discussion
      TheoL
      TheoL
    • RE: [Solved] API 2.0 void receive(const MyMessage& message) Problem

      @paqor That's great. I looked at the Sketch you posted on your site and noticed you're still using a delay. Which as short as it may be can cause messages to be missed.

      void loop(){
      //-----------------------------------------------------------------------------
      //TEMP_FEUCHTE 
      delay(dht.getMinimumSamplingPeriod());
      

      My advice is to do this with a wait as well.

      void loop(){
      //-----------------------------------------------------------------------------
      //TEMP_FEUCHTE 
      wait(dht.getMinimumSamplingPeriod()); // Changed ByTheo
      

      That way you don't block incoming messages. Generally, if you want your sketch to wait use a wait.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: Library V2.x API error

      @BearWithBeard Well there are more things in play. Making assumptions now. Most people don't want to read the trouble shooting section, they just want to be helped quickly. And from a usability perspective written documentation isn't the most optimized form of transferring knowledge. Because it is almost impossible to write things in such a way every one can understand it. A simple comic on radio trouble shooting might help more people. But again, that is just assumptions.

      I always try to find the solution myself. But have seen people asking question that were documented well. In this an other forums.

      posted in General Discussion
      TheoL
      TheoL
    • RE: How to disable default node registration to the GW?

      @Nca78 If there's a power outage MySensors handles restoring communication. What you could do is install a watch dog during initialization. And give at the longest time as possible, or some kind of random. That helps overloading the gateway when everything is turned back on again.

      If a device should operate even without gateway communication, then you've got several options. Just add an extra arduino to your project. Make the MySensors node an i2c slave and handle everything else in the other Arduino. This is just one solution, which I'd only use for delicate devices,

      But none of them will keep the node operating without an UPS kind of solution. There are nowadays powerful capacitors than can store a lot ow power, this is something that can help you keep the node up and running during power outage for at least a couple of minutes.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: What is actual status of MySensors?

      It has been taking over by CodeGarage to assure continuation

      posted in General Discussion
      TheoL
      TheoL
    • RE: Sensor presentation failure

      @Sergio-Rius Thank you! It's part of a library I'm working on, which just handles all the binary switch logic for you. Learning how to program is hard enough, so I'm trying to make it easier for new MySensors users. I'll be pushing it to my github in a couple of days. When I'm done testing.

      posted in Bug Reports
      TheoL
      TheoL
    • RE: Option non blocking registration at gateway

      @mfalkvidd @Yveaux There was a similar discussion a couple of weeks ago. The gateway should always be reachable. Unless there's a power cut. But to be honest I don't know what happens then. Might take a couple of hours before my network is completely healed. Because the nodes might come up earlier than the gateway once the power is back on. Also the gateway might not be able to handle all the node registrations. But in those cases nodes need to register themselves with a random delay. Just to give the gateway the time to handle the load. Because I'm not convinced it can.

      My personal statement is: Devices should work independently from your home automation if they are a vital part of your life. Like light and so. Home Automation and IoT should enhance your life, and not take over your life.

      And to be honest. I don't see the need of buffering messages. Because the messages you'll be buffering might already be outdated when the gateway and your controller come up again. Meaning you could have switched the lights on and then off. So what would be the value of buffering the outdated data? We should just simply accept the fact that we've lost some sensor values. The data can be interpolated in the long run anyway. Which Domoticz already does, when it shows you the graphs.

      I can't remember the last power cut we had over here. So to me losing some sensor values in a situation like that is acceptable. Certainly if all of my MySensors devices will keep working in a situation like this. Then loosing data isn't that bad.

      This is also the reason why you should send the current state of sensors and actors on a regular basis to you controller. That way the controller and the nodes will be in synch again at some time, after a power cut.

      This feature would indeed help us in creating a solution which enhances our lives instead of the opposite. But that's just my 50 cents. Curious how Z-waves handles this?

      posted in Feature Requests
      TheoL
      TheoL
    • Another ProMini 3.3V timing isue and the solution

      At the moment I'm developing an IntervaloMeter. It's not going to be a MySensors project, well indirectly it is. It's a device that can send a shutter trigger signal to my Nokia D90 digital camera on a interval basis. I'm developing this device, so that I can make a time lapse of the MySensors wake-up light I've developed. So that you guys can see the different color changes. Since I don't own an original WakeUp light, I could use your opinion.

      For the intervaloMeter I'm using a ProMini 3.3V with a Nokia 5110 display.
      Nokia 5110.jpg Since the AdaFruit library for that LCD display uses pin 3, I couldn't use pin 3 for hooking the Ir transmitter led to the Arduino. So I couldn't use IRremote.h which I think is part of MySensors.

      After having a hard time getting the Ir to work on the ProMini 3.3V, I realized I had three options:

      1. Use a ProMini 5V because that has a 16Mhz processor for which most of the libraries are optimized. But I wanted this to be a 2 AA battery project. I kept that as the last resource.
      2. Look for another LCD display that doesn't use pin 3 and that also only needs 3.3V. This wasn't the first option I wanted to go for. I had spent 24 hours developing a User Interface that is optimized for the best User Experience I could come up with for the Nokia 5110 lcd display. Yeah I know, I should have sorted out how to control the Ir led with a ProMini 3.3V first, but I didn't
      3. Look for a way to free Pin 3. This was the first one I wanted to explore.

      After some research I came across this pdf from AdaFruit https://learn.adafruit.com/downloads/pdf/nokia-5110-3310-monochrome-lcd.pdf

      I hooked up the Nokia 5110 reset pin to the RST pin of the ProMini and bingo!!! It works so now I have pin three available. The PDF contains more tips, about how you can hook up the LCD with only 3 pins, which also might mean, that I'll be able to use the Nokia 5110 in a MySensor project ;-).

      I was now able to use the IRremote.h library by Ken Shirriff's. It uses the Arduino internal PWM timers which is really accurate when it comes to timing. My D90 responds to each IR command triggered by my Arduino. I'm really happy that I didn't spend 24 hours developing a user interface , that I had to throw away. But even if I would have, on the positive side I learned a great deal on designing a pretty good User Interface with the Arduino and the Nokia 5110 (I'll post a video on this topic in the future).

      Apologies for this long story, especially since it's not about MySensors. But maybe I helped someone with sharing my findings.

      p.s. Maybe we can keep track of all 8Mhz friendly libraries. Because as much as I like the ProMini 3.3V. I found out, that I spend a lot of time finding the right libraries for 8Mhz processors.

      posted in Development
      TheoL
      TheoL
    • RE: Option non blocking registration at gateway

      @hek Just curious. How important is the handshake? Because if it's important I think it would be a good option, to let node's do a delayed hand shake when the initial one fails. So that they can continue, but just won't use the my sensors part until a delayed handshake is done.

      A delayed hand shake would only be needed when there's a power cut.

      posted in Feature Requests
      TheoL
      TheoL
    • RE: Multiple DH22 sensors

      @Jasper-van-Winden It can't know that. You'll need three instances of DHT. I changed your sketch so that it should work. At least it compiles I don't have three D22 that I can use to test.

      I've appended // <--- by Theo to each line I've changed.

      /**
         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.
      
      */
      
      #include <SPI.h>
      #include <MySensor.h>
      #include <DHT.h>
      
      #define CHILD_ID_HUM1 0
      #define CHILD_ID_TEMP1 1
      #define HUMIDITY_SENSOR_1_DIGITAL_PIN 3
      
      #define CHILD_ID_HUM2 3
      #define CHILD_ID_TEMP2 4
      #define HUMIDITY_SENSOR_2_DIGITAL_PIN 4
      
      #define CHILD_ID_HUM3 5
      #define CHILD_ID_TEMP3 6
      #define HUMIDITY_SENSOR_3_DIGITAL_PIN 5
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      
      MySensor gw;
      
      DHT dht1; // <--- by Theo
      DHT dht2; // <--- by Theo
      DHT dht3; // <--- by Theo
      
      
      float lastTemp1;
      float lastHum1;
      float lastTemp2;
      float lastHum2;
      float lastTemp3;
      float lastHum3;
      boolean metric = true;
      
      MyMessage msgHum1(CHILD_ID_HUM1, V_HUM);
      MyMessage msgTemp1(CHILD_ID_TEMP1, V_TEMP);
      MyMessage msgHum2(CHILD_ID_HUM2, V_HUM);
      MyMessage msgTemp2(CHILD_ID_TEMP2, V_TEMP);
      MyMessage msgHum3(CHILD_ID_HUM3, V_HUM);
      MyMessage msgTemp3(CHILD_ID_TEMP3, V_TEMP);
      
      void setup()
      {
        gw.begin();
        dht1.setup(HUMIDITY_SENSOR_1_DIGITAL_PIN); // <--- by Theo
        dht2.setup(HUMIDITY_SENSOR_2_DIGITAL_PIN); // <--- by Theo
        dht3.setup(HUMIDITY_SENSOR_3_DIGITAL_PIN); // <--- by Theo
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("HumiditySensorDrieineen", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID_HUM1, S_HUM);
        gw.wait( 55 ); // <--- by Theo
        gw.present(CHILD_ID_TEMP1, S_TEMP);
        gw.wait( 55 ); // <--- by Theo
        gw.present(CHILD_ID_HUM2, S_HUM);
        gw.wait( 55 ); // <--- by Theo
        gw.present(CHILD_ID_TEMP2, S_TEMP);
        gw.wait( 55 ); // <--- by Theo
        gw.present(CHILD_ID_HUM3, S_HUM);
        gw.wait( 55 ); // <--- by Theo
        gw.present(CHILD_ID_TEMP3, S_TEMP);
        gw.wait( 55 ); // <--- by Theo
      
        metric = gw.getConfig().isMetric;
      }
      
      void loop()
      {
        delay(dht1.getMinimumSamplingPeriod());
      
        float temperature1 = dht1.getTemperature(); // <--- by Theo
        if (isnan(temperature1)) {
          Serial.println("Failed reading temperature from DHT1");
        } else if (temperature1 != lastTemp1) {
          lastTemp1 = temperature1;
          if (!metric) {
            temperature1 = dht1.toFahrenheit(temperature1); // <--- by Theo
          }
          gw.send(msgTemp1.set(temperature1, 1));
          Serial.print("T: ");
          Serial.println(temperature1);
        }
      
        float humidity1 = dht1.getHumidity(); // <--- by Theo
        if (isnan(humidity1)) {
          Serial.println("Failed reading humidity from DHT1");
        } else if (humidity1 != lastHum1) {
          lastHum1 = humidity1;
          gw.send(msgHum1.set(humidity1, 1));
          Serial.print("H: ");
          Serial.println(humidity1);
        }
      
        float temperature2 = dht2.getTemperature(); // <--- by Theo
        if (isnan(temperature2)) {
          Serial.println("Failed reading temperature from DHT2");
        } else if (temperature2 != lastTemp2) {
          lastTemp2 = temperature2;
          if (!metric) {
            temperature2 = dht2.toFahrenheit(temperature2); // <--- by Theo
          }
          gw.send(msgTemp2.set(temperature2, 1));
          Serial.print("T: ");
          Serial.println(temperature2);
        }
      
        float humidity2 = dht2.getHumidity(); // <--- by Theo
        if (isnan(humidity2)) {
          Serial.println("Failed reading humidity from DHT2");
        } else if (humidity2 != lastHum2) {
          lastHum2 = humidity2;
          gw.send(msgHum2.set(humidity2, 1));
          Serial.print("H: ");
          Serial.println(humidity2);
        }
      
        float temperature3 = dht3.getTemperature(); // <--- by Theo
        if (isnan(temperature3)) {
          Serial.println("Failed reading temperature from DHT3");
        } else if (temperature3 != lastTemp3) {
          lastTemp3 = temperature3;
          if (!metric) {
            temperature3 = dht3.toFahrenheit(temperature3); // <--- by Theo
          }
          gw.send(msgTemp3.set(temperature3, 1));
          Serial.print("T: ");
          Serial.println(temperature3);
        }
      
        float humidity3 = dht3.getHumidity(); // <--- by Theo
        if (isnan(humidity3)) {
          Serial.println("Failed reading humidity from DHT3");
        } else if (humidity3 != lastHum3) {
          lastHum3 = humidity3;
          gw.send(msgHum3.set(humidity3, 1));
          Serial.print("H: ");
          Serial.println(humidity3);
        }
      
        //  gw.sleep(SLEEP_TIME); //sleep a bit  // // <--- by Theo
        gw.wait(SLEEP_TIME); //sleep a bit  // // <--- by Theo
      }
      
      posted in Development
      TheoL
      TheoL
    • RE: RF Nano = Nano + NRF24, for just $3,50 on Aliexpress

      I know it's an old topic. But Today I received 2 of the Makefun RF Nanos. And after reading this topic I feared I would need a lot of time to get it to work. But I quickly adjusted a MySensors example and hooked a led to it, just to able to test.

      I don't need to specify the CE and CS pins - in fact it didn't work if I did. And I can control the led with the node located in every room in my house. Not that I have a very big house. But so far no failures. So the reach isn't that bad at all. I also see a connector that seems to be there for hooking up an Antenna. I think that would be something I try before replacing the capacitor.

      As a non hardware specialist soldering SMD is a skill I have yet to master. So I'm quite happy with the small footprint. As I don't plan on powering this one with batteries, I power it with a phone charger. Next step is to see how stable it is as a gateway. But That is something I wanna try in the weekend.

      Here's the simple sketch I used. Don't watch the comments. I literally heked it together to be able to test it.

       Test sketch for testing the RF Nano
      */
      
      // 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>
      
      #define SN "RF Nano test"
      #define SV "1.0"
      
      const uint8_t LED_PIN = 8;
      
      MyMessage lightMsg(0, V_LIGHT);
      
      
      /***
         Test sketch initialization method
      */
      void setup()
      {
        pinMode( LED_PIN, OUTPUT );
        digitalWrite( LED_PIN, LOW );
      
      }
      
      void presentation() {
        // Register the LED Dimmable Light with the gateway
        present( 0, S_LIGHT );
      
        delay( 50 );
      
        sendSketchInfo(SN, SV);
      
        delay( 50 );
      
        // Pull the gateway's current light state  upon sensor node power-up. All examples says it should be in the setup -
        // but that never works for me. Besides I thought the setup was only executed ones and the presentation each time after a succesfull connection
        request( 0, V_LIGHT );
      }
      
      /***
          Dimmable LED main processing loop
      */
      void loop()
      {
      }
      
      void receive(const MyMessage &message) {
        if (message.type == V_LIGHT || message.type == V_DIMMER) {
          Serial.println( message.data  );
          int lightState = atoi( message.data );
      
          if ( lightState ) {
            Serial.println( "Turning light on" );
            digitalWrite( LED_PIN, HIGH );
          }
          else {
            Serial.println( "Turning light off" );
            digitalWrite( LED_PIN, LOW );
          }
      

      So far happy with it. I'll give it a durability test the next few weeks. Just to see if it will keep working. The only thing I really don't like is the very very bright power led. So I guess I have to start practicing removing these tiny SMD leds.

      But if it keeps performing as it does. This might be my to go with board for all non battery powered nodes.

      posted in Hardware
      TheoL
      TheoL
    • RE: Dimmable LED kitchen light (Arduino, APDS-9960, RGBWW led)

      Love it. Have you tried the APDS-9930? I have them laying around, but haven't got time to try them

      posted in OpenHardware.io
      TheoL
      TheoL
    • RE: MySensors Contest Winners 2016

      Congratulations to all the other winners. I seriously never thought I had any change in winning. I have another project in the pipeline which, my guess, your wife/girlfriend is gonna like a lot. Mine does anyway.

      posted in Announcements
      TheoL
      TheoL
    • RE: Extra info page or wiki.

      @j-jk Thanx for your kind words.

      To be honest I don't think you should know that much details, like how the protocols works and how a sensor looks up for the gateway or a repeater node. The good thing about MySensors is that you don't need to know that kind of stuff. MySensors hides it from you and takes care of it. What you need to know is how you declare and setup the gateway in your Sketch. How you present different sensors to the gateway and how you can send and receive values to and from the gateway. Combining different sensors into one sketch is already something, you need to learn some basic software skills for.

      What I'm working on is a basic how-to tutorial for how to combine Sketches. I don't mind sharing them with @Hek 'cause they might be suitable for the mysensors.org website as well. Since my English is good, but not good enough, somebody has to review them.

      I've been a teacher at the Hogeschool of Enschede in the field of software Engineering for over 4 years. I always use the knowledge and educational skills I learned during that period in the tutorials I write. Because I like to educate people.

      The problem with teaching people how to develop software, is that writing good software is actually harder than most people think. Some people can teach themselves how to write software. But for a lot of people looking at examples is not enough. And I'm not trying to discourage anyone, because writing software is also very fun. But when you have to combine software with electronics, it might just be too much at the same time, for people.

      posted in Development
      TheoL
      TheoL
    • RE: Why continue to use NRF24L01?

      @sgonch A couple. No IP-adress for instance. I for one don't believe in HTTP as a good protocol for IoT, But that's just my fifty cents.

      posted in Hardware
      TheoL
      TheoL
    • RE: Dimmable LED kitchen light (Arduino, APDS-9960, RGBWW led)

      @mfalkvidd I have so far not been able to cover the sensor. It's very sensitive. So if somebody knows a material that can cover the sensor while keeping it operating, I'll be be much obliged.

      posted in OpenHardware.io
      TheoL
      TheoL
    • RE: 💬 Soil Moisture Sensor

      @Diazovitch69 I have a hard time zooming in the provided wiring, so I can't check it. But as evb says, it looks like the radio isn't connected right. So either it's not wired correctly or you could have a broken radio.

      The things I normally do when I encounter this, is first check and double check the wiring. I also measure the individual cables in the dupont cable. It happened to me once I had bought a broken cable. Or another problem I once had, was that the power and ground rail of the bread board weren't connected from the left to the right section. Some broad boards have them connected others don't have that so you need to connect them in the middle.

      I even got a free arduino once. Because I was convinced everything was correct so I contacted the supplier and he send me a new Arduino. I replaced it and still the same problem lol. Then I measured and found the cause.

      If you're sure the wiring is correct. I'd try out another radio. Be sure that power radio with 3.3v and not 5V.

      posted in Announcements
      TheoL
      TheoL
    • RE: New to this and frustrated with the arduino IDE

      @ewaldsreef I'm not sure what you changed in the .h files. But if it were statements like #define etc. Than you either should change them back or reinstall everything. Because the libraries will no longer work.

      I'd suggest the following steps. Just to be sure where it goes wrong.

      1. Uninstall the ide
      2. Install the ide again and tyr if you can upload the blink sketch to an arduino. This shouldn't cause any problems.
      3. then follow the guidelines for installing the mysensors library into the arduino ide.
      4. Hook up an antenna and an LED (with 220 Ohm resistor)
      5. Upload the simple light example to the arduino
      6. Watch the errors.
      posted in Development
      TheoL
      TheoL
    • RE: Why continue to use NRF24L01?

      @neech I'm extending my local Intranet Of Things eco-system, my conclusion is the same as yours. I'll be adding a separate local router. By that I'm also creating a DMZ, which will make it harder for hackers to get to my local network. And I'll be able to add a VPN in the DMZ. With the VPN I'll be able to connect to my local network when I'm not at home.

      Since I already want an extra router, I'll have no extra costs when I'll be adding some ESP8266 sensors. But my point is, that most people don't know how to add an extra router, besides it adds cost at least 100 dollar or more your solution. I haven't checked how much cheaper the ESP8266 is, but you'll have to take the extra cost for purchasing an extra router and the power consumption of that router into account. How many NRF24L01 sensors can you build for that kind of money?

      posted in Hardware
      TheoL
      TheoL
    • RE: fail presentation

      @Luc3as it seems that you have found a bug in Home Assistant. Haven't seen a Stack trace in a while. I think it would help the developers if you can post the log file including the stack trace.

      posted in Home Assistant
      TheoL
      TheoL
    • RE: 💬 Battery Powered Sensors

      @tssk I use a threshold. I measure every 30 - 60 seconds. If a change goes pass the threshold I report immediately. Else I report periodically. I think I've created a small lib for that some years ago

      posted in Announcements
      TheoL
      TheoL
    • RE: Multiple I2C sensors sketch

      @macieiks I don't think you're question is really related to MySensors, it's more an Arduino related question. The problem you might have is the memory capacity of the Arduino. Here's the sketch for the first mySensor node I made. It uses an I2C lux and i2c barometric pressure sensor and an HDT11 humidity sensor.

      /**
       * 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.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik EKblad
       * 
       * DESCRIPTION
       * This sketch provides an example how to implement a humidity/temperature
       * sensor using DHT11/DHT-22 
       * http://www.mysensors.org/build/humidity
       */
       
      // #define DEBUG 
       
      #include <SPI.h>
      #include <MySensor.h>  
      #include <DHT.h>
      #include <Wire.h>
      #include <Adafruit_BMP085.h>
      #include <Adafruit_TSL2561_U.h>
      #include <Adafruit_Sensor.h>
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_BARO 2
      #define CHILD_ID_LIGHT 3
      
      #define HUMIDITY_SENSOR_DIGITAL_PIN 3
      
      const float ALTITUDE = 28; // <-- adapt this value to your own location's altitude. Lijkt dus in meters te zijn
      unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
      
      const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" };
      enum FORECAST
      {
      	STABLE = 0,			// "Stable Weather Pattern"
      	SUNNY = 1,			// "Slowly rising Good Weather", "Clear/Sunny "
      	CLOUDY = 2,			// "Slowly falling L-Pressure ", "Cloudy/Rain "
      	UNSTABLE = 3,		// "Quickly rising H-Press",     "Not Stable"
      	THUNDERSTORM = 4,	// "Quickly falling L-Press",    "Thunderstorm"
      	UNKNOWN = 5			// "Unknown (More Time needed)
      };
      
      Adafruit_BMP085 bmp = Adafruit_BMP085();
      MySensor gw;
      Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
      
      DHT dht;
      float lastTemp = -1000;
      float lastHum = -1;
      float lastPressure = -1;
      int lastForecast = -1;
      int lastLightLevel = -1;
      
      const int LAST_SAMPLES_COUNT = 5;
      float lastPressureSamples[LAST_SAMPLES_COUNT];
      
      // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm
      // get kPa/h be dividing hPa by 10 
      #define CONVERSION_FACTOR (1.0/10.0)
      
      int minuteCount = 0;
      bool firstRound = true;
      // average value is used in forecast algorithm.
      float pressureAvg;
      // average after 2 hours is used as reference value for the next iteration.
      float pressureAvg2;
      
      float dP_dt;
      
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage pressureMsg(CHILD_ID_BARO, V_PRESSURE);
      MyMessage forecastMsg(CHILD_ID_BARO, V_FORECAST);
      MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      
      
      /**************************************************************************/
      /*
          Displays some basic information on this sensor from the unified
          sensor API sensor_t type (see Adafruit_Sensor for more information)
      */
      /**************************************************************************/
      #ifdef DEBUG
      void displaySensorDetails(void)
      {
        sensor_t sensor;
        tsl.getSensor(&sensor);
        Serial.println("------------------------------------");
        Serial.print  ("Sensor:       "); Serial.println(sensor.name);
        Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
        Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
        Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
        Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
        Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");  
        Serial.println("------------------------------------");
        Serial.println("");
        delay(500);
      }
      #endif
      
      /**************************************************************************/
      /*
          Configures the gain and integration time for the TSL2561
      */
      /**************************************************************************/
      void configureSensor(void)
      {
        /* You can also manually set the gain or enable auto-gain support */
        // tsl.setGain(TSL2561_GAIN_1X);      /* No gain ... use in bright light to avoid sensor saturation */
        // tsl.setGain(TSL2561_GAIN_16X);     /* 16x gain ... use in low light to boost sensitivity */
        tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */
        
        /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
        tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */
        // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS);  /* medium resolution and speed   */
        // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  /* 16-bit data but slowest conversions */
      
        /* Update these values depending on what you've set above! */
      #ifdef DEBUG
          Serial.println("------------------------------------");
        Serial.print  ("Gain:         "); Serial.println("Auto");
        Serial.print  ("Timing:       "); Serial.println("13 ms");
        Serial.println("------------------------------------");
      #endif
      }
      
      void setup()  
      { 
        gw.begin();
      
      #ifdef DEBUG
        Serial.begin(115200);
        Serial.println("Light Sensor Test"); Serial.println("115200");
      #endif
      
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Inside weather conditions", "1.0");
      
        /* Only presenting the sensors if they're available */  
        if (bmp.begin()) {
          gw.present(CHILD_ID_BARO, S_BARO);
        }
      #ifdef DEBUG
        else {
          Serial.println( 'Barometer not found' );
        }
      #endif
      
        if(!tsl.begin())
        {
      #ifdef DEBUG
          /* There was a problem detecting the ADXL345 ... check your connections */
          Serial.print( "Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!" );
      #endif
       //    while(1);
        } 
        else {
      #ifdef DEBUG
          /* Display some basic information on this sensor */
          displaySensorDetails();
      #endif  
          /* Setup the sensor gain and integration time */
          configureSensor();
          gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); 
        }
      
        // 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);
        gw.sendBatteryLevel( 100 );
      }
      
      void loop()      
      {  
        delay(dht.getMinimumSamplingPeriod());
      
        float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;
        float temperature = bmp.readTemperature();
        
        int forecast = sample(pressure);
        
      #ifdef DEBUG
        float dhtTemperature = dht.getTemperature();
        Serial.print("Temperature = ");
        Serial.print(temperature);
        Serial.println( " *C" );
        Serial.print("Pressure = ");
        Serial.print(pressure);
        Serial.println(" hPa");
        Serial.print("Forecast = ");
        Serial.println(weather[forecast]);
      
        Serial.print( "Dht Temp: " );
        Serial.print(dhtTemperature);
        Serial.println( " *C" );
      #endif
      
        if (isnan(temperature)) {
      #ifdef DEBUG    
            Serial.println("Failed reading temperature from DHT");
      #endif
        }
        else if (temperature != lastTemp) {
          lastTemp = temperature;
          gw.send(msgTemp.set(temperature, 1));
      #ifdef DEBUG    
          Serial.print("T: ");
          Serial.println(temperature);
      #endif    
        }
        
        float humidity = dht.getHumidity();
        if (isnan(humidity)) {
      #ifdef DEBUG
        Serial.println("Failed reading humidity from DHT");
      #endif  
        } 
        else if (humidity != lastHum) {
            lastHum = humidity;
            gw.send(msgHum.set(humidity, 1));
      #ifdef DEBUG      
            Serial.print("H: ");
            Serial.println(humidity);
      #endif      
        }
        
         sensors_event_t event;
      
       // maybe a delay between the sensor readings
        tsl.getEvent(&event);
       
        /* Display the results (light is measured in lux) */
        // if (event.light) { // removed test to see if we get a 0 meeting during the evening and night.
      #ifdef DEBUG
          Serial.print(event.light); 
          Serial.println(" lux");
      #endif
          if ( event.light != lastLightLevel ) {
            gw.send(lightMsg.set((uint16_t)event.light));
            lastLightLevel = event.light;
          }
      /*  } // removed test to see if we get a 0 meeting during the evening and night.
        else
        {
          // If event.light = 0 lux the sensor is probably saturated and no reliable data could be generated! 
       #ifdef DEBUG
         Serial.println("Sensor overload");
       #endif  
        }
        */
        
        if (pressure != lastPressure) 
        {
          gw.send(pressureMsg.set(pressure, 0));
          lastPressure = pressure;
        }
      
        if (forecast != lastForecast)
        {
          gw.send(forecastMsg.set(weather[forecast]));
          lastForecast = forecast;
        }
      
       gw.sleep(SLEEP_TIME); //sleep a bit
      }
      
      
      float getLastPressureSamplesAverage()
      {
      	float lastPressureSamplesAverage = 0;
      	for (int i = 0; i < LAST_SAMPLES_COUNT; i++)
      	{
      		lastPressureSamplesAverage += lastPressureSamples[i];
      	}
      	lastPressureSamplesAverage /= LAST_SAMPLES_COUNT;
      
      	return lastPressureSamplesAverage;
      }
      
      
      
      // Algorithm found here
      // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
      // Pressure in hPa -->  forecast done by calculating kPa/h
      int sample(float pressure)
      {
      	// Calculate the average of the last n minutes.
      	int index = minuteCount % LAST_SAMPLES_COUNT;
      	lastPressureSamples[index] = pressure;
      
      	minuteCount++;
      	if (minuteCount > 185)
      	{
      		minuteCount = 6;
      	}
      
      	if (minuteCount == 5)
      	{
      		pressureAvg = getLastPressureSamplesAverage();
      	}
      	else if (minuteCount == 35)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change * 2; // note this is for t = 0.5hour
      		}
      		else
      		{
      			dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value.
      		}
      	}
      	else if (minuteCount == 65)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) //first time initial 3 hour
      		{
      			dP_dt = change; //note this is for t = 1 hour
      		}
      		else
      		{
      			dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 95)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 1.5; // note this is for t = 1.5 hour
      		}
      		else
      		{
      			dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 125)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		pressureAvg2 = lastPressureAvg; // store for later use.
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 2; // note this is for t = 2 hour
      		}
      		else
      		{
      			dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 155)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 2.5; // note this is for t = 2.5 hour
      		}
      		else
      		{
      			dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value
      		}
      	}
      	else if (minuteCount == 185)
      	{
      		float lastPressureAvg = getLastPressureSamplesAverage();
      		float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
      		if (firstRound) // first time initial 3 hour
      		{
      			dP_dt = change / 3; // note this is for t = 3 hour
      		}
      		else
      		{
      			dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value
      		}
      		pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past.
      		firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop.
      	}
      
      	int forecast = UNKNOWN;
      	if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval.
      	{
      		forecast = UNKNOWN;
      	}
      	else if (dP_dt < (-0.25))
      	{
      		forecast = THUNDERSTORM;
      	}
      	else if (dP_dt > 0.25)
      	{
      		forecast = UNSTABLE;
      	}
      	else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05)))
      	{
      		forecast = CLOUDY;
      	}
      	else if ((dP_dt > 0.05) && (dP_dt < 0.25))
      	{
      		forecast = SUNNY;
      	}
      	else if ((dP_dt >(-0.05)) && (dP_dt < 0.05))
      	{
      		forecast = STABLE;
      	}
      	else
      	{
      		forecast = UNKNOWN;
      	}
      
      	// uncomment when debugging
      #ifdef DEBUG
      	Serial.print(F("Forecast at minute "));
      	Serial.print(minuteCount);
      	Serial.print(F(" dP/dt = "));
      	Serial.print(dP_dt);
      	Serial.print(F("kPa/h --> "));
      	Serial.println(weather[forecast]);
      #endif
      	return forecast;
      }
      
      posted in Development
      TheoL
      TheoL
    • RE: Best dimmable countertop lights?

      If ordered some DUAL white ledstrips. They've promissed me that you can mix them in to warmer light. Made be something for you.

      Will play with them and report my findings here.

      posted in Hardware
      TheoL
      TheoL
    • RE: another relay problem....

      @martinhjelmare I already had a gut feeling that the gateway doesn't generate message's like this. Because it was designed to be a gateway with as less logic in it as possible 😉 Glad you cleared that one.

      posted in Home Assistant
      TheoL
      TheoL
    • RE: 💬 Relay

      @mfalkvidd I'm in an older version I discovered. Ran across more small differences.

      posted in Announcements
      TheoL
      TheoL
    • RE: Can someone check my code? Please :)

      I would strip the complete sketch and leave only the button part in it. That way it's much easier to detect if there's any mistake. It's really hard to help you with a sketch if this size.

      You could try to give the debouncer a higher interval, e.g.:
      debouncer2.interval(25);

      posted in Development
      TheoL
      TheoL
    • RE: arduino promini 3.3V , out put digital.

      @sundberg84 Would a logical level converter help? I want to do the same in the near future.

      posted in Hardware
      TheoL
      TheoL
    • RE: Receiving date/time from sensor

      Actually I would love to see a new sensor type for setting an alarm time.

      posted in Feature Requests
      TheoL
      TheoL
    • RE: 💬 MySensors Library - v2.x

      It might be me, but when I declare the receiveTime handler is stated in the documentation:

      bool receiveTime(uint32_t ts);

      I get an error. it should be:

      void receiveTime(uint32_t ts) {
      }

      at least in the latest MySensors version

      posted in Announcements
      TheoL
      TheoL
    • RE: Has anyone tried software reset of an Arduino?

      I used it in a test sketch.

      void(* resetFunc) (void) = 0; //declare reset function @ address 0
      
      void loop() {
        if ( Serial.available() ) {
          // read the incoming byte:
          char incomingByte = Serial.read();
      
          // say what you got:
          Serial.print("I received: ");
          Serial.println(incomingByte, DEC );
          if ( incomingByte == 115 ) {
            Serial.println( "Resetting??" );
            gw.wait(50 ); // give serial some time to complete it's printing
            resetFunc();  //call reset
          }
        }
        gw.process();
      }
      

      And the Serial output is:

      Resetting??
      send: 17-17-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
      send: 17-17-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
      send: 17-17-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
      read: 0-0-17 s=255,c=3,t=6,pt=0,l=1,sg=0:M
      sensor started, id=17, parent=0, distance=1
      

      So on my Uno it seems to wok fine. Looks promissing

      posted in Development
      TheoL
      TheoL
    • RE: FTDI/Serial or USB?

      I'm no expert. But if you don't want to us the USB as power supply (is that possible?) I'd go for FDTI. Save space and hardware. And if you're node supports OTA, you're probably never gonna connect the USB of FDTI after the initial software is loaded anyway.

      posted in Hardware
      TheoL
      TheoL
    • Overloading the Arduino delay

      I'm not sure if this is possible. But it would help a lot of people, if MySensors would overload the Arduino delay and replace it with a MySensors wait implementation.

      I'm aware of the fact that this might cause some problems with existing libraries. Because they we're build around the delay function. But these libraries aren't the best anyway.

      Please consider this. Because it'll help a lot of MySensors users.

      posted in Feature Requests
      TheoL
      TheoL
    • RE: MQTT without radio?

      You could try an RS232 Gateway. A forum member made one a couple of months ago.

      I found this article with some links http://forum.mysensors.org/topic/1947/rs485-rs232-serial-transport-class-for-mysensors-org/62

      posted in PiDome
      TheoL
      TheoL
    • RE: MySensors 2.0 startup failure blocks node work

      Dear @Konstantin-Kolesnichenko,

      This behaviour has got nothing to do with the 2.0 version. It's the same in the previous version of MySensors. Node's need communication with the gateway before they can start.

      I'm closing this topic. See https://forum.mysensors.org/topic/4449/how-to-disable-default-node-registration-to-the-gw/2. It's a thread about the same topic.

      posted in Development
      TheoL
      TheoL
    • RE: FTDI/Serial or USB?

      @Samuel235 I think that most of us, have at least one ProMini. So I expect that we all have an FDTI programmer available. Besides that an FDTI programmer isn't that expensive. It might be good to calculate what the return on investment is. How many USB and IC's can you buy for one FDTI programmer?

      posted in Hardware
      TheoL
      TheoL
    • RE: Filter node

      In all honesty mixing rfm69 and nrf24L01+, as @evb, suggests seems to me to be a way that isn't complicated and doesn't acquire any additional coding. I think I'd go that route

      posted in Feature Requests
      TheoL
      TheoL
    • Bug in SenseBenderDefault sketch

      I was wondering why my SenseBender kept reporting every minute, even though the temperature and humidity didn't change.

      It's a minor one. But in the sendTempHumidityMeasurements(bool force) method, the difference is determined by dividing with 100 and not 100.0 this causes a wrong rounding and always reports a difference higher than the treshhold. Resulting in a temperature report every minute. Even though the temperature hasn't changed much.

      corrected code.

      /*********************************************
       *
       * Sends temperature and humidity from Si7021 sensor
       *
       * Parameters
       * - force : Forces transmission of a value (even if it's the same as previous measurement)
       *
       *********************************************/
      void sendTempHumidityMeasurements(bool force)
      {
        bool tx = force;
        
        si7021_env data = humiditySensor.getHumidityAndTemperature();
        float oldAvgHum = raHum.getAverage();
        
        raHum.addValue(data.humidityPercent);
        
        float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0); // <-- fixed
        float diffHum = abs(oldAvgHum - raHum.getAverage());
      
        Serial.print(F("TempDiff :"));Serial.println(diffTemp);
        Serial.print(F("HumDiff  :"));Serial.println(diffHum); 
      
        if (isnan(diffHum)) tx = true; 
        if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true;
        if (diffHum >= HUMI_TRANSMIT_THRESHOLD) tx = true;
      
        if (tx) {
          measureCount = 0;
          float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0;
           
          int humidity = data.humidityPercent;
          Serial.print("T: ");Serial.println(temperature);
          Serial.print("H: ");Serial.println(humidity);
          
          gw.send(msgTemp.set(temperature,1));
          gw.send(msgHum.set(humidity));
          lastTemperature = temperature;
          lastHumidity = humidity;
        }
      }
      

      ps. I'm sorry I don't have a github account.

      posted in Bug Reports
      TheoL
      TheoL
    • RE: Powering a sensor with digital out

      @hozze

      try this

      void loop()
      {
        digitalWrite(SENS_ON, HIGH);
      
        delay(10000); // To check the input voltage on pin 2
      // byTheo 10 seconds seems to be a bit much??
      
        int moisture = analogRead(VAL_PROBE); //measuring the moisture
      
        digitalWrite(SENS_ON, LOW); // turn it off
      //byTheo you didn't turn the pin off
      
      
        send(msg.set(moisture));  // sending the data 
        sleep(10000);  // sleeping for 10 sec
      // byTheo 1000 s isn't 10 secs 
      }
      posted in Development
      TheoL
      TheoL
    • RE: Adding local sensor to NodeMCU gateway

      @Wodian I've remove your SSID and password from the sketch. You probably didn't want everybody to have those.

      posted in Hardware
      TheoL
      TheoL
    • RE: Robot mower ignores the rain, MySensors to the rescue!

      It's a bit too late over here, will look at it tomorrow. Your own startup cool!! What is your business?

      posted in Domoticz
      TheoL
      TheoL
    • RE: Azure IoT ?

      @Martin-Tellblom Take a look at https://evothings.com/is-it-possible-to-secure-micro-controllers-used-within-iot/ article.

      posted in Controllers
      TheoL
      TheoL
    • RE: Tool for static analysis of memory usage

      @mfalkvidd lots of ram is what we like. In case you're interested. This is a good i2c slave http://jamesreubenknowles.com/arduino-i2c-1680 tutorial and this is a great explanation of the i2c protocol

      How I2C Communication Works and How To Use It with Arduino – 09:57
      — How To Mechatronics

      posted in Development
      TheoL
      TheoL
    • RE: RS485 & ENC28J60 gateway

      I'm not sure, but I think it depends on whether or not the code is using large local variables. At some point it's no longer possible to claim a space on the heap, because the free heap space is to fragmented

      I have one Arduino that has a sketch with the same warning, but it's been running for a long time. No problems so far. But I've declared most of the variables global.

      This is AdaFruits article on the topic:
      https://cdn-learn.adafruit.com/downloads/pdf/memories-of-an-arduino.pdf

      posted in Hardware
      TheoL
      TheoL
    • RE: Does Domoticz Support scene controllers?

      @drock1985 Hello my friend,

      Domoticz support scenes, so you should be able to add a scene controller. I'm not 100% sure how @Awi made the controller, but if I'm not mistaken he runs Domoticz as well.

      So the trick is, creating a controller which is actually nothing more than a multiple switch node. In Domoticz you should see the individual switches an you should be able to add each individual switch.

      From there on it's just a matter of connecting the right scene to the right button in Domoticz and you're good to go.

      posted in Domoticz
      TheoL
      TheoL
    • RE: Check if the value changed since last time

      I think that @Yveaux refers to my generic threshold library (github). It really makes it easy to add sensors and reporting their values to the gateway.

      posted in Development
      TheoL
      TheoL
    • RE: RF Nano = Nano + NRF24, for just $3,50 on Aliexpress

      @ncollins That is a nice board indeed. I haven't checked because I will order some things after dinner. For me it is a must to keep the arduino Nano footprint. So I can replace the nano and nrf in some of the projects I already built.

      posted in Hardware
      TheoL
      TheoL
    • RE: [SOLVED] Error sending switch command

      @raptorjr Try changing the delay in your loop to a wait statement.

       wait(SLEEP_TIME); // delay(SLEEP_TIME);
      

      When you use a delay the Arduino completely delays your sketch meaning no incomming events can be processed. When you use a MySensors wait. The Arduino doesn't delay your sketch and will be able to handle incomming messages.

      posted in Domoticz
      TheoL
      TheoL
    • RE: upgrading to 2.0

      @parachutesj Today I had to upgrade to MySensors 2.0 as well. As @sundberg84 you should use a MS 2.0 gateway. MS 2.0 sketched don't work with an older gateway, as I've experienced. And it seems to be logic to update the repeater nodes as well.

      So far I haven't update any of the nodes and seems to work fine. But I'll be upgrading them a.s.a.p.

      Hope this helps you.

      posted in Development
      TheoL
      TheoL
    • RE: RF Nano = Nano + NRF24, for just $3,50 on Aliexpress

      So I know a lot of people switched over to Tasmota and other ESP enabled solution. Just wanted to share my experience of Today and couldn't really find another topic.

      As of Today I finally have fiber glass internet. Something I looked forward to and feared at the same time. I was looking forward to the speed. But not in getting everything working with a new router. I'll keep it short.

      1. Telephone - worked immediately no problems at all
      2. Wifi - Hard time finding the new ssid. But I lucked out. After a call with KPN, I found out the new router copied the ssid and password from the old router
      3. Getting home automation and Ikea tradfri gateway running. I use TP-link power line to connect all ethernet devices by wire. But I always assumed you couldn't use a switch connected to a tp-link. Oh boy I was wrong. It worked.
      4. The new router differs from the old one, in the way that it does not have a separate output for the tv receiver, you can connect the receiver just to any ethernet port you have available. So I hooked the reciever up to a tp-link and running.
      5. Sonos didn't work. I needed to connect only one with ethernet to my router en reenter the SSID and passwd. But then Sonos was back in the air.

      Now imagine of you have a dozen of ESP as sensors or actuators. And the new router would not have copied the SSID and password? Then I would manually have to set the new ssid and password for each ESP. When I realized this, it came to me how simple MySensors is in use. Thankful that I discovered it. And thankful to you all for creating this great sensors network

      posted in Hardware
      TheoL
      TheoL
    • RE: Domotiocz + Rain gauge

      @AWI Would love to join forces with you my friend. I can make a Fritzing 😉

      posted in Domoticz
      TheoL
      TheoL
    • RE: Starting my PC with a 3.3v arduino pro mini?

      @kiesel said in Starting my PC with a 3.3v arduino pro mini?:
      It wouldn't be logic to put it between the opto coupler and the Arduino pin. Because it's purpose is to separate the 2 circuits. Hence protecting both circuits. At least that's how I understand how Opto Couplers work. The opto coupler connects 2 circuits trough light no physical contact.

      posted in Development
      TheoL
      TheoL
    • My Wemos D1 mini adventures - Interrupts on pins D3 and D4

      Hi all,

      Recently I started to experiment with the Wemos D1 mini as a MySensors node, with a NRF24L01+ radio. As most wouldn't go this route, since it has built in WiFi. I did, because for one WiFi was not available for the particular node I'm developing. And second I don't really like my HA to run on WiFi. There are many reasons I have for this. But my main concern is the amount of time it takes to reconfigure all your nodes when the ssid and or password on your router have changed. But let's not start a topic on this. In this topic I just wanted to share some tips and tricks I discovered which some were hard to find on the internet and others I came up with my own solution. I'll keep adding tips and tricks to this topic if I discover new ones.

      The Mini D1 doesn't like it when you declare an interrupt handler like you'd normally do.

      volatile bool interruptReceived= false;
      
      void handleInterrupt() {
        interruptReceived = true;
      }
      

      If you're lucky it compiles. But it will not work. You'll receive a strange bootloader error and the Mini will not boot. The reason for this is that the Mini expects handlers to be stored in the IRAM space. Just add a compiler directive and your interrupt handler will work just fine.

      volatile bool interruptReceived= false;
      
      ICACHE_RAM_ATTR void handleInterrupt() {
        interruptReceived = true;
      }
      
      void setup() {
          pinMode( interruptPin, INPUT_PULLUP );
          attachInterrupt(digitalPinToInterrupt( interruptPin ), handleInterrupt, FALLING ); 
      

      Be carefull with using interrupts on D3 and D4

      So the ESP2866 does a lot of funky things during bootup. It will pull some pins HIGH and LOW to check if it should go into program mode or not. It probably uses it for more reasons, but I'm by no means an ESP expert. The D3 and D4 pins are pulled up high by the Esp, with a - I believe - 10K resistor. Whenever you connect anything to it, that will cause these pins to be high during booting, the Wemos will not finish the boot mode and your sketch is never loaded.

      I wanted to attach an MCP23017 port extender to my Wemos and use the interrupt to refresh the values. So I didn't need to poll the MCP23017 all of the time and kept CPU time available for other tasks. The problem with this, is that the MCP23017 pulls it's interrupt pin HIGH when there's no interrupt - which is always the case when the chip power's up. So connecting the interrupt pin to D3 or D4 caused my Mini D1 to not exit boot mode.

      I could have simply used D3 and D4 as SDA and SCL pins for the I2c communications and use D1 and D2 as interrupt pins. But not all libraries like that. So the easiest way to get around it was a simple and cheap hardware solution. I connected a diode (doesn't matter which one you take. Just take a low 1N400x one) and that did the following:
      The HIGH value of the MCP's interrupt pin is blocked by the diode. When the MCP pulls the interrupt pin low current can flow between the interrupt pin (INPUT_PULLUP) on the Wemos Mini and the MCP's interrupt pin. This made sure the MCP is never able to pull the pin on the Mini high. And the problem was actually solved - easy peasy. I can use D3 and D4 as interrupt pins.

      Here's the schematic. In my case I use the mirror mode on the MCP's interrupts. So I only need to connect one of the MCP23017's interrupt pins to the Wemos.
      Schermafbeelding 2021-10-09 om 15.49.36.png
      I also run the MCP23017 on 3.3V so it's the same as the Wemos mini.

      posted in Hardware
      TheoL
      TheoL
    • RE: relay with delay feature

      I use something like this

      unsigned long nextEvent;
      
      void setup() {
        nextEvent = millis() + ( 5 *  60 + 1000); // 5 hours
      }
      
      void loop() {
        if ( nextEvent <= millis() ) {
          // do reading
          nextEvent = millis() + ( 5 *  60 + 1000); // 5 hours
        }
      
        gw.wait( 500 ); // or whatever you want.
      }
      

      But that's just the algorithm

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: What's the best way to set up lots of binary sensors on a single Arduino?

      @Melih-Kulig Don't forget to order some 100uf capacitors, if you don't have them. It helps getting the NRF24L01+ working smoothly

      posted in Development
      TheoL
      TheoL
    • RC-SPC1K capacitive rain sensor

      Did any one ever experimented with this rain sensor https://www.radiomodules.eu/en/component/62/capacitive-rain-sensor?

      alt text

      alt text

      It doesn't oxidize like the normal rain sensors and has a builtin temperature sensor and heater. The heating seems like a good thing for during the winters. So you can melt away any snow. Although I assume you have to turn it on whenever you measure any rain, so the water can vaporize. Because I think that might give a false positive. But that would be something to test.

      On the product site there's also the schematics for an Arduino Uno Shield and a sketch you can upload to operate the Sensor. I didn't have time yet to check those out.

      I think the sensor is also used in a lot in the more expensive commercial rain sensors. Although they only trigger a rain detection signal not the amount of falling rain. According to the production site, you should also be able to detect the amount of rain, which is indicated by the capacitance you measure on the sensor.

      Schermafbeelding 2021-10-22 om 14.41.31.png

      I'm pretty sure Kemo uses this sensor in their product.

      alt text

      The RC-SPC1K seems like a decent sensor for rain detection. But I can't find many Arduino projects. So wondering if any one of you has any experience with this sensor. Because a commercially available solution costs 50 euro. Although the sensor itself also costs 18 euros, 9 for the sensor and 9 shipping costs. And you still need some components - opto coupler and resistor - to hook it up to the Arduino and a water resistant casing.

      I can imagine more projects then only a rain sensor for closing the sunscreens. Maybe something like a small water basin for birds during those hot summer days, that gets refilled when it's empty.

      posted in Hardware
      TheoL
      TheoL
    • RE: Has anyone made a 2 or 4 channel relay , and is that worked correct ?

      @Reza Since it's already a long thread I didn't want to read everything. But just a stupid question. Did you measure the relay? It would be my starting point. Because if that's not working, the rest will not work either.

      Also I once had a relay connected to a ProMini 5V, which I powered over FDTI. But I forgot to setup my FDTI programmer to 5V. By this the Arduino didn't have enough power to switch on the relay. It took me a while before I discovered that, because the NFR24L01+ antenna was working just fine.

      Before I add an external power source to an Arduino, I always feed the Arduino through the USB of my computer. In my experience it has always supplied enough power for controlling a relay state. You could try it, just to eliminate power supply issues.

      Just a few tips for you my friend. I hope you'll be able to find the cause of your troubles really soon.

      Take care.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: help . power supply and add motion sensor to vera controller

      I can only tell you how I deal with question 1.

      I hook a 5V cell phone charger to the arduino. I connect the ground of the adapter to the ground of the arduino. The +5V from the adapter needs to be connected to the raw or Vin pin of the Arduino. It depends on how the pin is labeled. Some arduino use raw for the labels others use VIn.

      I always power the motion sensor directly from the +5V of the adapter, not from the vcc of the arduino. This is the easiest way without using extra power regulators.

      posted in My Project
      TheoL
      TheoL
    • RE: Your workshop :)

      @Samuel235 There is a thread on a Dutch forum which is describing the best tool for hobbyists, not the most expensive. You'll have to use google translator. But I've been told it's a good list.

      http://knutselblog.tweakblogs.net/blog/12398/best-buy-guide-voor-de-knutselaar

      posted in General Discussion
      TheoL
      TheoL
    • RE: Has anyone made a 2 or 4 channel relay , and is that worked correct ?

      @Reza what happens if you connect pin 3 to in2 and pin 4 to in1? That's the easiest way to check your relay. I'm not an expert. Buy my guess is, that if there's a power problem, you wouldn't be able to control any one of the relays. But maybe someone with more knowledge will be able to confirm or deny that,

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: Physical mood light color and brightness selector based on LCD touchscreen (with demo video)

      I absolutely love this project. And I wouldn't call it needlessly at all. Great job and thanx for sharing.

      posted in My Project
      TheoL
      TheoL
    • RE: Motor Control with S_cover

      I think you can find the answer in this topic:

      http://forum.mysensors.org/topic/2874/i-am-not-able-to-stop-the-blinds-motor-once-the-first-command-is-sent

      posted in General Discussion
      TheoL
      TheoL
    • RE: Question about sleep until interrupt

      @flopp thank you very much for your quick response!

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: Gesture controlled Floor Lamp

      @hek done!

      posted in My Project
      TheoL
      TheoL
    • RE: Raspberry Pi is frustrating and I wanted to vent

      @micah Don't get me started. I once spent an entire Saturday setting up a Pi. But it kept throwing errors after I've setup the wifi. Do you know what the problem was????? On the original Raspbian image there are two DHCP clients installed. They conflicted with each other. Can you imagine that? Two different pieces of software performing the same task, being installed on an original Raspbian image?

      Of course, I can laugh about it now. But that weekend, I was really pssd off. Lol.

      posted in General Discussion
      TheoL
      TheoL
    • RE: Has anyone made a 2 or 4 channel relay , and is that worked correct ?

      @Reza I'm not sure. But if I understand you correctly, my gut feeling is that your pin 3 on the Arduino is broken (or not correctly setup in the code). Could be a power issue, but I seriously doubt it.

      Just try the blink sketch example. Hookup an LED to pin 3 and change the BLINK_LED pin to pin 3 instead of 13. That way you can check if pin 3 is working correctly.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: BMP280 + I2C

      @marekd Welcome on the forum. And thank you for sharing your sketch. Would love to see some pictures of your irrigation controller.

      posted in My Project
      TheoL
      TheoL
    • RE: Alternatives for nRF24L01+ ?

      @gmccarthy you do now that MySensors also supports RFM69 right? I runs on a lower frequency. And if I remember it correctly from high school, a lower frequency has a longer range. But there are people here that have more knowledge of that.

      http://www.aliexpress.com/item/RFM69HC-20dBm-RFM69HW-RFM69/32344130193.html?spm=2114.30010308.3.2.VppMGg&ws_ab_test=searchweb201556_9,searchweb201602_4_301_10034_10033_507_10032_508_10020_10017_10005_10006_10021_10022_401_10018_10019,searchweb201603_1&btsid=8bf462de-90bd-45b8-b7a5-41c292a00da3

      Much cheaper and more versatile than Xbee.

      Besides. If it isn't a hardware problem. You might end up with the same problems when you use Xbee. Just a thought though.

      posted in General Discussion
      TheoL
      TheoL
    • RE: Has anyone made a 2 or 4 channel relay , and is that worked correct ?

      @Reza In that case, since it's so predictable, it's a bug in your sketch. At least that's what I think. Unfortunately I have busy weekend and week ahead, so I don't think I have the time to investigate your code. I'm really sorry. I have to check if I have a spare relay, and if I can find one I'm willing to check your sketch. But as mentioned before I can't promise that.

      Hopefully others might be able to help you sooner. Take care.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: Combined Sensor RepeaterNode and sleep(SLEEP_TIME) in MySensors 2.0.0

      @sincze I've created a library for this purpose. It's not completely tested, so there might be some bugs in it. It's a sort of buy me a beer if you like it library ;-). And yeah I know implementation code should be put in .cpp. Will do that when I'm done testing.

      /**
       * Library ThresholdUtil.h 
       * 
       * Copyright (c) ByTheo
       * 
       * Description:
       *   This library handles all interval based reading of simpels who's values you want to send on a periodical basis. This means that at least every given interval number of readings
       *   the callback handler for that sensor is being called. If howver the value of the sensors goes past the defined threshold value of that sensor, it will call the callbackhandler
       *   the soon as it detects the threshold. This library was based upon the Sensbender Micro example Sketch.
       * 
       * Useage:
       *   1. register each individual sensor to the library with the registerThresholdedSensor() function in your Sketchs setup() function. See comments in code.
       *   2. implement a SensorValueRequestedCallback() function in your Sketch
       *   3. Implement a SensorValueTransmission() function in your sketch 
       *   4. Call checkThresholdedSensors from within your loop as much as you can.
       * 
       * History
       *   August 1st 2016 - Initial version
       * 
       * Design decisions:
       * - don't put sensro specific code into this library (separation of concern). The main sketch is responsible for the retrieval of sensor values.
       * - Don't use C++ is absorps too much resources. PLain old C is more resource efficient
       * - Don't implement memory management. Freeing up is unnecessary because we don't need to support it. Sensors shouldn't be dynamic in a Sketch
       * 
       * 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.
       *
       *******************************
      */
      
      #ifndef THRESHHOLD_UTIL_H
      #define THRESHHOLD_UTIL_H
      
      /**
       * Declartion of the type definition used by the library
       */
      typedef enum { TEMPERATURE_SENSOR, HUMIDTY_SENSOR, LIGHTLEVEL_SENSOR, CUSTOM_SENSOR } ThreshHoldedSensorType; // The different kind of sensor type for which you can store values. You can extend this enum to your likings or do a pus request on GITHUB
      typedef void (*SensorValueRequestedCallback)( uint8_t aSensorId, ThreshHoldedSensorType aType, float *value ); // Callback handler which is called whenever the library needs a new value for a specific sensor
      typedef void (*SensorValueTransmission)( uint8_t child_id, uint8_t sensor_id, ThreshHoldedSensorType sensor_type, float value ); // Callback handler called whenever the library notices that the value of a specific sensor has to be send to the gateway
      
      /**
       * Structure used by the library for administrating the variabels for a specific sensor. The library uses a linked list of structures.
       */
      typedef struct ThresholdedSensorStruct {
        uint8_t child_id;
        uint8_t sensor_id; // unique id for the sensors for which we hold the values
        ThreshHoldedSensorType sensor_type;
        float      threshHold;
        uint8_t    forcedTransmissionInterval;
        uint8_t    measureCounter;
        float      lastValue;
        unsigned long lastChecked;
        uint8_t    readingInterval;
        ThresholdedSensorStruct *nextNode;
      } *thssPtr;
      
      /**
       * The root node of the linked list of ThresholdedSensorStructs
       */
      thssPtr thresHoldedSensorsrootNode = NULL;
      
      /**
       * Mehthod for adding a sensor who's value needs to be monitored.
       * child_id: The id of child for which the sensor is monitored. It's only for the convenience of the main sketch and isn't used by the library 
       * sensor_id: An id of a sensor. You can use this to group different sensor values if they come from the same sensor. Some sensors like the HDT11 or the BMP180 report multiple sensor types
       *            The main sketch should use this to request the values of such kind of sensors just once and not multiple times for each request for value made by the library
       * sensor_type: Indicates what kind of values are being monitored. Use this to determine what kind of value is required when dealing with multi purpose sensors
       * theshHold: The value of threshold is indicates how much the new value needs to differ from the last send value before it triggers a resend.
       * readingInterval: The amount of seconds the library waits before it request a new value for this sensor
       * forcedTransmissionInterval: The amount of measurements without retransmissions, before a retransmission is triggered. In other words of the values of a sensor don't extend the threshold, a retransmission
       *            is triggered of this given amount of readings.
       */
      void registerThresholdedSensor(   uint8_t child_id, uint8_t sensor_id, ThreshHoldedSensorType sensor_type, float threshHold, uint8_t readingInterval, uint8_t forcedTransmissionInterval ) { // single sensor
        thssPtr aSensor = (ThresholdedSensorStruct*)malloc(sizeof(struct ThresholdedSensorStruct));
        aSensor->sensor_id = sensor_id;
        aSensor->child_id = child_id;
        aSensor->sensor_type = sensor_type;
        aSensor->threshHold = threshHold;
        aSensor->forcedTransmissionInterval = forcedTransmissionInterval;
        aSensor->measureCounter = forcedTransmissionInterval - 1; // correct initialzation
        aSensor->lastValue = 0;
        aSensor->readingInterval = readingInterval;
        aSensor->lastChecked = millis(); // not checked
        aSensor->nextNode = NULL;
        if ( thresHoldedSensorsrootNode == NULL ) {
          thresHoldedSensorsrootNode = aSensor;
        }
        else {
          thssPtr node = thresHoldedSensorsrootNode;
          while ( node->nextNode != NULL ) {
            node = node->nextNode;
          }
          node->nextNode = aSensor;
        }
      }
      
      /**
       * Supportive method for the checkThresholdedSensors routine. It checks if the value of the given sensors needs to be read according to the given timeStamp.
       * The given SensorValueRequestedCallback is used to query the values of a sensor. The given SensorValueTransmission is called when a (re)transmisson for the value
       * of the given Sensor is required.
       * This method contains the actual logic of the library.
       */
      void checkIndividualThreshHoldedSensor( thssPtr aSensor, unsigned long timeStamp, SensorValueRequestedCallback aCallBack, SensorValueTransmission transmissionCallback ) {
        // determine whether node should be checked in first place!!!
        if ( aSensor->lastChecked <= timeStamp ) {
          aSensor->measureCounter++;
          float value;
          aCallBack( aSensor->sensor_id, aSensor->sensor_type, &value );
          aSensor->lastChecked = timeStamp + ( (unsigned long)aSensor->readingInterval * 1000 );
      
          float diffMeasurement = abs( aSensor->lastValue - value );
      
          bool sendValues = false;
      
          if ( diffMeasurement >= aSensor->threshHold || aSensor->measureCounter == aSensor->forcedTransmissionInterval ) { // transmit value
            aSensor->lastValue = value;
            aSensor->measureCounter = 0;
            transmissionCallback(  aSensor->child_id,  aSensor->sensor_id, aSensor->sensor_type, aSensor->lastValue );
          }
        }
      }
      
      /**
       * Checks all defined sensors on: if they need to be checked and if their value needs to be send to the gateway:
       * aCallBack: pointer to a function that can determine the sensors current value (logic should be implemented in the main sketch, separation of concern)
       * transmissionCallback: pointer to the function the deals with sending a value of a sensor to the gateway (logic should be implemnted by the main sketch, separation of concern)
       */
      void checkThresholdedSensors( SensorValueRequestedCallback aCallBack, SensorValueTransmission transmissionCallback ) {
        unsigned long timeStamp = millis();
        if ( thresHoldedSensorsrootNode != NULL ) {
          thssPtr node = thresHoldedSensorsrootNode;
          checkIndividualThreshHoldedSensor( node, timeStamp, aCallBack, transmissionCallback );
          while ( node->nextNode != NULL ) {
            node = node->nextNode;
            checkIndividualThreshHoldedSensor( node, timeStamp, aCallBack, transmissionCallback );
          }
        }
      }
      
      #endif
      

      In your setup code you add:

        registerThresholdedSensor( CHILD_ID_TEMP, DHT_SENSOR, TEMPERATURE_SENSOR, 0.5, 30, 20 ); // every 30 seconds report at least every 10 minutes
        registerThresholdedSensor( CHILD_ID_HUMIDITY, DHT_SENSOR, HUMIDTY_SENSOR, 1.0, 60, 10 ); // every 60 seconds
      

      Add this line in the presentation method:

        checkThresholdedSensors( checkThrsedSensor, reportSensorValue ); // Necessary call for intializing ThresholdUtil
      

      Now implement the call back function's.

      float lastHumidity;
      
      /**
       * Callback method called by the Threshold util library whenever the library needs a new value for a specific sensor
       */
      void checkThrsedSensor( uint8_t aSensorId, ThreshHoldedSensorType aType, float *value ) {
        if ( aSensorId == DHT_SENSOR  ) {
          if ( aType == TEMPERATURE_SENSOR ) {
            lastHumidity = dht.readHumidity();
            *value = dht.readTemperature();;
          }
          else {
            // no need to read Humidity. We just read it when we read temp value. Haven't found a decent solution to support this from within the library
            *value = lastHumidity;
          }
        }
      }
      /**
       * Threshholded sensor's value needs to be reported to the gateway.
       */
      void reportSensorValue( uint8_t child_id, uint8_t sensor_id, ThreshHoldedSensorType sensor_type, float value ) {
        if ( child_id == CHILD_ID_TEMP ) {
          send( TemperatureMsg.set( value, 1), true );
        }
        else {
          send( HumidityMsg.set( value, 1), true );
        }
      

      And add this into your sketches main loop:

          checkThresholdedSensors( checkThrsedSensor, reportSensorValue );
      

      The library will only report changes when temperature differs 0.5 degrees from last send values. Or if the threshold isn't reached it sends the temperature every 5 minutes. It's the same for humidity, but that has a threshold of 1 %.

      Hope this helps. I will put the code on my github with examples when I've tested it enough.

      posted in My Project
      TheoL
      TheoL
    • RE: Meetup in the Netherlands - Saturday July 30th, in Breda!

      @scalz I would love to meet you. Maybe next time, we can do it in Belgium. 😉

      posted in General Discussion
      TheoL
      TheoL
    • RE: Has anyone made a 2 or 4 channel relay , and is that worked correct ?

      @Reza The Sketch is working? If so great. I wasn't sure, because I wasn't able to test it. I can't tell what was wrong. I just rewrote it. In theory it's possible to add 6 relays this way. This is because pin 9 is in use by the NFR24L01+ antenna. You could use pin 2 as a starting pin (you don't need to connect the radio to pin 2, because it's not using it). So you might be able to add up 7 relays with this sketch.

      Because you also have pin 0 + 1 and the 6 analog pins, you can add up to 15 relays, but you'll need a different Sketch for this. Just let me now if you can get it to work with the max of 7 relays.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: DS18B20 API 2.0

      Nice project!

      posted in My Project
      TheoL
      TheoL
    • RE: Meet in Malmö, Summer 2016?

      It seems like you all had a great time. Hopefully we can say the same after the 30th of July.

      posted in General Discussion
      TheoL
      TheoL
    • RE: Has anyone made a 2 or 4 channel relay , and is that worked correct ?

      @Reza Glad that I could help. I was just thinking. I've added a wait in between the presentation of the relays childs to the gateway. Maybe that made the difference. Anyway good luck and enjoy the greatness of MySensors and it's wonderful community.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: BMP280 SPI Adafruit

      Hi @Matt

      Thanx your for your posting. Hopefully others can benefit from this.

      posted in My Project
      TheoL
      TheoL
    • RE: MySensors Evolution

      Awesome. I'll be using this when I do the MySensor masterclass the 9th of September. Love it!

      posted in General Discussion
      TheoL
      TheoL
    • RE: Trying to build a Door and Sound sensors

      @chatainsim Glad I could help.

      posted in Troubleshooting
      TheoL
      TheoL
    • RE: Web App for Simple Control of my Home Automation kludge

      @sundberg84 Domoticz supports Ajax requests through the REST interface. So we just a slight modification it should be able to work on Domotitcz as well.

      posted in My Project
      TheoL
      TheoL