Relay / Motion Multisensor



  • Hi, I thought I would share my newest project with you Guys.
    This project is a multisensory, containing a relay and a motion sensor.

    The project is powered by 230V and has a small 5V power supply in the box as well.
    What I used:
    HC-SR501 PIR
    1 channel relay
    Arduino Pro Mini 5V
    NRF24L01+
    AMS1117 5V-3.3V Step Down Module
    1A 5V Power Supply from Ebay

    Code:
    MultiSensor_Relay_Motion.ino

    Pictures:
    image2.jpeg
    image1.jpeg
    image3.jpeg image5.jpeg image6.jpeg

    The Multisensor is used in my basement room, and turns on the light if there is motion, when I enter the room.
    The logic is made by PLEG on a Vera3



  • Very nice.


  • Admin

    Nice! But you should probably isolate the high voltage parts a bit. We wouldn't want a MySensors related fire started.


  • Hero Member

    @hek said:

    Nice! But you should probably isolate the high voltage parts a bit. We wouldn't want a MySensors related fire started.

    +1 on that one!



  • @ServiceXp @hek Here just a little update

    I have now glued all parts to the box, and added a plastic cover over the part with 230V

    Billede 30-01-15 18.44.44.jpg
    Billede 30-01-15 18.47.20.jpg

    so now nothing should be able to touch and it looks a bit nicer.



  • Hello

    i want to make a similar project but i want to add a dht22 with this sketch
    have you a sketch with a dht because i have a problem with mine

    thanks



  • @madmax good idea I have some DHT22 lying around. But I have not tried making a multi sensor with them.

    Have You tried the skech from the site, I tried it and it work on mine?



  • @Dalhoj i use this and it's working fine

    i want to include another relay and it's ok for me

    #include <SPI.h>
    #include <MySensor.h>
    #include <Wire.h>
    #include <DHT.h>
    #include <SimpleTimer.h>
    
    #define CHILD_ID_HUM 1
    #define CHILD_ID_TEMP 2
    #define CHILD_ID_MOTION 3
    #define CHILD_ID_RELAY 4
    
    #define HUMIDITY_SENSOR_DIGITAL_PIN 19
    #define MOTION_SENSOR_DIGITAL_PIN 3
    #define INTERRUPT MOTION_SENSOR_DIGITAL_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define RELAY  8  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
    unsigned long SLEEP_TIME = 600000; // Sleep time between reads (in milliseconds) - 10mins
    
    MySensor gw;
    DHT dht;
    SimpleTimer timer;
    
    float lastTemp;
    float lastHum;
    boolean lastTripped;
    boolean metric = true;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msg(CHILD_ID_MOTION, V_TRIPPED);
    
    void setup()  
    { 
      // Initialize library and add callback for incoming messages
      gw.begin(incomingMessage, AUTO, true);
      
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("HumTempRelayMotion", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      gw.present(CHILD_ID_MOTION, S_MOTION);
      gw.present(CHILD_ID_RELAY, S_LIGHT);
      pinMode(RELAY, OUTPUT);
      digitalWrite(RELAY, gw.loadState(RELAY)?RELAY_OFF:RELAY_ON);
      
      //Serial.begin(9600);
      timer.setInterval(30000, getMeasure);
      metric = gw.getConfig().isMetric;
      
    }
    
    void loop()      
    {  
      // Alway process incoming messages whenever possible
      gw.process();
      timer.run();
      
      boolean tripped = digitalRead(MOTION_SENSOR_DIGITAL_PIN) == HIGH;    
      if (tripped != lastTripped) {
        lastTripped = tripped;
        Serial.print("M: ");
        Serial.println(tripped);
        gw.send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
      }
    
    }
    
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-CHILD_ID_RELAY+RELAY, 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());
       } 
    }
    
    void getMeasure() {
      delay(dht.getMinimumSamplingPeriod());
    
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
    }
    


  • hello, just looking to use this project to try and set up a motion triggered sprinkler to scare away some rabbits eating my plants and grass. Thinking of the relay triggering a 24v valve, my only problem is how do I extend the time the replay is closed, thinking I only need to spray water for 5-10secs... any tips would be greatly appreciated.

    thanks



  • Guys, I would like to use this sketch with dht but on Uno and with 8 relays and use analog pins...
    Should I Just change part:

    #define RELAY 8
    To
    #define RELAY A0
    ?


  • Hardware Contributor

    This project got me inspired, so I made this:

    IMG_7318.jpg

    Same PIR, no relay on this board yet. To test the principle (and sketch) I used a red LED. The kicker is that I can send an SMS ("LED ON") to this board to switch on the LED, and another (... "LED OFF" tada !) to switch it back off. I can ask "STAT?" and it sends me an SMS with the status of all analog/digital ports. And when the PIR "fires" I get a prowl message via Domoticz. Call me a kid, blame the glas of wine I just had, but this is super fun !!!!!



  • @Ashley-Savage
    ah mis read the code... build circuit and sorted my timer via my vera with a timer to switch off relay after 5 secs...



  • Has anyone the code for mysensors 2.1?
    It doesnt work for me in 2.1 ๐Ÿ˜•
    Please help



  • I need your help pls ๐Ÿ˜•


Log in to reply
 

Suggested Topics

10
Online

11.4k
Users

11.1k
Topics

112.7k
Posts