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. Development
  3. Using Sleep RISING mode with momentary switch?

Using Sleep RISING mode with momentary switch?

Scheduled Pinned Locked Moved Development
sleep
2 Posts 2 Posters 993 Views 2 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.
  • Sergio RiusS Offline
    Sergio RiusS Offline
    Sergio Rius
    wrote on last edited by
    #1

    I'm trying to make a sensor for garden doorbell duties. So I built a battery powered sensor with a momentary switch wired to pin 3 using a pull down resistor.
    My intention is to make it detect when someone pushes the button (obviously) but not changing the state to off as the button is released, but using a timer.
    With that maneuver I want to be able to make a camera send me the video while that timer is active.
    Also, as the sensor is battery powered, It will also sleep for a longer time and wake on the pin interrupt.

    So I thought that it could be clean and nice only waking the sensor on the button pushed and only changing the amount of sleep.
    In my code I used the sleep function with the RISING mode, but I found that it triggers with the on, but also the off state of the switch.

    I made a nasty hack and put a delay to neglect the pulling up of the button, but is there any solution?

    There's my code:

    // Loop will iterate on changes on the BUTTON_PINs
    void loop() 
    {
      uint8_t value = digitalRead(PRIMARY_BUTTON_PIN);
      unsigned long sleepTime = value==HIGH ? SHORT_PAUSE : SLEEP_TIME;
      send(msg.set(value==HIGH ? 1 : 0));
      digitalWrite(FEEDBACK_LED_PIN, value);
    
    #ifdef MY_DEBUG
       Serial.println(value==HIGH ? "Button press detected!" : "Reset!");
       Serial.print("New values: "); Serial.print(value); Serial.print(" / "); Serial.println(sleepTime);
    #endif
    
      SendBatteryLevel();
    
      delay(5000);
      
      // Sleep until something happens with the sensor
      sleep(PRIMARY_BUTTON_PIN-2, RISING, sleepTime);
    }```
    mfalkviddM 1 Reply Last reply
    0
    • Sergio RiusS Sergio Rius

      I'm trying to make a sensor for garden doorbell duties. So I built a battery powered sensor with a momentary switch wired to pin 3 using a pull down resistor.
      My intention is to make it detect when someone pushes the button (obviously) but not changing the state to off as the button is released, but using a timer.
      With that maneuver I want to be able to make a camera send me the video while that timer is active.
      Also, as the sensor is battery powered, It will also sleep for a longer time and wake on the pin interrupt.

      So I thought that it could be clean and nice only waking the sensor on the button pushed and only changing the amount of sleep.
      In my code I used the sleep function with the RISING mode, but I found that it triggers with the on, but also the off state of the switch.

      I made a nasty hack and put a delay to neglect the pulling up of the button, but is there any solution?

      There's my code:

      // Loop will iterate on changes on the BUTTON_PINs
      void loop() 
      {
        uint8_t value = digitalRead(PRIMARY_BUTTON_PIN);
        unsigned long sleepTime = value==HIGH ? SHORT_PAUSE : SLEEP_TIME;
        send(msg.set(value==HIGH ? 1 : 0));
        digitalWrite(FEEDBACK_LED_PIN, value);
      
      #ifdef MY_DEBUG
         Serial.println(value==HIGH ? "Button press detected!" : "Reset!");
         Serial.print("New values: "); Serial.print(value); Serial.print(" / "); Serial.println(sleepTime);
      #endif
      
        SendBatteryLevel();
      
        delay(5000);
        
        // Sleep until something happens with the sensor
        sleep(PRIMARY_BUTTON_PIN-2, RISING, sleepTime);
      }```
      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by mfalkvidd
      #2

      @Sergio-Rius delay is actually the easiest way to do it :) Either that, or build a hardware debouncer.

      See also https://www.mysensors.org/build/binary for how to use the bounce2 library to handle debouncing. That solution doesn't support interrupts though, so delay is probably a better solution for your node.

      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