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. Sensor sleep causing problems

Sensor sleep causing problems

Scheduled Pinned Locked Moved Development
4 Posts 4 Posters 1.1k Views 4 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.
  • signal15S Offline
    signal15S Offline
    signal15
    wrote on last edited by
    #1

    I'm using the Temp Sensor Example to build a freezer alarm. It has a beeper, and a button on it to silence the beeper.

    The code to make it beep is:

    digitalWrite(BUZZERPIN, HIGH);
    delay(500);
    digitalWrite(BUZZERPIN, LOW);
    delay(500);
    

    But, this temp sensor sketch has a built in delay of 30 seconds between reads. Which means that I get a couple of beeps, and then silence for 30 seconds. I also have a button that needs to be read, so if it's pressed, it sets a variable that silences the alarm. I'm pretty sure that cannot be read during sleep.

    'm guessing the answer is no, but is there a way to fork a thread that handles the buzzer, and another that looks for the button press? What is the solution to this? Do I just set the sleep to 1 second for the temp read and then just note that I have to hold the button until the button read happens and the buzzer stops?

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

      In case of alarm you can programmatically exclude the sleep so the loop runs continuously until temperature gets back to normal or button pressed, or use millis to count time according to the needs.

      PS Take a look at this and following article for inspiration

      1 Reply Last reply
      0
      • signal15S signal15

        I'm using the Temp Sensor Example to build a freezer alarm. It has a beeper, and a button on it to silence the beeper.

        The code to make it beep is:

        digitalWrite(BUZZERPIN, HIGH);
        delay(500);
        digitalWrite(BUZZERPIN, LOW);
        delay(500);
        

        But, this temp sensor sketch has a built in delay of 30 seconds between reads. Which means that I get a couple of beeps, and then silence for 30 seconds. I also have a button that needs to be read, so if it's pressed, it sets a variable that silences the alarm. I'm pretty sure that cannot be read during sleep.

        'm guessing the answer is no, but is there a way to fork a thread that handles the buzzer, and another that looks for the button press? What is the solution to this? Do I just set the sleep to 1 second for the temp read and then just note that I have to hold the button until the button read happens and the buzzer stops?

        Boots33B Offline
        Boots33B Offline
        Boots33
        Hero Member
        wrote on last edited by
        #3

        @signal15 You can achieve what you want but you will need to do as @gohan has indicated.
        When the Temperature is within normal limits use the normal code with sleep to save power.
        When a temperature outside the desired range is detected then bypass the normal temp code and run the different code needed to execute the beep etc.

        You will need to use non blocking delays for the beep and for the time between temp readings an example here

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

          Hello,

          I would do something much more simple

          At the beginning of the sketch :

          bool buzzerState = false;
          

          Then at the end of your sketch where you currently have the sleep() :

          if (AlarmModeIsActive) {
          buzzerState = not(buzzerState);  // invert state of buzzer
          digitalWrite(BUZZERPIN, buzzerState);
          sleep(BUZZER_PIN, CHANGE, 2000);  // Sleep but put interrupt on the button so we don't have to wait for a reaction when pushing the button
          }
          else {
            // here do normal sleep for your node
           sleep(30000);
          }
          

          Of course don't forget to reset buzzer state and set buzzer pin to low when button is pressed.

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


          10

          Online

          11.7k

          Users

          11.2k

          Topics

          113.0k

          Posts


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