Motion (PIR), actuator and Temp sensor



  • Hi,

    I'm trying to make and sensor, as subject says. I've got temp (DS18B20) and actuator working, but not the PIR (HC-SR501).

    PINs as follow:
    RADIO IRQ = PIN2
    Temp = PIN3
    PIR data = PIN4
    Actuator = PIN 5,6

    My question is now, does a PIR require an Interrupt PIN on the arduino (PIN 2,3) , or can I use any PIN?



  • Thats unfortunate question, as it all depends on the code you write..


  • Admin

    If you want to sleep the node, then using pin-interrrupt is a great way of waking the node when motion is detected.

    You can use use the radio-irq pin for you sensors. It is currently not used by the mysensors library.



  • Ok, so basicly you are saying, that the PIR DOESN'T require an irq pin on the arduino?



  • @hek said:

    If you want to sleep the node, then using pin-interrrupt is a great way of waking the node when motion is detected.

    You can use use the radio-irq pin for you sensors. It is currently not used by the mysensors library.

    So, not need to wire the radio IRQ PIN at all?


  • Admin

    @Hausner said:

    So, not need to wire the radio IRQ PIN at all?

    No

    Ok, so basicly you are saying, that the PIR DOESN'T require an irq pin on the arduino?

    No, you can poll it yourself if you stay awake.



  • Ok, finally got it to work with this:

    // Example sketch showing how to control physical relays. 
    // This example will remember relay state even after power failure.
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
    #define MAX_ATTACHED_DS18B20 16
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    //boolean receivedConfig = false;
    boolean metric = true;
    #define RELAY_1 5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define RELAY_2 6
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    // Motion sensor defs
    unsigned long SLEEP_TIME = 10000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 4   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    //#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 3   // Id of the sensor child
    
    boolean lastTrippedState;
    
    MySensor gw;
    //
    MyMessage msgTemp(0, V_TEMP);
    MyMessage msgRelay2(2, V_LIGHT);
    MyMessage msgMotion(3, V_TRIPPED);
    
    void setup()  
    {   
      gw.begin(incomingMessage, AUTO, true);
      gw.sendSketchInfo("Temp/Relay/Motion Sensor", "1.0");
      //
      gw.present(1, S_LIGHT);
      pinMode(RELAY_1, OUTPUT);
      //
      gw.present(2, S_LIGHT);
      pinMode(RELAY_2, OUTPUT);
      digitalWrite(RELAY_1, gw.loadState(1)? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_2, gw.loadState(1)? RELAY_ON : RELAY_OFF);
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      //
      gw.present(CHILD_ID, S_MOTION);
      
      // Fetch the number of attached temperature sensors  
      //numSensors = sensors.getDeviceCount();
    
      // Present all sensors to controller
      //for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
         gw.present(0, S_TEMP);
      //}
    }
    //
    void loop() 
    {
      gw.process();
      boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
      if (tripped != lastTrippedState)
      {  
        Serial.println(tripped? "tripped" : "not tripped");
        gw.send(msgMotion.set(tripped?"1":"0"));  // Send tripped value to gw//
        //digitalWrite(RELAY_1, tripped? 1 : 0);
      }
      lastTrippedState = tripped;
      
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures(); 
    
      // Read temperatures and send them to controller 
      //for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(0):sensors.getTempFByIndex(0)) * 10.)) / 10.;
    
        // Only send data if temperature has changed more then 1 degC and no error
        if (int(lastTemperature[0]) != int(temperature) && temperature != -127.00) { //added integer
    
          // Send in the new temperature
          gw.send(msgTemp.setSensor(0).set(temperature,1));
          lastTemperature[0]=temperature;
        }
       //}
    }
    
    void incomingMessage(const MyMessage &message) {
      // 
      if (message.type==V_LIGHT && message.sensor == 2) 
      {
        // Change relay state
        digitalWrite(RELAY_2, message.getBool()?RELAY_ON:RELAY_OFF);
        // Store state in eeprom
        gw.saveState(message.sensor, message.getBool());
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

Log in to reply
 

Suggested Topics

  • 87
  • 1
  • 2
  • 5
  • 7
  • 8

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts