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. Troubleshooting
  3. PIR example doesn`t wake Mega 2560?

PIR example doesn`t wake Mega 2560?

Scheduled Pinned Locked Moved Troubleshooting
15 Posts 4 Posters 2.7k Views 3 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.
  • V vobi

    Hello all,

    I just wired and tested the Motion Sensor example, (https://www.mysensors.org/build/motion),
    but my Mega 2560 wont wake from sleep because of the interrupt when motion is detected.
    It always finishes the sleeping. I serialprinted the sleeps output, it always states -2.
    The motion sensor works, I can see that, when I shorten the sleep time (tested with 1 sec).
    I also tested the output of the PIR, it generates more than 3.7 volts.
    I`m using the latest library and IDE. I made my best to read all connected forum posts but didn't find a solution.
    Anyone please can check it if it works for him?
    Any help would be appreciated!
    Thanks!

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

    @vobi which pin (DIGITAL_INPUT_SENSOR) are you using?

    The following pins on the Mega has support for interrupt: 2, 3, 18, 19, 20, 21

    V 1 Reply Last reply
    0
    • mfalkviddM mfalkvidd

      @vobi which pin (DIGITAL_INPUT_SENSOR) are you using?

      The following pins on the Mega has support for interrupt: 2, 3, 18, 19, 20, 21

      V Offline
      V Offline
      vobi
      wrote on last edited by
      #3

      @mfalkvidd
      I follow exactly the example, so D3.
      But D2 also doesn't work.

      1 Reply Last reply
      0
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by gohan
        #4

        Same problem here. I tried pretty much anything without success so far. I still need to check pins other than D2 and D3

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vobi
          wrote on last edited by
          #5

          Thanks, I will test the sketch on UNO.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vobi
            wrote on last edited by
            #6

            So, I have tested the following:
            Sketch on Mega 2560,
            pin 3 with int1 - not working
            pin 3 with int5 - not working
            pin2, int0,4 - not working
            pins 18-21, (digitalPinToInterrupt(DIGITAL_INPUT_SENSOR)) - not working
            Sketch on UNO - works as it should!
            So definitely something strange going on with 2560s interrupts.
            Any advice?

            1 Reply Last reply
            0
            • gohanG Offline
              gohanG Offline
              gohan
              Mod
              wrote on last edited by
              #7

              It looks like the mega is not meant to be used as a sleeping node 😁

              mfalkviddM 1 Reply Last reply
              0
              • gohanG gohan

                It looks like the mega is not meant to be used as a sleeping node 😁

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

                @gohan nice catch. The return value -2 is defined as MY_SLEEP_NOT_POSSIBLE https://github.com/mysensors/MySensors/blob/fd417b66b25d66f8ac749a0c5e253e886598bac7/core/MySensorsCore.h#L82

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vobi
                  wrote on last edited by vobi
                  #9

                  Then what does it do when sleep is issued?
                  Because the defined sleep-time still has to pass...and it does "nothing" till that, and that something cannot be broken by interrupt?
                  What should be the good method to catch an interrupt, or a motion, without going thru the main loop crazy fast?
                  Why cant it sleep?

                  1 Reply Last reply
                  0
                  • scalzS Offline
                    scalzS Offline
                    scalz
                    Hardware Contributor
                    wrote on last edited by
                    #10

                    @vobi
                    i think mega2560 can go powerdown, but have not the hardware for testing.
                    What you could do for isolting the issue, is removing sleep and check if the interrupt triggers well (with a bool flag)

                    V 1 Reply Last reply
                    0
                    • scalzS scalz

                      @vobi
                      i think mega2560 can go powerdown, but have not the hardware for testing.
                      What you could do for isolting the issue, is removing sleep and check if the interrupt triggers well (with a bool flag)

                      V Offline
                      V Offline
                      vobi
                      wrote on last edited by
                      #11

                      @scalz
                      Thanks, I will try it, and report back.

                      1 Reply Last reply
                      0
                      • gohanG Offline
                        gohanG Offline
                        gohan
                        Mod
                        wrote on last edited by gohan
                        #12

                        I think the interrupt is triggered but it is just ignored by the sleep function, if the code I've been advised to use to check the interrupt is correct 😀

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          vobi
                          wrote on last edited by
                          #13

                          I have tested it, the interrupt indeed works fine.
                          So yes, because there is no sleep, it cannot be interrupted.
                          I still don`t understand why it cannot sleep.
                          And IMHO the interrupt should break the not-so-sleep-but-wait cycle anyway.
                          What do You think?

                          1 Reply Last reply
                          0
                          • gohanG Offline
                            gohanG Offline
                            gohan
                            Mod
                            wrote on last edited by
                            #14

                            I don't have this much deep knowledge on the chip, but my best guess is that there must be something different in the MEGA chip than the other on the at328p on the uno and mini pro. It could very well be that the MEGA is not designed to be a low power device, but I'll let others say something more appropriate :)

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              vobi
                              wrote on last edited by vobi
                              #15

                              According to Mr. Nick Gammon, thats not the case (or I`m missing something):

                              Running from a 9V battery through the "power in" plug, it draws about 50 mA.
                              Running on 5V through the +5V pin, it draws about 49 mA.
                              (Note: around 68 mA on a Mega 2560 board)
                              Now we'll try putting it to sleep:
                              Sketch B

                              #include <avr/sleep.h>
                              void setup () 
                              {
                                set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
                                sleep_enable();
                                sleep_cpu ();  
                              }  // end of setup
                              void loop () { }
                              

                              Now the Uno draws 34.5 mA. A saving, but not a lot.
                              (Note: around 24 mA on a Mega 2560 board)
                              http://www.gammon.com.au/power

                              Also see:
                              https://forum.arduino.cc/index.php?topic=76724.0

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


                              20

                              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