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. Video How To: Battery Powered Chair Occupancy (Contact) Sensor

Video How To: Battery Powered Chair Occupancy (Contact) Sensor

Scheduled Pinned Locked Moved My Project
20 Posts 8 Posters 10.5k Views 7 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.
  • S Offline
    S Offline
    Samuel235
    Hardware Contributor
    wrote on last edited by Samuel235
    #2

    Awesome work dude, ts the video that get me with your builds, not many people even bother to document things but you go to the extra length of a video to help others. Thank you!

    I'm definitely going to work on my battery sensing for my battery nodes, you seem to have got it working pretty nicely here...

    MySensors 2.1.1
    Controller - OpenHAB (Virtual Machine)
    Gateway - Arduino Mega MQTT Gateway W5100

    petewillP 1 Reply Last reply
    0
    • S Samuel235

      Awesome work dude, ts the video that get me with your builds, not many people even bother to document things but you go to the extra length of a video to help others. Thank you!

      I'm definitely going to work on my battery sensing for my battery nodes, you seem to have got it working pretty nicely here...

      petewillP Offline
      petewillP Offline
      petewill
      Admin
      wrote on last edited by petewill
      #3

      @Samuel235 thanks :)
      I love MySensors and have so much help over the years from everyone. I try to help when/where I can. I may not be the best at coding but I do know how to make videos (well, better than I code at least :) ).

      My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Samuel235
        Hardware Contributor
        wrote on last edited by
        #4

        Well, i for one appreciate the help that you're injecting back into the community. I've had a lot of help from people like you around here and its my aim to provide help back too. I try to get everything documented that people help me on just so there is information written down for people to see and get help from themselves. If one person has struggled on something, i'm pretty sure others are too and this is why I attempt to document and share everything that others help me on.

        MySensors 2.1.1
        Controller - OpenHAB (Virtual Machine)
        Gateway - Arduino Mega MQTT Gateway W5100

        1 Reply Last reply
        1
        • pgregg88P Offline
          pgregg88P Offline
          pgregg88
          wrote on last edited by
          #5

          Pete, Thank you for taking the time to create, post and explain this. I've been struggling with an optimized battery powered sensor and this nailed it. Personally, I broke new ground on multiple fronts with this one. First foray with 2.2 and first custom boot loaders.

          Question:

          • My objective is to create a standardized set of sketches for battery powered motion and door/window switches. I'm looking for that instant gratification of a light turning on the moment presence is detected. Yet, battery optimization is still important.

          • How do you recommend I remove some of your bouncing goodness in this sketch for my purposes?

          • I experimented with the following, but my knowledge of 2.2 and interrupt challenges is limited. My attempt was to reduce the sensor state checks from 3 to 1, but I failed at that. I assume it might be better to change the approach, but didn't want to start hacking your code goodness with my lack of 2.2 knowledge.

          #define DEBOUNCE_DELAY 1001 // reduced to 1001. Appear to be no issues, but the impact is minimal

          uint8_t oldContactVal = 1; //changed from 2 to 1. Caused failure, but I changed this combo of 3 variables at the same time. I'm not sure which one or if all together cause the failure. I'm still slow on arduino / mysensors logic.

          uint8_t contactVal[1]; //changed from 2 to 1

          uint8_t contactTracker = 0; //did not change. I left this at zero

          int8_t wakeVal = 0; //did not change. I left this at zero

          else {
          //Woke by interrupt, send contact value
          if (contactTracker < 1) {
          // I changed this for <2 to <1

          Any insights from the community are appreciated.

          petewillP 1 Reply Last reply
          0
          • Nca78N Offline
            Nca78N Offline
            Nca78
            Hardware Contributor
            wrote on last edited by
            #6

            Thank a lot for the idea and for the video explaining the implementation.

            Did you check the power consumption when you don't send battery life at regular intervals ? If you set the wake up only on interrupt then current in sleep mode goes from 5-6uA to 2 when contact is opened. It's so low that you don't really need regular reporting of battery life. I do that and report battery life only on opening/closing of doors/windows and my battery life is great even on chinese CR2032 cells (still over 85% on my entrance door).
            I guess it would drop to 5-6µA when sensor is connected ?

            petewillP 1 Reply Last reply
            0
            • pgregg88P pgregg88

              Pete, Thank you for taking the time to create, post and explain this. I've been struggling with an optimized battery powered sensor and this nailed it. Personally, I broke new ground on multiple fronts with this one. First foray with 2.2 and first custom boot loaders.

              Question:

              • My objective is to create a standardized set of sketches for battery powered motion and door/window switches. I'm looking for that instant gratification of a light turning on the moment presence is detected. Yet, battery optimization is still important.

              • How do you recommend I remove some of your bouncing goodness in this sketch for my purposes?

              • I experimented with the following, but my knowledge of 2.2 and interrupt challenges is limited. My attempt was to reduce the sensor state checks from 3 to 1, but I failed at that. I assume it might be better to change the approach, but didn't want to start hacking your code goodness with my lack of 2.2 knowledge.

              #define DEBOUNCE_DELAY 1001 // reduced to 1001. Appear to be no issues, but the impact is minimal

              uint8_t oldContactVal = 1; //changed from 2 to 1. Caused failure, but I changed this combo of 3 variables at the same time. I'm not sure which one or if all together cause the failure. I'm still slow on arduino / mysensors logic.

              uint8_t contactVal[1]; //changed from 2 to 1

              uint8_t contactTracker = 0; //did not change. I left this at zero

              int8_t wakeVal = 0; //did not change. I left this at zero

              else {
              //Woke by interrupt, send contact value
              if (contactTracker < 1) {
              // I changed this for <2 to <1

              Any insights from the community are appreciated.

              petewillP Offline
              petewillP Offline
              petewill
              Admin
              wrote on last edited by
              #7

              @pgregg88 said in Video How To: Battery Powered Chair Occupancy (Contact) Sensor:

              I experimented with the following, but my knowledge of 2.2 and interrupt challenges is limited. My attempt was to reduce the sensor state checks from 3 to 1, but I failed at that. I assume it might be better to change the approach, but didn't want to start hacking your code goodness with my lack of 2.2 knowledge.

              If you're using this for contact or motion sensors I would remove most of my code as it's not needed. For the motion sensor code it can be really simple as you don't even need a debounce. Check out the motion sensor sketch in the MySensors library. Really all you need is a digitalRead then send that value.
              For the contact sensors I would just use a wait(20); and then read the sensor again to make sure it's still the same value (or you could use the debounce library). You can also check out the code in the binary sleep sensor and pull from that https://github.com/mysensors/MySensors/blob/development/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino#L94

              My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

              1 Reply Last reply
              0
              • Nca78N Nca78

                Thank a lot for the idea and for the video explaining the implementation.

                Did you check the power consumption when you don't send battery life at regular intervals ? If you set the wake up only on interrupt then current in sleep mode goes from 5-6uA to 2 when contact is opened. It's so low that you don't really need regular reporting of battery life. I do that and report battery life only on opening/closing of doors/windows and my battery life is great even on chinese CR2032 cells (still over 85% on my entrance door).
                I guess it would drop to 5-6µA when sensor is connected ?

                petewillP Offline
                petewillP Offline
                petewill
                Admin
                wrote on last edited by petewill
                #8

                @Nca78 Wow, cool. I never got readings down to 2uA. Maybe my multimeter isn't very good or something else...? The main reason I regularly report the battery is to provide a heartbeat as well as reset the sensor if for some reason it could not communicate with the gateway the first time.

                Edit: I just re-read your post. I now see that you were saying I could save those additional uA by not using the sleep. That is a good idea. I'm still a little torn on the idea because I like the assurance of the heartbeat. I'll have to think about it. Thanks for sharing though!

                My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                1 Reply Last reply
                1
                • JicJ Offline
                  JicJ Offline
                  Jic
                  wrote on last edited by Jic
                  #9

                  That doesn't work to me! :( I am using an arduino clone. I don't Know if that is the problem.

                  When I use your sketch (an others from Mysensors) my Arduino usage is 30mA, seems like the sleep method doesn't work rigth.

                  I test with a liltle example from rocketscream/Low-Power and then my Arduino usage is 16uA. Anyone know where the problem may be?

                  Thanks

                  sundberg84S mfalkviddM petewillP 3 Replies Last reply
                  0
                  • JicJ Jic

                    That doesn't work to me! :( I am using an arduino clone. I don't Know if that is the problem.

                    When I use your sketch (an others from Mysensors) my Arduino usage is 30mA, seems like the sleep method doesn't work rigth.

                    I test with a liltle example from rocketscream/Low-Power and then my Arduino usage is 16uA. Anyone know where the problem may be?

                    Thanks

                    sundberg84S Offline
                    sundberg84S Offline
                    sundberg84
                    Hardware Contributor
                    wrote on last edited by
                    #10

                    @Jic did you remove the led and voltage regulator?

                    Controller: Proxmox VM - Home Assistant
                    MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                    MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                    RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                    JicJ 1 Reply Last reply
                    0
                    • sundberg84S sundberg84

                      @Jic did you remove the led and voltage regulator?

                      JicJ Offline
                      JicJ Offline
                      Jic
                      wrote on last edited by
                      #11

                      @sundberg84

                      Yes, I have removed both

                      sundberg84S 1 Reply Last reply
                      0
                      • JicJ Jic

                        That doesn't work to me! :( I am using an arduino clone. I don't Know if that is the problem.

                        When I use your sketch (an others from Mysensors) my Arduino usage is 30mA, seems like the sleep method doesn't work rigth.

                        I test with a liltle example from rocketscream/Low-Power and then my Arduino usage is 16uA. Anyone know where the problem may be?

                        Thanks

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

                        @Jic 30mA is way too high even for an unmodified Arduino that is fully awake. There must be something wrong with the Arduino or the measurement.

                        1 Reply Last reply
                        0
                        • JicJ Jic

                          @sundberg84

                          Yes, I have removed both

                          sundberg84S Offline
                          sundberg84S Offline
                          sundberg84
                          Hardware Contributor
                          wrote on last edited by
                          #13

                          @Jic - you should see in the serial debug if the node is sleeping or not. I have heard there might be a problem with sleep in som recent version. Maybe you investigate this and if nessecaru upgrade to development branch.

                          Controller: Proxmox VM - Home Assistant
                          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                          1 Reply Last reply
                          1
                          • JicJ Jic

                            That doesn't work to me! :( I am using an arduino clone. I don't Know if that is the problem.

                            When I use your sketch (an others from Mysensors) my Arduino usage is 30mA, seems like the sleep method doesn't work rigth.

                            I test with a liltle example from rocketscream/Low-Power and then my Arduino usage is 16uA. Anyone know where the problem may be?

                            Thanks

                            petewillP Offline
                            petewillP Offline
                            petewill
                            Admin
                            wrote on last edited by
                            #14

                            @Jic In addition to the great suggestions above also try to disconnect all the sensors and measure again. I had two bad radios that were using way too much power. Bad clones I guess.

                            My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                            1 Reply Last reply
                            0
                            • OliverDogO Offline
                              OliverDogO Offline
                              OliverDog
                              wrote on last edited by
                              #15

                              Thanks for sharing this awesome project...

                              I want to install all my windows with reed sensors powered by 2AA alcaline batteries and would like they last more than 5 years... and I think your project fits perfectly
                              How long do those used batteries last?

                              Did you implement what @Nca78 suggested?

                              I have already cut LED and Power Regulator from Arduino Pro Mini 3.3v and will change bootloader.
                              Have you choosen the best (lowest power consumption) bootloader to use?

                              I would try the MYSBootloader_1MHz.hex from MySensors GitHub.
                              Would the optiboot_atmega328_01M_009600_NOLED from GertSanders better for low power?

                              Thanks for the help...

                              Nca78N 1 Reply Last reply
                              0
                              • OliverDogO OliverDog

                                Thanks for sharing this awesome project...

                                I want to install all my windows with reed sensors powered by 2AA alcaline batteries and would like they last more than 5 years... and I think your project fits perfectly
                                How long do those used batteries last?

                                Did you implement what @Nca78 suggested?

                                I have already cut LED and Power Regulator from Arduino Pro Mini 3.3v and will change bootloader.
                                Have you choosen the best (lowest power consumption) bootloader to use?

                                I would try the MYSBootloader_1MHz.hex from MySensors GitHub.
                                Would the optiboot_atmega328_01M_009600_NOLED from GertSanders better for low power?

                                Thanks for the help...

                                Nca78N Offline
                                Nca78N Offline
                                Nca78
                                Hardware Contributor
                                wrote on last edited by Nca78
                                #16

                                @OliverDog if you are using 2xAA then 6uA in sleep mode is fine for a few decades.
                                You can estimate battery life there, if you don't spend your time jumping on your chair it should last the 5 years easily ;)
                                http://oregonembedded.com/batterycalc.htm

                                For the bootloaders battery life won't be different, any bootloader using internal oscillator at 1MHz is fine.

                                1 Reply Last reply
                                1
                                • OliverDogO Offline
                                  OliverDogO Offline
                                  OliverDog
                                  wrote on last edited by
                                  #17

                                  Great!!! Got it working, but can't measure the consumption...
                                  My multimeter shows always 000.
                                  The sensors is working fine and reporting properly while connected to multimeter, but always 0 current...
                                  Tried 200u, 2000u, 20m and 200m, always reporting zero... Is is that low?

                                  Did I connect something wrong??? (multimeter in series with positive battery pole and circuit line in (Radio+APM+1M ResistorPin3)
                                  Or is my aliexpress multimeter that bad???

                                  0_1502410544175_20170810_210709.jpg

                                  Nca78N 1 Reply Last reply
                                  0
                                  • OliverDogO OliverDog

                                    Great!!! Got it working, but can't measure the consumption...
                                    My multimeter shows always 000.
                                    The sensors is working fine and reporting properly while connected to multimeter, but always 0 current...
                                    Tried 200u, 2000u, 20m and 200m, always reporting zero... Is is that low?

                                    Did I connect something wrong??? (multimeter in series with positive battery pole and circuit line in (Radio+APM+1M ResistorPin3)
                                    Or is my aliexpress multimeter that bad???

                                    0_1502410544175_20170810_210709.jpg

                                    Nca78N Offline
                                    Nca78N Offline
                                    Nca78
                                    Hardware Contributor
                                    wrote on last edited by Nca78
                                    #18

                                    Clean desk you have here @OliverDog this would make my wife dream :D

                                    For the multimeter, no idea. At 200u it should see something, maybe your red wire is in the wrong plug of the multimeter ? Usually it's a different plug for voltage and for current but you can have a different plug for high current (A) and low current (mA) too...

                                    1 Reply Last reply
                                    1
                                    • OliverDogO Offline
                                      OliverDogO Offline
                                      OliverDog
                                      wrote on last edited by
                                      #19

                                      I had just cleaned it!!! My wife gave up caring about this desk...:smirk:

                                      I found my multimeter fuse was burned... so I wired its base poles and now I can measure:

                                      Sleeping + Reed Disconnected - most time 6 uA
                                      Sleeping + Reed Connected - most time 9 uA
                                      When sending new status to gateway - 25 - 230 uA (around 140 uA most times)
                                      Sending time was less than 1 second.

                                      2 AA will give me 29 years (battery certainly will die first)
                                      2 AAA - 12 years.
                                      1 CR2032 - 2,5 years.

                                      Thanks for the help...

                                      1 Reply Last reply
                                      2
                                      • Nca78N Offline
                                        Nca78N Offline
                                        Nca78
                                        Hardware Contributor
                                        wrote on last edited by
                                        #20

                                        @OliverDog when sending to gateway you cannot trust your multimeter. It's probably around 15mA but only during a fraction of a second, and what you read is some kind of average between that and the very low power consumption in sleep mode.

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


                                        29

                                        Online

                                        11.7k

                                        Users

                                        11.2k

                                        Topics

                                        113.1k

                                        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