What is the correct message type for a security sirene? And how can I hookup a 9V piezo buzzer to the arduino?


  • Contest Winner

    I'm trying to figure out the correct message type for a MySensors Security Sirene node.

    I tried V_TRIPPED with S_SOUND but the sensor didn't appear in Domoticz. I'm using V_LIGHT again, but it Domoticz sees that as a light as expected. But I want it to appear as a sirene.

    // Declare messages that will be sent to the MySensor's gateway.
    MyMessage sireneMsg( SIRENE_CHILD_ID, V_LIGHT ); // trying to figure out what type to use to make it known as a security sirene..???
    

    I present it as a light, but I'm looking for a S_SOUND

    gw.present( SIRENE_CHILD_ID, S_LIGHT, "Sirene" );
    

    As of now I hooked a 3V piezo buzzer to the Arduino Pro Mini 3.3V which is not really loud. Which is okay for now, I'll be using it as an extra wakeUp alarm. But also help on how to hook up a 9V Piezo to an arduino will be much appreciated.

    Thanx in advance

    Here's the code so far.

    /**
     * MySensors RoomSensor with piezo alarm for audio feedback, like weather alarm when there's a huricane alarm.
     * Version 1.0b
     * Created 10-10-2015
     * Author  by Theo
     *
     * Version history:
     * 10-10-2015 Initial version
     *
     * Parts used:
     * - Arduino ProMini 3.3V
     * - 3V Piezo buzzer GND connected to Arduino's GND and the + connected to PIN 5.
     *
     * Design decision's
     * - none at the moment.
     */
    
    #include <MySensor.h>
    #include <SPI.h>
    
    #define PIEZO_PIN 5       // The arduino pin to which the piezo buzzer is attached
    #define SIRENE_CHILD_ID 0 // The child ID of the sirene.
    #define PIEZO_ON_DURATION  600
    #define PIEZO_OFF_DURATION 500
    #define SIRENE_TONE 200   // The tone of the SIRENE. We use PWM so choose from 0 to 255 (0 is off b.t.w.)
    
    // define sketch name and version
    #define SN "Sirene"
    #define SV "1.0"
    
    boolean sireneOn = false;
    unsigned long nextPiezoEvent = 0;
    boolean piezoOn = false;
    
    // Declare and initialize objects.
    MySensor gw;
    
    // Declare messages that will be sent to the MySensor's gateway.
    MyMessage sireneMsg( SIRENE_CHILD_ID, V_LIGHT ); // trying to figure out what type to use to make it known as a security sirene..???
    
    /**
     * Initialize variables, arduino pins etc before we start the main loop.
     */
    void setup() {
    #ifdef DEBUG
      Serial.begin( 115200 ); // only debug to serial monitor during development
    #endif
      // setup a connection to the MySensor's gateway and request an ID if we do not have one yet.
      gw.begin(incomingMessage);
      gw.sendSketchInfo(SN, SV);
    #ifdef DEBUG
      Serial.println( "Radio is connect right." );
    #endif
    
      gw.present( SIRENE_CHILD_ID, S_LIGHT, "Sirene" );
      gw.sendBatteryLevel( 100, false ); // Let the Domotica controller know that we're a 100% powered sensor.
      gw.request( SIRENE_CHILD_ID , V_LIGHT ); // request current state. An alarm might be active.
      
      pinMode( PIEZO_PIN, OUTPUT);
    }
    /**
     * The next Sirene Event has occured. Determine next step.
    */
    void handlePiezoEvent() {
      unsigned long curMS = millis();
      if ( piezoOn == true ) {
        digitalWrite( PIEZO_PIN, 0 );
        nextPiezoEvent = curMS + PIEZO_OFF_DURATION;
        piezoOn = false;
      }
      else {
        analogWrite( PIEZO_PIN, SIRENE_TONE );
        nextPiezoEvent = curMS + PIEZO_ON_DURATION;
        piezoOn = true;
      }
    }
    
    /** 
     * Main loop of the sketch.
     */
    void loop() {
      if ( sireneOn == true &&  millis() >= nextPiezoEvent ) { // only play a tone when there's an actual alarm.
          handlePiezoEvent();
      }
      gw.wait( 50 ); // Just wait 50ms not really necessary but give the arduino some rest. It's working really hard for us. Besides it calls gw.process() which we need for handling incomming messages.
    }
    
    /**
     * Call back handler, for handling messages send by the MySensors gateway
     */
    void incomingMessage(const MyMessage &message) {
      if ( message.type == V_LIGHT ) {
        if ( message.sensor == SIRENE_CHILD_ID ) {
          sireneOn = message.getBool();
          #ifdef DEBUG
            Serial.println( "Sirene state changed to " + (String)sireneOn );
          #endif
          if ( sireneOn == false ) {
            analogWrite( PIEZO_PIN, 0 ); // turn off the noise
          }
          else {
            nextPiezoEvent = 0;
            piezoOn = false;
          }
        }
      }
    }
    

  • Hardware Contributor

    Assuming you have the latest beta when you look at github s_sound should be supported:

    S_SOUND = 33, //Sound sensor V_LEVEL(in dB), V_TRIPPED, V_ARMED
    (https://github.com/domoticz/domoticz/blob/master/hardware/MySensorsBase.h)

    	V_ARMED = 15,					//Armed status of a security sensor. 1 = Armed, 0 = Bypassed	S_DOOR, S_MOTION, S_SMOKE, S_SPRINKLER, S_WATER_LEAK, S_SOUND, S_VIBRATION, S_MOISTURE
    
    	V_TRIPPED = 16,					//Tripped status of a security sensor. 1 = Tripped, 0 = Untripped	S_DOOR, S_MOTION, S_SMOKE, S_SPRINKLER, S_WATER_LEAK, S_SOUND, S_VIBRATION, S_MOISTURE
    

    The Sensor wont appear with the presentation. You need to send the tripped or armed status at startup.


  • Contest Winner

    @sundberg84 Thank you very much for your fast reply. I'll install that beta release on one of my spare Raspberry Pi's, because I'm afraid to install it on my production version. It gave me a hard time when I did that a couple of weeks ago. But MySensors support in the Beta sounds really great. Do you happen to know when there will be a new stable version of Domoticz??


  • Hardware Contributor

    No clue :(


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.