Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Multisensor PIR based on IKEA Molgan

Multisensor PIR based on IKEA Molgan

Scheduled Pinned Locked Moved My Project
112 Posts 21 Posters 49.8k Views 37 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Cliff KarlssonC Cliff Karlsson

    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?

    dynamiteD Offline
    dynamiteD Offline
    dynamite
    wrote on last edited by
    #78

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

    1 Reply Last reply
    0
    • Cliff KarlssonC Offline
      Cliff KarlssonC Offline
      Cliff Karlsson
      wrote on last edited by
      #79

      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 ?

      YveauxY 1 Reply Last reply
      0
      • Cliff KarlssonC Cliff Karlsson

        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 ?

        YveauxY Offline
        YveauxY Offline
        Yveaux
        Mod
        wrote on last edited by
        #80

        @Cliff-Karlsson see here: https://forum.mysensors.org/topic/3756/multisensor-pir-based-on-ikea-molgan/58

        http://yveaux.blogspot.nl

        1 Reply Last reply
        0
        • pjblinkP Offline
          pjblinkP Offline
          pjblink
          wrote on last edited by
          #81

          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

          dynamiteD 1 Reply Last reply
          0
          • pjblinkP pjblink

            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

            dynamiteD Offline
            dynamiteD Offline
            dynamite
            wrote on last edited by
            #82

            @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?

            1 Reply Last reply
            0
            • gijssG Offline
              gijssG Offline
              gijss
              wrote on last edited by
              #83

              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!

              dynamiteD 2 Replies Last reply
              0
              • gijssG gijss

                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!

                dynamiteD Offline
                dynamiteD Offline
                dynamite
                wrote on last edited by
                #84

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

                1 Reply Last reply
                0
                • Mark SwiftM Offline
                  Mark SwiftM Offline
                  Mark Swift
                  wrote on last edited by
                  #85

                  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!

                  mfalkviddM 1 Reply Last reply
                  0
                  • Mark SwiftM Mark Swift

                    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!

                    mfalkviddM Offline
                    mfalkviddM Offline
                    mfalkvidd
                    Mod
                    wrote on last edited by
                    #86

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

                    1 Reply Last reply
                    0
                    • gijssG gijss

                      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!

                      dynamiteD Offline
                      dynamiteD Offline
                      dynamite
                      wrote on last edited by
                      #87

                      @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

                      gijssG 1 Reply Last reply
                      0
                      • dynamiteD dynamite

                        @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

                        gijssG Offline
                        gijssG Offline
                        gijss
                        wrote on last edited by
                        #88

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

                        gijssG 1 Reply Last reply
                        0
                        • Cliff KarlssonC Offline
                          Cliff KarlssonC Offline
                          Cliff Karlsson
                          wrote on last edited by
                          #89

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

                          YveauxY 2 Replies Last reply
                          0
                          • L Offline
                            L Offline
                            LastSamurai
                            Hardware Contributor
                            wrote on last edited by
                            #90

                            I would be interested too!

                            1 Reply Last reply
                            0
                            • Cliff KarlssonC Cliff Karlsson

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

                              YveauxY Offline
                              YveauxY Offline
                              Yveaux
                              Mod
                              wrote on last edited by
                              #91

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

                              http://yveaux.blogspot.nl

                              dynamiteD 1 Reply Last reply
                              0
                              • YveauxY Yveaux

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

                                dynamiteD Offline
                                dynamiteD Offline
                                dynamite
                                wrote on last edited by
                                #92

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

                                1 Reply Last reply
                                0
                                • Cliff KarlssonC Cliff Karlsson

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

                                  YveauxY Offline
                                  YveauxY Offline
                                  Yveaux
                                  Mod
                                  wrote on last edited by
                                  #93

                                  @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!

                                  http://yveaux.blogspot.nl

                                  1 Reply Last reply
                                  1
                                  • gijssG gijss

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

                                    gijssG Offline
                                    gijssG Offline
                                    gijss
                                    wrote on last edited by
                                    #94

                                    @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

                                    dynamiteD 1 Reply Last reply
                                    0
                                    • gijssG gijss

                                      @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

                                      dynamiteD Offline
                                      dynamiteD Offline
                                      dynamite
                                      wrote on last edited by
                                      #95

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

                                      1 Reply Last reply
                                      0
                                      • R Offline
                                        R Offline
                                        ricmail85
                                        wrote on last edited by
                                        #96

                                        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?

                                        dynamiteD YveauxY 2 Replies Last reply
                                        0
                                        • R ricmail85

                                          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?

                                          dynamiteD Offline
                                          dynamiteD Offline
                                          dynamite
                                          wrote on last edited by
                                          #97

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

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          11

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

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