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. Hardware
  3. Motion (PIR), actuator and Temp sensor

Motion (PIR), actuator and Temp sensor

Scheduled Pinned Locked Moved Hardware
7 Posts 3 Posters 3.8k Views 1 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.
  • H Offline
    H Offline
    Hausner
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andriej
      wrote on last edited by
      #2

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

      :-)

      1 Reply Last reply
      0
      • hekH Offline
        hekH Offline
        hek
        Admin
        wrote on last edited by
        #3

        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.

        H 1 Reply Last reply
        0
        • H Offline
          H Offline
          Hausner
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • hekH hek

            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.

            H Offline
            H Offline
            Hausner
            wrote on last edited by
            #5

            @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?

            hekH 1 Reply Last reply
            0
            • H Hausner

              @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?

              hekH Offline
              hekH Offline
              hek
              Admin
              wrote on last edited by hek
              #6

              @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.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hausner
                wrote on last edited by
                #7

                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());
                  }
                }
                
                1 Reply Last reply
                1
                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