Alternative battery operated motion sensor using 433MHz sensors


  • Hero Member

    I never managed to get a motion sensor attached to an arduino to work reliably, especially on batteries so I looked for an alternative using ready made sensor that could be "MySensord". Here is what I came up with:

    I found these 433MHz battery operated Motion sensors that seemed like a nice alternative and then I got myself this 433MHz receiver to hock up to my MySensors 5V Pro Mini node like this (I allso connected an NRF24L01+ but I left it out from the drawing to keep it clean):

    0_1479892250747_433MHzReceiver.jpg

    I attached a 17,3cm wire as a quarter length antenna to the receiver calculated here

    Then I created this sketch to handle it all:

    /**
     * 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.
     *
     *******************************
     *
     *
     *
     *
     */
    
    // Enable debug prints
    //#define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    #define MY_BAUD_RATE  9600
    
    #define MY_NODE_ID 18
    #define SKETCH_NAME "RF433 Motion"
    #define SKETCH_VERSION "1.0"
    
    #include <MySensors.h>
    #include <RCSwitch.h>
    #include <SPI.h>
    
    unsigned long TRIP_RESET_TIME = 120000;
    
    unsigned long NOW_TIME = millis();
    unsigned long KnownSensor1 = 5945054;
    unsigned long TRIP_TIME_1 = millis();
    bool untripsent_1 = 1;
    bool tripped_1 = 0;
    
    unsigned long KnownSensor2 = 5914846;
    unsigned long TRIP_TIME_2 = millis();
    bool untripsent_2 = 1;
    bool tripped_2 = 0;
    
    #define RF433RECIEVER 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    
    RCSwitch mySwitch = RCSwitch();
    
    #define CHILD_ID_1 1   // Id of the sensor child
    #define CHILD_ID_2 2   // Id of the sensor child
    
    // Initialize motion message
    MyMessage msg1(CHILD_ID_1, V_TRIPPED);
    MyMessage msg2(CHILD_ID_2, V_TRIPPED);
    
    void setup()
    {
      mySwitch.enableReceive(digitalPinToInterrupt(RF433RECIEVER));  // Receiver on interrupt 0 => that is pin #2
    
    }
    
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
    
      wait(50);
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_1, S_MOTION);
      wait(50);
      present(CHILD_ID_2, S_MOTION);
      wait(50);
    
    }
    
    void loop()
    {
    
    
      if (mySwitch.available()) {
    
        int value = mySwitch.getReceivedValue();
    
        if (value == 0) {
          Serial.print("Unknown encoding");
        } else {
          Serial.print("Received ");
          Serial.println( mySwitch.getReceivedValue() );
          //Serial.print(" / ");
          //Serial.print( mySwitch.getReceivedBitlength() );
          //Serial.print("bit ");
          //Serial.println( mySwitch.getReceivedProtocol() );
    
          if (mySwitch.getReceivedValue() == KnownSensor1) {
            int value = mySwitch.getReceivedValue();
    
            if (tripped_1 == 0) {
              Serial.println("Sending Tripped value");
              send(msg1.set(1));  // Send tripped value to gw
              tripped_1 = 1;
            }
    
            TRIP_TIME_1 = millis();
            untripsent_1 = 0;    
          }
    
          if (mySwitch.getReceivedValue() == KnownSensor2) {
            int value = mySwitch.getReceivedValue();
    
            if (tripped_2 == 0) {
              Serial.println("Sending Tripped value");
              send(msg2.set(1));  // Send tripped value to gw
              tripped_2 = 1;
            }
    
            TRIP_TIME_2 = millis();
            untripsent_2 = 0;        
          }
    
          mySwitch.resetAvailable();
        }
    
      }
      
      unsigned long NOW_TIME = millis();
      
      if ((NOW_TIME - TRIP_TIME_1 >= TRIP_RESET_TIME) && (untripsent_1 == 0))
      {
        Serial.println("Sending Un-tripped value");
        send(msg1.set(0));  // Send Un-tripped value to gw
        TRIP_TIME_1 = NOW_TIME;
        untripsent_1 = 1;
        tripped_1 = 0;
      }
    
      if ((NOW_TIME - TRIP_TIME_2 >= TRIP_RESET_TIME) && (untripsent_2 == 0))
      {
        Serial.println("Sending Un-tripped value");
        send(msg2.set(0));  // Send Un-tripped value to gw
        TRIP_TIME_2 = NOW_TIME;
        untripsent_2 = 1;
        tripped_2 = 0;    
      }
      
    }
    
    
    

    So far I'm happy with the performance. I have one outside sending me a snapshot from a camera if there is movement when we are away and I have not had any false triggers so far. The communication range of the 433MHz sensors is great. I cannot comment on how long the batteries will hold on these since they have only been in use a few weeks.



  • @korttoma Did you give power to the antenna side of the RXB6?

    What is the distance between your receiver and the senders?



  • @korttoma I set up a pir node with promini and nrf24l01+ about 6 weeks ago running on 2xAAA batterues. No false triggers yet and it detects many movements each day. Battery level is still 100% (3V) so it is possible to do this. Maybe something else is affecting your previous test, like situation, distance or interfereing signals?

    But you have another solution that mighte well be useful to someone else with the issues you faced. Good of you to share it.


Log in to reply
 

Suggested Topics

  • 8
  • 3
  • 90
  • 5
  • 1
  • 7

37
Online

11.4k
Users

11.1k
Topics

112.6k
Posts