Door Sensor / Mini Pro Clone Interrupt


  • Hardware Contributor

    Hello,

    i have some Trouble with my Door Sensor.
    The Sensor works fine, but if i use the gw.sleep function they don't wake up. I try D2 and D3. Nothing happens. . . .

    Herre is my Sketch:

    
    #include <SPI.h>
    #include <MySensor.h>
    #include <Bounce2.h>
    
    
    #define CHILD_ID 1
    #define CHILD_ID_BATT 3
    #define SENSOR_ID 30
    #define BUTTON_PIN 3
    #define INTERRUPT 1
    
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    
    #define SLEEP_TIME 600000
    
    MySensor gw;
    
    Bounce debouncer = Bounce(); 
    int oldValue=-1;
     
    int batterie_check = 0;
    float normaldeltabatt = 0.400;
    float batteriezwischen = 0;
    int interrupt = 1;
    
    MyMessage msg(CHILD_ID,V_TRIPPED);
    MyMessage msgVolt(CHILD_ID_BATT, V_VOLTAGE);
    
    void setup() {
      
      // use the 1.1 V internal reference
      analogReference(INTERNAL);
      gw.begin(NULL, SENSOR_ID);
      pinMode(BUTTON_PIN,INPUT);
      gw.sendSketchInfo("WoZi_Window", "1.0");
      digitalWrite(BUTTON_PIN,HIGH);
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      gw.present(CHILD_ID, S_DOOR);  
      
    }
    
    void loop() {
      
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
       
      if (value != oldValue) {
         // Send in the new value
         gw.send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
      }
    
      
    //  if (batterie_check >= 30 || batterie_check < 1) { 
    //    // get the battery Voltage
    //    int sensorValue = analogRead(BATTERY_SENSE_PIN);
    //    float batteryValue = sensorValue * 0.0033140756302521;
    //    //int batteryPcnt = sensorValue / 10;
    //    batteriezwischen = batteryValue - 2;
    //    //Serial.println(batteriezwischen);
    //    float batteryPcnt = (batteriezwischen/normaldeltabatt) * 100;
    //
    //    Serial.print("Batt: ");
    //    Serial.print(batteryValue);
    //    Serial.println(" V");
    //    gw.send(msgVolt.set(batteryValue, 1));
    //    Serial.print("Battery Prozent: ");
    //    Serial.print(batteryPcnt);
    //    Serial.println(" %");
    //    gw.sendBatteryLevel(batteryPcnt);
    //    batterie_check = 1;
    //  } else {
    //    batterie_check++;  
    //  }
     
    gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME);
    
    }
    

  • Contest Winner

    could you post a schematic you use for the provided sketch? It's a bit hard to tell what's wrong, just by looking at your sketch.


  • Mod

    This will not affect the functionality of your sketch, but I suggest you change

    gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME);
    

    to

    gw.sleep(digitalPinToInterrupt(BUTTON_PIN) , CHANGE, SLEEP_TIME);
    

    and remove

    #define INTERRUPT 1
    

    to avoid mistakes if you change BUTTON_PIN but forget to change INTERRUPT.


  • Hardware Contributor

    Thanks for help. . . i dont now why but it works now.

    I Think i had an Hardware issues 😞

    Thanks!


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 1
  • 6

58
Online

11.4k
Users

11.1k
Topics

112.6k
Posts