Combine multisensor with switch



  • Hey Guys,

    I want to build a USB-powered-sensor. I need to change an internal variable per switch. There is not a pin to be driven.

    link to sketch

    I have not yet understood how the interrupt and the time for reading the sensors is maintained. is that even possible?

    Regards,
    n3ro



  • Not sure I completely understand what you are wanting to accomplish, are you wanting to change some variable in your code from the z-wave controller? This is possible(limited), but we need to know a little before we can help you with this. What type of variable are you wanting to chance(bool, int, float, char, string)?

    Interrupts and read times:
    Assuming you uncomment the code you have in your loop; the line that reads "gw.sleep(PIR_SENSOR_DIGITAL - 2, CHANGE, SLEEP_TIME);" is what is controlling the interrupt and sleep timing. This is saying that if the PIR_SENSOR_DIGITAL pin CHANGE(s) states, continue the loop. SLEEP_TIME sets the amount of time between triggering a timer interrupt(in other words the amount of time before continuing even if the PIR interrupt is not triggered).



  • Hey 😃
    Sorry my question wasn't good.

    Let me explain what i mean.
    I have just updated my sketch in Github to make i a little bit better to understood (there is no z-wave component).

    I want to Build a USB-powered-sensor with the following functions:

    1. Read some Sensors every x Seconds (done with millis and working)
    2. Read a PIR (done and working without interrupt)
    3. Read AirQuality (implemented but never tested because i haven't this component at the moment)
    4. If Smoke is detected make alarm with beeper (same like the AirQuality Sensor)
    5. a switch to disable the beeper (i don't know how to implement this)

    I hope it's better to follow.

    Regards,
    n3ro

    Update:
    This is the beeper



  • What exactly should the switch do? Silence the alert till what?



  • @Jan-Gatzke

    Yes, i want to disable the Smoke alarm, because sometime i make really much smoke in the kitchen without any fire 😄


  • Hero Member

    @n3ro I read from you information that you need a kind of switch to disable some functionality in your sketch. You can implement this by creating booleans (best stored in EEPROM) that indicate the current state of the the switch. In the "incomingMessage" code frrom your sketch the framework is present (in the commented part). You can define a boolean for the Beeper which can be switched on/off by the incoming message.

    (you need to define the beeper_id as a switch (S_LIGHT) and the status beeperState first..

    void incomingMessage(const MyMessage &message) //Turn Alarm on/off
    {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type == V_LIGHT) {
         // Change beeper on/off  
        if (message.sensor == beeper_id){ 				// check if message is beeper
    		beeperState = message.getBool(); 
    		gw.saveState( message.sensor,  beeperState ); // save sensor state in EEPROM (location == sensor number)
    		}
        }
    }
    
    


  • @AWI cool!
    Now it works but i cant switch it off every time. i have to stitch it on and off again multiple times to deactivate it


  • Hero Member

    @n3ro Probably a receive error. Put a Serial.print statement in the incomingMessage part and see if it receives messages.



  • @AWI you are right. i get this on the GW:

    <- I_LOG_MESSAGE 0;0;3;0;9;send: 0-0-10-10 s=5,c=1,t=2,pt=0,l=1,st=fail:0
    -> Sending 10;5;1;1;2;1

    <- I_LOG_MESSAGE 0;0;3;0;9;send: 0-0-10-10 s=5,c=1,t=2,pt=0,l=1,st=fail:1
    -> Sending 10;5;1;1;2;0

    It is possible that the node only accept the switching signal in the "right" moment?


  • Hero Member

    @n3ro As long as your node is frequently using the gw.process() statement then it will receive the sent messages. Can be any kind of radio disturbance i.e. supply / noise / interference with other 2.4 GHz sources. I would do a few tests with sending messages back and forth. A lot has been written on the forum with respect to "fail" messages.


Log in to reply
 

Suggested Topics

  • 1
  • 10
  • 6
  • 1
  • 3
  • 2

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts