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 30.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.
  • icebobI Offline
    icebobI Offline
    icebob
    wrote on last edited by
    #37

    @the-cosmic-gate sorry, I'm working a big complex sketch, I can't share my code currently.

    the cosmic gateT 1 Reply Last reply
    0
    • icebobI icebob

      @the-cosmic-gate sorry, I'm working a big complex sketch, I can't share my code currently.

      the cosmic gateT Offline
      the cosmic gateT Offline
      the cosmic gate
      wrote on last edited by
      #38

      @icebob said:

      @the-cosmic-gate sorry, I'm working a big complex sketch, I can't share my code currently.

      Big and complex sounds interesting :)
      Could you maybe share us a sneak peak ;-)

      There's more than meets the eye

      1 Reply Last reply
      0
      • icebobI Offline
        icebobI Offline
        icebob
        wrote on last edited by
        #39

        @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 1 Reply Last reply
        0
        • carlierdC Offline
          carlierdC Offline
          carlierd
          wrote on last edited by
          #40

          @the-cosmic-gate Did you solved your power consumption issue ?

          the cosmic gateT 1 Reply Last reply
          0
          • carlierdC carlierd

            @the-cosmic-gate Did you solved your power consumption issue ?

            the cosmic gateT Offline
            the cosmic gateT Offline
            the cosmic gate
            wrote on last edited by
            #41

            @carlierd said:

            @the-cosmic-gate Did you solved your power consumption issue ?
            Not yet, this because we moved to oneother house and didn't have the time now .
            Also i had to disconnect and reconect all te sensors and domotica in this new house

            There's more than meets the eye

            1 Reply Last reply
            0
            • carlierdC Offline
              carlierdC Offline
              carlierd
              wrote on last edited by
              #42

              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.

              the cosmic gateT 1 Reply Last reply
              0
              • carlierdC 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.

                the cosmic gateT Offline
                the cosmic gateT 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
                  • carlierdC Offline
                    carlierdC 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
                      • carlierdC Offline
                        carlierdC 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
                          • carlierdC Offline
                            carlierdC 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
                                • carlierdC Offline
                                  carlierdC 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
                                  • carlierdC 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
                                    • carlierdC Offline
                                      carlierdC 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
                                      • carlierdC 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
                                        • carlierdC Offline
                                          carlierdC 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
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          19

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          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