Multisensor PIR based on IKEA Molgan



  • @tomkxy You can change the sensitivity of the PIR. You have to change the value or R15. See here for a datasheet of the BISS001
    But I do not know whether you should increase or decrease it...?
    If you did not modify your PIR then the PIR will stay high for 30 SEC. What is the period between the false triggers?
    Could it have to do with powering your sensebender from the powersource within the PIR and not directly from the battery?



  • @dynamite I see no clear pattern for the false triggers. Most of the time it is after about 7 minutes. But not strictly. Sometimes more than a half hour.. Well if I would power the sense bender directly from the battery I either would have to use a regulator or remove one of the batteries. Would the PIR still work reliable with about 2.4V? Would it make sense to try a capacitor between the 3V where I power the sense bender from to ground?



  • @tomkxy The range of PIR is 3-5V so most probably 2.4 V will give some trouble.


  • Mod

    @tomkxy you can just use 3 batteries to power the pir and only 2 to power the atmega and radio. Just c
    Use the same ground on them, and tap the arduino power after the second battery.
    I have some pirs running this way and they work just fine!



  • @Yveaux @tomkxy You were one step ahead of me, I was just thinking of that solution. At the moment I am also preparing version 2 of the MOLGAN PIR based on Arduino pro Mini I will check on the false positives as well. But I will feed both the PIR and pro Mini directly from the three batteries.



  • @Yveaux @dynamite Thanks for your suggestion. I followed @Yveaux suggestion and tapped the power for the sensebender after the second battery. It is now working for 2 hours without any false triggers. I will continue the test (for test purposes the sensor is sitting in a room with usually has no movement).


  • Mod

    @tomkxy 👍
    The same setup is working fine for me for quite a long time now!



  • @Yveaux Unfortunately, I still get false triggers. Do you also use a sensebender? Any ideas, what I can try. I tapped into as you suggested to the second battery.


  • Mod

    @tomkxy I have some ProMini's (8Mhz) with regulator bypassed which are 2xAA fed in this way.
    The PIRs are HC-SR501's, also with the regulator removed and 3xAA fed.
    I haven't tested this setup on the Molgan's yet, but assuming the IC's are both BISS0001 I expect results to be identical.

    Here's a picture of my setup:

    0_1465748316875_20160328-160217.jpg

    (Btw. components on the HC-SR501 have been moved to the side to decrease the unit's depth)


  • Mod

    FYI, I measured power comsumption on the Mogan when sleeping with and without regulator.
    The power consumption was significantly less with the voltage regulator, then when directly powered from 3xAAA (regulator removed).
    Therefore, my Molgan hack board design targets to use the PIR with regulator (3xAAA input) and the ATmega+nRF powered directly from 2xAAA.



  • @tomkxy I Will put mine for a test run online tonight in the closet. If no trigger than it should be ok.
    Edit: did something wrong when removing led from pro mini so some debugging is required.... No testing tonight 😢



  • I googled a bit regarding PIR false alarms and found a couple of links. Apart from small bugs - which I have not in the room - air vents could trigger false alarms. Thus, I put back the plastic dome and now have sind 4 hours no false alarms. I am now convinced that my false alarms a most probably triggered by placement and may be air vents.

    http://de.actmeters.com/advice/five-causes-of-pir-false-alarms/
    https://www.youtube.com/watch?v=h0bp91xy5vY
    http://www.hkvstar.com/technology-news/how-to-install-pir-sensor-minimize-the-false-alarm.html


  • Mod

    @tomkxy of course you should always mount the fresnel cover. It focuses the incoming IR on the sensor and forms a barrier. Without the cover the sensor will always be more sensitive and have a much smaller field of view, increasing sensitivity even more.
    If an unmodified Molgan doesn't suffer from false triggers, a modified one also shouldn't.

    This is one more confirmation of the importance of describing your setup accurately 😏



  • I made a couple of additional modifications based on posts here and google results:

    • put a short wait before the node goes to sleep -> based on reports from that forum
    • read the motion pin twice with a small wait in between
    • put a small alu foil between the radio and the PCB -> there are some reports in the internet that RF interference could cause false triggers

    I had a close look at the sensor today and everything looked okay so far. However, I was moving into the room in and out. Let's see what the result tomorrow will be.



  • @TimO said:

    @tomkxy Nice write up! Do you have an idea on the accuracy of the humidity sensor within the case?

    I did some comparison measure regarding temp and humidity. I place an open Sensebender just beside the modded Molgan. The humidity measured at the Molgan was about 11% lower than the humidity measured by the open Sensebender. With respect to temp the Molgans temp was about 6% lower than the temp measured by the open Sensebender.


  • Hero Member

    @tomkxy Thank you for reporting back!



  • Ok, so if I as a complete beginner want to use a the original pir and control the lights all I need to do is:

    Tap the power from the regulator U1 and power a 3.3v mini-pro (keeping the 3 batteries)

    Remove Resistor R17 and connect the solderpoint nearest the chip to an arduino input and I can then basicly be able to run the standard motion sketch ? (After removing the photodiode and bridging the connectors?)

    I can connect the the other solderpoint to an arduino output and if uploading a sketch witch puts that output HIGH the leds will turn on?

    If I am fine with 30secs of triggertime I do not have to do anything more?

    Are all my assumptions correct?



  • @Cliff-Karlsson correct!😄



  • @Cliff-Karlsson
    Excellent summarized! Perfect HowTo!

    Voted Cliff-Karlson for Documentation Team 😄



  • Haha, right. Last question, if I also want the sensor to report battery-usage. Is there any way to accomplish that without soldering any more resistors?


  • Mod

    @Cliff-Karlsson Yes, there is!
    Use my Vcc library!



  • @Yveaux @Cliff-Karlsson but in the scheme of cliff he is taken the power after the power regulator. So you are not
    Measuring the battery with your VCC library.


  • Mod

    @dynamite You're right then. I didn't read his howto, just answered how to read battery voltage without voltage divider 😉



  • Ok, but if I measured right when talking the power from the regulator you could get 3v or ~4.5v witch i guess is directly from the batteries. If I connect the 4.5v to the power input on the same side as the tx/rx can I still not use the vcc library?



  • How would a sketch for this PIR look like? I tried combining the PIR and RelayActuator but my skills are not enough.

    This is what I have came up with:

    /**
     * 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
     * Motion Sensor example using HC-SR501 
     * http://www.mysensors.org/build/motion
     *
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define RELAY_1  9  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    
    #define CHILD_ID 1   // Id of the sensor child
    #define SECONDARY_CHILD_ID 4
    
    void before() { 
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      
      
    }
    
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Light/Motion Sensor ikea", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_MOTION);
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);
    }
    
    void loop()     
    {     
      // Read digital motion value
      boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
            
      Serial.println(tripped);
      send(msg.set(tripped?"1":"0"));  // Send tripped value to gw 
    
      // Sleep until interrupt comes in on motion sensor. Send update every two minute.
      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
    }
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
      }
      }
    

    But it does not complie after the last part is added. And I would also like to get the vcc -stuff into the same sketch. Could someone post a working sketch for this?



  • @Cliff-Karlsson you can only use the VCC sketch if you by pass the voltage regulators. So power the arduino from two batteries by a separate wire.



  • @Cliff-Karlsson the receive routine is out of the repeat loop



  • Ok, tried placing it in the loop to but with the same result. In the RelayActuator it looks like it really is placed outside the loop: RelayActuator

    What would the prefered way be to connect the power to the a 3.3v arduino for the best battery time?

    4.5v from the PIR regulator --> Arduino RAW (using 3 batteries)
    3v from the PIR regulator --> Arduino VCC (3batteries)

    And how would I power it from only 2 batteries? would not the PIR or leds need higher voltage than 3v ?


  • Mod



  • Hi guys,

    I'm struggling with this one unfortunately, i can't get it to trip/untrip.

    Sketch is identical to the motion example.

    I've removed the photo diode (not bridged the gap, it looks like bridging the gap stops it from tripping at all, leaving it open means it trips whatever the light level is). This was tested without connecting to the arduino, working as normal.

    So i've removed resistor 17, and connected my arduino pin 4 up to the chip side of where R17 was. I'm running the main board of the existing power lines, but i've tapped into the + of the middle battery and that's going to VCC on the arduino. Arduino nano GND is connected to the main board -.

    Where am I going wrong? I've tried this on two boards now and they're both acting the same. Serial monitor is just showing me:

    send: 14-14-4-0 s=1,c=1,t=16,pt=0,l=1,sg=0,st=ok:1
    1
    send: 14-14-4-0 s=1,c=1,t=16,pt=0,l=1,sg=0,st=ok:1
    1
    send: 14-14-4-0 s=1,c=1,t=16,pt=0,l=1,sg=0,st=ok:1
    1

    Thanks,

    Patrick



  • @pjblink hi your setup sounds ok to me! And from your debug I think it is transmitting a value. Is this value submitted after activating the pir?
    After activation the is high for about 30 sec then it sound be low again. Maybe you can verify this procedure. Can you debug on the receiving side?



  • I have build a couple of these and they work fine. Replacing batteries with the baseplate is really a huge advantage, and battery life seems to be pretty good.

    I have one issue though: I have built one including an LDR. But this seems to freeze after a random time, no longer reacting to movement.
    @dynamite , can you may be share your code and the way you have attached your LDR to the arduino etc?

    Many thanks!



  • @gijss Hi I will try to find the code tonight and post it on github.



  • Guys,

    This is fantastic. Can someone summarise the best practises for using an Arduino Pro mini, to benefit from maximum battery life and voltage monitoring?

    Thank you!


  • Mod

    @Mark-Swift https://www.mysensors.org/build/battery has information on how to get good battery life



  • @dynamite , can you may be share your code and the way you have attached your LDR to the arduino etc?

    @gijss the code can be found here. But I don't know the actual status of this code as I have not used it for a while and I was busy creating a dimmer. But maybe you can copy parts out of it.

    https://github.com/rspaargaren/My-sensors-IKEA/blob/master/multisensor.ino



  • @dynamite said:

    @gijss the code can be found here. But I don't know the actual status of this code as I have not used it for a while and I was busy creating a dimmer. But maybe you can copy parts out of it.

    https://github.com/rspaargaren/My-sensors-IKEA/blob/master/multisensor.ino

    @dynamite Thanks for the code, I am sure it will prove to be useful. Will try to experiment this weekend. Can you also share how you connected the LDR to the arduino? I have the feeling I might be using a suboptimal wiring scheme (or wrong resistor) resulting in shorter battery life.



  • @Yveaux Did you finish the PCB for the molgan?, If so is it possible for you to share the files?


  • Hardware Contributor

    I would be interested too!


  • Mod

    @Cliff-Karlsson Yes, works like a charm!
    It has been on my ToDo list for quite a long time to publish the files -- please hold on a little longer 😉



  • @Yveaux great as my project was on hold for a while but still on the to do list...:-)


  • Mod

    @Cliff-Karlsson @LastSamurai @dynamite I just published the PCB on [OpenHardware.io].(https://www.openhardware.io/view/274/Ikea-Molgan-Hack)
    A sketch will follow soon.

    Enjoy!



  • @dynamite

    It has been a while (mainly because the PIR was out of order for other reasons) but now I am restarting the project and again it happened that the PIR no longer responded. So I took a look at your code, but it seems your are using a BH1750 light sensor, is that correct? And are you using that in fact at the moment, or did you switch to LDR and is this perhaps not the latest version of the code?

    Thanks!

    Gijss



  • @gijss Hi let me check upon that as the PIR has not been on the top of my priority list. I have one of the PIR based on LDR sensor. But I was working on a BH1750 sensor. So most probably the code is related to that version.



  • Hi to all,
    I've realized my hacked version of the Ikea Molgan but the PIR sensor stays always HIGH.
    Everything works apart of this... Do you have any idea howto investigate?

    could I have broken it?



  • @ricmail85 hi iT has been a while ago but as far as I recollect I had the same problem with one of my sensors ...

    In normal situation the sensors gives a high signal for approx 30 sec.

    In the bricked PIR I have replace the pir board by a cheap and modified pir from Ali.



  • Ok thanks for your reply. I'll check the board for some weak connection and try again...
    bye!


  • Mod

    @ricmail85 I also have one Molgan that I just can't get to work correctly. Put it aside, thinking it was an incident, but if more people have issues, this might be a structural thing...



  • @Yveaux said in Multisensor PIR based on IKEA Molgan:

    @ricmail85 I also have one Molgan that I just can't get to work correctly. Put it aside, thinking it was an incident, but if more people have issues, this might be a structural thing...

    I'll give it a try. I have to check that the wires I soldered on the back of the breadboard are just fine...
    I'll let you know.

    bye!



  • @ricmail85 @Yveaux basically mine was shortcut by testing Some connection which I should not have Done....🙄



  • @dynamite @Yveaux Ok I've done some testing. Here my results.

    I checked the wire connections between the Arduino and the PIR and they were ok. Actually when powering everything with batteries I always get HIGH from PIR.

    Then I tried to leave only the PIR without the Arduino and its radio (disconnected the GND wire) and the PIR (alone) was working! I checked with multimeter it oscillates between 0V and 3V if a movement was detected.

    So I concluded that the failure was due to the Arduino. If arduino+radio are powered (by the same battery source) i get always HIGH.

    Looking at this post https://forum.mysensors.org/topic/5273/ikea-molgan-hack/36 I found similar problems due to ripples. I added a capacitor (100uF) in parallel to the PIR capacitor and a 10uF capacitor between the + and - of the battery pack.

    By doing so I still cannot move from HIGH signal from PIR when everything was connected. So I've done more debugging and I found that everything works like a charm if I put a sleep (1000 ms) after sending a message (in my sketch I send 4 different message types when the Molgan wake up).

    Maybe there is still some disturb arising from the radio (sending a message require some power at least)? Now my project is working, actually with the sleep(1000) trick after each send.

    I don't know if the capacitors were effectively needed at this point...

    Hope this can help!
    bye!


  • Hardware Contributor

    I am the one from your post and the capacitors only helped a little. One of my molgans simply doesn't seem to work.
    But you are right sending takes a lot of energy (vs doing nothing) so a bigger capacitor and/or pauses in between definitely should help!



  • @LastSamurai
    Some more debugging and I see the problems arise when I do analogread, so does not seem related to the radio itself.

    If I send a message about a dht sensor (digitalread) it is ok. If I send a message of battery/light measure (analogread), the pir gets high...


  • Mod

    @ricmail85 does the behavior change when you swap the order of the messages sent? Eg first send the battery value.



  • @Yveaux yes, it seems to work better by sending before the messages performing analogread and then the one using digitalread...


  • Mod

    @ricmail85 could be power related then. Try adding some sleep or wait statements inbetween each message sent.



  • @Yveaux Yes I found a partial fix by adding sleep of 1000 ms after each send. And by doing analogread before digitalread. It seems related to power fluctuations. I ve already added some capacitors to the Pir. Shoul I add akso in parallel to the R2 resistance when reading the battery and light level?

    Bye!


  • Mod

    @ricmail85 I still think it's strange that you need the delays for a battery powered sensor. Normally the batteries can supply sufficient power to compensate for the bursts required when sending.
    I don't want to read back the whole thread now, but what was your setup again?



  • @Yveaux This is my configuration

    1. Arduino Pro Mini 3.3V
    2. RFM69 radio 433MHz
    3. Photo-resistor
    4. DHT11 temp sensor
    5. Battery voltage measurement through voltage partition.
    6. The arduino and radio are powered by a 3.3V MCP1700-3302E voltage regulator

    yesterday I've noticed the following. If I shutdown the gateway, the sensors fail to reach it and the PIR goes HIGH forever. By rebooting the gateway there is no chance to get it LOW. I have to remove the batteries and everything starts to work again.


  • Mod

    @ricmail85 said in Multisensor PIR based on IKEA Molgan:

    The arduino and radio are powered by a 3.3V MCP1700-3302E voltage regulator

    I suspect the regulator injects noise in your supply and/or isn't able to supply enough power for a series of transmissions.
    You could try powering directly from 2xAA battery, without using a regulator.
    Both the ATmega and radio will work directly on 2xAA.
    The DHT11 won't (IIRR) but there are many way better alternatives for it that work at less than 5V supply (e.g. Si7021, BME280, SHT11 etc.).
    The PIR needs > 3.3V; refer to this post on how to power only the PIR from 3xAA.

    If you don't need a lot of accuracy on the battery measurement (who does...) then you could consider using the Vcc library I wrote a while ago.



  • @Yveaux Thanks for your reply. I've done a lot of debugging today. And I guess I found the issue.
    It's definitely related to the radio power consumption as you suggested.

    I'm currently using the new RFM69 driver, with ATC enabled by default. As long as the power level stays below -4 dB, everything works fine. If the gateway is powered off, the radio power level automatically increases to 100% and the PIR behaves weird. It's always HIGH.

    By rebooting the gateway, the node relink itself and gradually lowers its power. As before, when it goes below -4dB the PIR starts to work again.

    Since it's a battery powered device I decided to set

    #define MY_RFM69_MAX_POWER_LEVEL_DBM (-4)

    at the beginning of the sketch file. Even if the gateway fails (shutdown) the PIR does not get HIGH anymore. All the measurements work fine now by limiting the max power to the radio.

    By doing so all the sleeps of 1000ms after each send are not needed anymore.


 

316
Online

8.3k
Users

9.1k
Topics

96.7k
Posts