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. 3 in 1 incl battery monitor

3 in 1 incl battery monitor

Scheduled Pinned Locked Moved My Project
60 Posts 11 Posters 35.0k Views 12 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.
  • C carlierd

    I just finished my first motion sensor node and the power consumption in idle is about 75uA. Could be better but not too bad ;)
    The only thing is that the range is a little bit low for good detection. It's between 1 and 3 meters ...

    David.

    T Offline
    T Offline
    the cosmic gate
    wrote on last edited by
    #43

    @carlierd said:

    I just finished my first motion sensor node and the power consumption in idle is about 75uA. Could be better but not too bad ;)
    The only thing is that the range is a little bit low for good detection. It's between 1 and 3 meters ...

    David.

    Hello David

    Could you share what and how ? :)

    Thnx

    There's more than meets the eye

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dylano
      wrote on last edited by
      #44

      And how is this sensor acting?

      This is what i am looking for..
      How lang can this sensor work? [ i wil try this with a 9Volt battery with a nano ]
      What battery do you use?

      Domoticz, with a lot of working hardware, include mysensors :-)
      OpenPLI, RuneAudio, Solarmeter, etc......

      Not a great builder of software and hardware, more a user...
      Only i try to do my best :-(

      1 Reply Last reply
      0
      • C Offline
        C Offline
        carlierd
        wrote on last edited by
        #45

        Hello,

        This is the code I use but it's not perfect especially with the battery report.

        The principle is as follow when the sensor start:

        • node in sleep mode with interrupt enable
        • if a move is detected, the detection is reported to the gateway
        • the node then go in sleep mode WITHOUT interrupt for 5 minutes
        • then the node return to sleep mode with interrupt enable

        This is to avoid having many report (and power consumption) to the gateway.

        The code (not perfect ! I have to rework on it but it's ok for the moment):

        /**
         * 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.
         *
         */
        
        /**************************************************************************************/
        /* Motion sensor.                                                                     */
        /*                                                                                    */
        /* Version     : 1.1.5                                                                */
        /* Date        : 30/01/2016                                                           */
        /* Modified by : David Carlier                                                        */
        /**************************************************************************************/
        /*                                ---------------                                     */
        /*                            RST |             |  A5                                 */
        /*                            RX  |             |  A4                                 */
        /*                            TX  |   ARDUINO   |  A3                                 */
        /*     RFM69 (DIO0) --------- D2  |     UNO     |  A2                                 */
        /*           Motion --------- D3  |             |  A1                                 */
        /*            Power --------- D4  | ATMEGA 328p |  A0                                 */
        /*              +3v --------- VCC |             | GND --------- GND                   */
        /*              GND --------- GND |  8MHz int.  | REF                                 */
        /*                            OSC |             | VCC --------- +3v                   */
        /*                            OSC |             | D13 --------- RFM69 (SCK)           */
        /*                            D5  |             | D12 --------- RFM69 (MISO)          */
        /*                            D6  |             | D11 --------- RFM69 (MOSI)          */
        /*                            D7  |             | D10 --------- RFM69 (NSS)           */
        /*                            D8  |             |  D9                                 */
        /*                                ---------------                                     */
        /*                                                                                    */
        /* +3v = 2*AA                                                                         */
        /*                                                                                    */
        /**************************************************************************************/
        
        #include <SPI.h>
        #include <MySensor.h>
        #include <MyTransportRFM69.h>
        #include <MySigningAtsha204Soft.h>
        
        //Constants
        #define SKETCH_NAME           "Motion Sensor"
        #define SKETCH_VERSION        "1.1.5"
        #define CHILD_ID              0
        #define CHILD_ID_VOLTAGE      1
        #define DIGITAL_INPUT_SENSOR  3
        #define BATTERY_REPORT_CYCLE  4   //Report each hour (4 * 15')
        
        //Misc. variables
        uint8_t switchState = 2;
        unsigned long SLEEP_TIME = 820000; // Sleep time between reads (in milliseconds) (close to 15')
        unsigned long SLEEP_TIME2 = 275000; // Sleep time after int. (in milliseconds) (close to 5')
        uint8_t cycleInProgress = 0;
        uint8_t firstReportDone = 0;
        uint8_t firstReportWithZeroDone = 0;
        
        //Construct MySensors library
        MySigningAtsha204Soft signer;
        MyHwATMega328 hw;
        MyTransportRFM69 transport;
        MySensor node(transport, hw, signer);
        MyMessage msgSwitch(CHILD_ID, V_TRIPPED);
        MyMessage msgVolt(CHILD_ID_VOLTAGE, V_VOLTAGE);
        
        /**************************************************************************************/
        /* Initialization                                                                     */
        /**************************************************************************************/
        void setup()  
          {
          //Get time (for setup duration)
          #ifdef DEBUG
            unsigned long startTime = millis();
          #endif
        
          //Start MySensors and send the Sketch Version Information to the Gateway
          node.begin();
          node.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        
          //Setup the button
          pinMode(DIGITAL_INPUT_SENSOR, INPUT);
        
          //Register all sensors
          node.present(CHILD_ID, S_MOTION);
          node.present(CHILD_ID_VOLTAGE, S_MULTIMETER);
        
          //Print setup debug
          #ifdef DEBUG
            int duration = millis() - startTime;
            Serial.print("[Setup duration: "); Serial.print(duration, DEC); Serial.println(" ms]");
          #endif
          }
        
        /**************************************************************************************/
        /* Main loop                                                                          */
        /**************************************************************************************/
        void loop()
          {
          //Get time (for a complete loop)
          #ifdef DEBUG
            unsigned long startTime = millis();
          #endif
        
          //Read digital motion value
          uint8_t value = digitalRead(DIGITAL_INPUT_SENSOR);
        
          //Get voltage for battery capacity report (add 0.1v to the read value)
          float realVoltage = (getVoltage() / 100.0) + 0.1;
          int batteryPcnt = realVoltage * 100 / 3.0;
          if (batteryPcnt > 100) {batteryPcnt = 100;}
        
          //Check is state change
          if (value != switchState)
            {
            //Report result if not first loop
            if (firstReportDone != 0)
              {
              node.send(msgSwitch.set(value==HIGH ? 1 : 0));
              }
        
            //Store result
            switchState = value;
            }
        
          //Report data to the gateway each hour
          if (cycleInProgress >= BATTERY_REPORT_CYCLE || firstReportDone == 0)
            {
            node.send(msgSwitch.set(value==HIGH ? 1 : 0));
            node.send(msgVolt.set(realVoltage, 2));
            node.sendBatteryLevel(batteryPcnt);
            cycleInProgress = 0;
            firstReportDone = 1;
            }
        
          //Change cycle number
          cycleInProgress++;
        
          //Print debug
          #ifdef DEBUG
            Serial.print("Value is ");
            Serial.print(value, 1);
            Serial.print("   ");
            Serial.print("Cycle is ");
            Serial.print(cycleInProgress, 1);
            Serial.print("   ");
            Serial.print(realVoltage);
            Serial.print(" v");
            int duration = millis() - startTime;
            Serial.print("   ");
            Serial.print("["); Serial.print(duration, DEC); Serial.println(" ms]");
            Serial.flush();
          #endif
        
          //Check if the motion was triggered and if it's not the first report
          if (switchState == 0 && firstReportWithZeroDone == 1)
            {
            //Sleep 5' without interrupt
            node.sleep(SLEEP_TIME2);
            }
        
          //Check if it's the first loop
          if (switchState == 0 && firstReportWithZeroDone == 0)
            {
            firstReportWithZeroDone = 1;
            }
        
          //Sleep until something happens with the sensor
          node.sleep(DIGITAL_INPUT_SENSOR-2, CHANGE, SLEEP_TIME);
          }
        
        /**************************************************************************************/
        /* Allows to get the real Vcc (return value * 100).                                   */
        /**************************************************************************************/
        int getVoltage()
          {
          const long InternalReferenceVoltage = 1056L;
          ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
          delay(50);  // Let mux settle a little to get a more stable A/D conversion
          //Start a conversion  
          ADCSRA |= _BV( ADSC );
          //Wait for it to complete
          while (((ADCSRA & (1<<ADSC)) != 0));
          //Scale the value
          int result = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L;
          return result;
          }
        

        On one sensor I tweak the PIR (remove regulator and diode) but on a second one, I just plug the 3 v to the H pin (see other topic on the forum).

        Working correctly for the moment (one month) but it depends on the presence in the house.

        David.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dylano
          wrote on last edited by Dylano
          #46

          @ Carlied,

          What code is better that one of you or the one from cosmi gate?

          What are the different thing? Is your code check'the battery status?

          And i get a error:
          no matching function for call to 'MySensor::MySensor(MyTransportRFM69&, MyHwATMega328&, MySigningAtsha204Soft&)'

          Domoticz, with a lot of working hardware, include mysensors :-)
          OpenPLI, RuneAudio, Solarmeter, etc......

          Not a great builder of software and hardware, more a user...
          Only i try to do my best :-(

          1 Reply Last reply
          0
          • C Offline
            C Offline
            carlierd
            wrote on last edited by
            #47

            The error is because I enable the signing function !
            Remove the following line:

            MySigningAtsha204Soft signer;
            

            And replace

            MySensor node(transport, hw, signer);
            

            by

            MySensor node(transport, hw);
            

            I don't know who had the best sketch.
            I measure internal battery status using the 1.1 reference.

            David.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dylano
              wrote on last edited by
              #48

              When i put this sketch in to a nano..
              With a 9volt battery....
              How long do think this working?

              Or how long is this acting on your 3 volt battery's?

              Domoticz, with a lot of working hardware, include mysensors :-)
              OpenPLI, RuneAudio, Solarmeter, etc......

              Not a great builder of software and hardware, more a user...
              Only i try to do my best :-(

              1 Reply Last reply
              0
              • C Offline
                C Offline
                carlierd
                wrote on last edited by
                #49

                It depends on the activity close to the sensor so not possible to say but some people reach several month without problem.
                In my house it's very fresh so I have not a lot of feedback to give.

                David.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dylano
                  wrote on last edited by Dylano
                  #50

                  5 days....:-1: on a 9volt block
                  The sketch on a nano
                  On my toilet.... so not a very busy room

                  Is there some one that live longer, with this sketch......?

                  Domoticz, with a lot of working hardware, include mysensors :-)
                  OpenPLI, RuneAudio, Solarmeter, etc......

                  Not a great builder of software and hardware, more a user...
                  Only i try to do my best :-(

                  1 Reply Last reply
                  0
                  • icebobI icebob

                    @the-cosmic-gate Nothing special. I made a big sketch, which contains 7-8 sensors (DHT, Si7021, MQ-2/9, PIR, Door magnet, Light, battery) reading code because I would like to upload the same sketch to all nodes and configurate it on controller side, which sensors is on the node and need to read.
                    But currently I reached the limit with I2C includes, so I need to think over this solution.

                    D Offline
                    D Offline
                    Dylano
                    wrote on last edited by
                    #51

                    @icebob said:

                    @the-cosmic-gate Nothing special. I made a big sketch, which contains 7-8 sensors (DHT, Si7021, MQ-2/9, PIR, Door magnet, Light, battery) reading code because I would like to upload the same sketch to all nodes and configurate it on controller side, which sensors is on the node and need to read.
                    But currently I reached the limit with I2C includes, so I need to think over this solution.

                    Dear..
                    Did you finish your big code....

                    Domoticz, with a lot of working hardware, include mysensors :-)
                    OpenPLI, RuneAudio, Solarmeter, etc......

                    Not a great builder of software and hardware, more a user...
                    Only i try to do my best :-(

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      carlierd
                      wrote on last edited by
                      #52

                      Hello,

                      9v means that you are using a voltage regulator which probably consumes a lot of power.
                      Why not using AA or AAA battery directly connected to Vcc ?

                      David

                      D 1 Reply Last reply
                      0
                      • C carlierd

                        Hello,

                        9v means that you are using a voltage regulator which probably consumes a lot of power.
                        Why not using AA or AAA battery directly connected to Vcc ?

                        David

                        D Offline
                        D Offline
                        Dylano
                        wrote on last edited by
                        #53

                        @carlierd said:

                        Hello,

                        9v means that you are using a voltage regulator which probably consumes a lot of power.
                        Why not using AA or AAA battery directly connected to Vcc ?

                        David

                        Motion and DHT needed 5volt i wash thinking..?
                        So 9 @ the vcc should be strong enough i was thinking.
                        And i do have @ the same time 3.5 for the radio

                        Are the extern step up better than the step down on a nano?

                        Domoticz, with a lot of working hardware, include mysensors :-)
                        OpenPLI, RuneAudio, Solarmeter, etc......

                        Not a great builder of software and hardware, more a user...
                        Only i try to do my best :-(

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          carlierd
                          wrote on last edited by
                          #54

                          The motion can be adapt to run on 3v easily (connect the Vcc to the H pad if available. You can find information on the forum). The DHT could also run on 3v. I have several nodes like that. No problem.
                          Can't reply for the step-up because I don't use it.

                          David.

                          D 1 Reply Last reply
                          0
                          • C carlierd

                            The motion can be adapt to run on 3v easily (connect the Vcc to the H pad if available. You can find information on the forum). The DHT could also run on 3v. I have several nodes like that. No problem.
                            Can't reply for the step-up because I don't use it.

                            David.

                            D Offline
                            D Offline
                            Dylano
                            wrote on last edited by
                            #55

                            @carlierd said:

                            The motion can be adapt to run on 3v easily (connect the Vcc to the H pad if available. You can find information on the forum). The DHT could also run on 3v. I have several nodes like that. No problem.
                            Can't reply for the step-up because I don't use it.

                            David.

                            @ David

                            How long is the 3v battery running whit this option?

                            Domoticz, with a lot of working hardware, include mysensors :-)
                            OpenPLI, RuneAudio, Solarmeter, etc......

                            Not a great builder of software and hardware, more a user...
                            Only i try to do my best :-(

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              carlierd
                              wrote on last edited by
                              #56

                              @Dylano : My nodes are really new so difficult to say exactly but for the moment the oldest node was started one month ago (04/02) and battery still at 3.32v.

                              David.

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                the cosmic gate
                                wrote on last edited by
                                #57

                                i'am back in business after the "big move" and going to try again to get this 4:1 sensor working for a long time uning 2 x AA batteries.
                                If someone has some new input, please let me know :) and feel free to change the sketch

                                There's more than meets the eye

                                C 1 Reply Last reply
                                0
                                • T the cosmic gate

                                  i'am back in business after the "big move" and going to try again to get this 4:1 sensor working for a long time uning 2 x AA batteries.
                                  If someone has some new input, please let me know :) and feel free to change the sketch

                                  C Offline
                                  C Offline
                                  carlierd
                                  wrote on last edited by
                                  #58

                                  @the-cosmic-gate
                                  Hello,
                                  Motion nodes are still working correctly. The oldest node started the 4 of February is still at 3,29v. My other nodes (temp / humidity / light) are also working correctly but I will replace DHT22 for another sensor.

                                  David.

                                  1 Reply Last reply
                                  0
                                  • rhuehnR Offline
                                    rhuehnR Offline
                                    rhuehn
                                    wrote on last edited by
                                    #59

                                    Hey @carlierd Just curious if you are still using a DHT22 with your sketch? Have you modified the code much from the above? I am looking at implementing something similiar ( identical actually ) and was wondering if much has changed for you over the last few months?

                                    Thanks!

                                    1 Reply Last reply
                                    0
                                    • C Offline
                                      C Offline
                                      carlierd
                                      wrote on last edited by
                                      #60

                                      Hello,

                                      All nodes are still working correctly but I still want to replace DHT22. But nothing done for the moment. Not at top position on my todo list ;)

                                      David.

                                      1 Reply Last reply
                                      0

                                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                      With your input, this post could be even better 💗

                                      Register Login
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      22

                                      Online

                                      12.0k

                                      Users

                                      11.2k

                                      Topics

                                      113.4k

                                      Posts


                                      Copyright 2025 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