Announcement

Collapse
No announcement yet.

Pics of a simple motion sensor - AC powered

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Pics of a simple motion sensor - AC powered

    In my guest bath, I have an Insteon motion sensor that I use to turn on the lights when someone enters. It works although it has a noticeable delay from when you walk in to when the lights turn on. So far my Arduino based motion sensors have been faster so I thought I would build a simple PIR based motion sensor and see if it does better. It is designed to plug into a wall outlet.

    Here are some pics:
    Attached Files

    #2
    That's interesting... Are you using an Arduino nano?

    Robert
    HS3PRO 3.0.0.500 as a Fire Daemon service, Windows 2016 Server Std Intel Core i5 PC HTPC Slim SFF 4GB, 120GB SSD drive, WLG800, RFXCom, TI103,NetCam, UltraNetcam3, BLBackup, CurrentCost 3P Rain8Net, MCsSprinker, HSTouch, Ademco Security plugin/AD2USB, JowiHue, various Oregon Scientific temp/humidity sensors, Z-Net, Zsmoke, Aeron Labs micro switches, Amazon Echo Dots, WS+, WD+ ... on and on.

    Comment


      #3
      Originally posted by langenet View Post
      That's interesting... Are you using an Arduino nano?

      Robert
      Nope. I'm using the nodeMCU. It is a version of the ESP 8266. It has built in wifi and works with the Arduino IDE as well as the plugin. Cost on eBay is about $4 each. PIRs can be had for $1.

      Comment


        #4
        Thanks for that... wow, these things are amazing and I'll have to get some to play with as well. Still new in the Arduino world and hadn't ever realized the potential of this architecture...

        Robert
        HS3PRO 3.0.0.500 as a Fire Daemon service, Windows 2016 Server Std Intel Core i5 PC HTPC Slim SFF 4GB, 120GB SSD drive, WLG800, RFXCom, TI103,NetCam, UltraNetcam3, BLBackup, CurrentCost 3P Rain8Net, MCsSprinker, HSTouch, Ademco Security plugin/AD2USB, JowiHue, various Oregon Scientific temp/humidity sensors, Z-Net, Zsmoke, Aeron Labs micro switches, Amazon Echo Dots, WS+, WD+ ... on and on.

        Comment


          #5
          Thanks for the nice pictures, could you please also post the code for the Arduino and perhaps the pins, there are some people here including me that would find it very helpful. Greig, would it be possible to make it stay on the top? I intend to document also my soil sensor when I'm done with that. For us new to Arduino everything is so challenging...
          Thanks

          Sent from my SM-G935V using Tapatalk

          Comment


            #6
            Nice find on the wifi board? How are you tying it back to HS? Initially I was using the mysensors plugin as it had its own wireless network, but when development fell off, I switched to the arduino plugin

            Comment


              #7
              Originally posted by waynehead99 View Post
              Nice find on the wifi board? How are you tying it back to HS? Initially I was using the mysensors plugin as it had its own wireless network, but when development fell off, I switched to the arduino plugin
              I don't know how Robert is doing it, but Enigmatheatre's plug-in works with the NodeMCU out for f the box. I am not using them in production, but when Greig was adding support for them last year, I had 5 of them connected and running an input/output cycle test for almost 30 days without a failure in the test or a disconnect.

              Unfortunately Greig's plug-in server URL is not resolving right now so if your version doesn't support the NodeMCU you will have to wait until he fixes that. The beta has support for the boards and I think even the release version has this support.

              EDIT: Greig just posted he is looking into the server problem.

              The NodeMCU support is limited to digital I/O and an LCD, but I think he plans on adding OneWire and possibly analog support.
              HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

              Comment


                #8
                Originally posted by rprade View Post
                I don't know how Robert is doing it, but Enigmatheatre's plug-in works with the NodeMCU out for f the box. I am not using them in production, but when Greig was adding support for them last year, I had 5 of them connected and running an input/output cycle test for almost 30 days without a failure in the test or a disconnect.

                Unfortunately Greig's plug-in server URL is not resolving right now so if your version doesn't support the NodeMCU you will have to wait until he fixes that. The beta has support for the boards and I think even the release version has this support.

                EDIT: Greig just posted he is looking into the server problem.

                The NodeMCU support is limited to digital I/O and an LCD, but I think he plans on adding OneWire and possibly analog support.
                I'm using the nodeMCU chip and the Arduino IDE version 1.8.2 along with Greig's Arduino plugin version 1.0.0.142. I use the nodeMCU API version of the sketch. When using the API sketch version with the nodeMCU, you have access to all the pins which include one analog one.

                As far as posting my sketch, below you will find the custom code that is added at the first of the API sketch. It includes code for 4 different types of sensors (PIR motion, magnetic door/window, simple leak sensor, and temp/humidity sensor. It may not be the prettiest but it works.

                Also, here is a link to a thread dealing with a multi-sensor I built. It includes pics.

                https://forums.homeseer.com/showthread.php?t=188366


                Code:
                //**************Declare your variables here******************* 
                
                #include <SimpleDHT.h>
                //#include <OneWire.h>
                //#include <DallasTemperature.h>
                
                //  This is the place where you define the hardware that is attached to this device. That hardware attaches thru a PIN on the Arduino.
                //  PINS (cross referencing the UNO to the 12E)
                
                int DHT11Sensor  = 2;     //  ESP 12E pin D4
                int MotionSensor = 13;    //  ESP 12E pin D7
                int DoorSensor   = 12;    //  ESP 12E pin D6    This is a device that is either/or. Both can't co-exist since they share pin 12 (ESP D6). Set one or the other for the pin
                int LeakSensor = 0;       //  ESP 12E pin D6    This is the alternative to the door sensor, another binary device. Logic below is a bit different.
                
                /*int DS18B20_Sensor = 4;    //  ESP 12E pin D2
                
                OneWire oneWire(DS18B20_Sensor);
                
                // vars used within this Sketch (locally)
                int Loop_Delay = 1000;
                int pirState = LOW;             // we start, assuming no motion detected
                int val = 0;                    // variable for reading the pin status
                */
                
                // DHT11 variables
                byte DHTTemperature = 0;
                byte DHTHumidity = 0;
                byte DHTData[40] = {0};
                int  DHTReturn;
                unsigned long DHTCurrentMillis = 0;
                unsigned long DHTPreviousMillis = 0;
                byte DHTTemperaturePrevious = 0;
                byte DHTHumidityPrevious = 0;
                
                /*
                // 18B20 variables
                
                // Pass our oneWire reference to Dallas Temperature.
                DallasTemperature sensors(&oneWire);
                
                float DS18B20_temp = 0;
                */
                
                SimpleDHT11 dht11;
                
                //motion PIR variables
                int PIRCurrentState = 0;
                int PIRPreviousState = -1;
                
                int DoorCurrentState = 0;
                int DoorPreviousState = 100;
                
                int LeakCurrentState = 0;
                int LeakPreviousState = 100;
                unsigned long LeakCurrentMillis = 0;
                unsigned long LeakPreviousMillis = 0;
                 
                void HSSetup() {
                  
                  //************************
                  //Add YOUR SETUP HERE;
                  //************************
                
                pinMode(DHT11Sensor, INPUT);
                pinMode(MotionSensor,INPUT);
                
                if (DoorSensor != 0) pinMode(DoorSensor, INPUT);
                if (LeakSensor != 0) pinMode(LeakSensor, INPUT);
                
                DHTCurrentMillis = millis();
                DHTPreviousMillis = millis();
                
                Serial.begin(9600);
                
                //sensors.begin();
                }
                
                
                void HSloop() {
                    //************************
                    //Add YOUR CODE HERE;
                    //************************
                    /* To Send Data to Homeseer use SendToHS(Device,Value)
                     Eg.. SendToHS(1,200); where 1 is the API device in homeseer and 200 is the value to send
                     To Recieve data from Homeseer look up the FromHS array that is updated when the device value changes.
                     Eg.. FromHS[5] would be the data from API Output device 5
                     All code that is located just below this block will execute regardless of connection status!
                     You can include SendToHS() calls, however when there isn't an active connection, it will just return and continue.
                     If you only want code to execute when HomeSeer is connected, put it inside the if statement below.
                     */
                
                    /*Execute regardless of connection status*/
                
                 
                
                 if (IsConnected == true) {
                   /*Execute ONLY when HomeSeer is connected*/
                
                
                 // **************  Start Motion Sensor *****************  
                  if (MotionSensor != 0) {  
                     PIRCurrentState = digitalRead(MotionSensor);
                     if (PIRCurrentState != PIRPreviousState) {
                        if (PIRCurrentState == HIGH) {
                           SendToHS(1,100);  
                        } 
                        else {
                           SendToHS(1,0);
                        }
                        PIRPreviousState = PIRCurrentState;   
                    }
                  }   
                // **************  End Motion Sensor *****************   
                
                // **************  Start Door Sensor ***************** 
                  if (DoorSensor != 0) {
                     DoorCurrentState = digitalRead(DoorSensor);
                     if (DoorCurrentState != DoorPreviousState) {
                        if (DoorCurrentState == HIGH) {
                           SendToHS(2,100);  
                        } 
                        else {
                           SendToHS(2,0);
                        }
                     DoorPreviousState = DoorCurrentState;   
                     }
                  }
                // **************  End Door Sensor ***************** 
                
                // **************  Start Water Leak Sensor ***************** 
                   if (LeakSensor != 0) {
                      LeakCurrentState = digitalRead(LeakSensor);
                      LeakCurrentMillis = millis();
                      if ((LeakCurrentMillis - LeakPreviousMillis) >= (1 * 60 * 1000)) {    // only update once per minute
                         if (LeakCurrentState != LeakPreviousState) {
                            if (LeakCurrentState == HIGH) {
                               SendToHS(2,100);  
                            } 
                            else {
                               SendToHS(2,0);
                            }
                            LeakCurrentMillis = millis();
                            LeakPreviousMillis = LeakCurrentMillis;
                            LeakPreviousState = LeakCurrentState;   
                         }
                      }
                  }
                // **************  End Water Leak Sensor ***************** 
                
                
                // **************  Start DHT11 Sensor *****************  
                  if (DHT11Sensor != 0) {
                     DHTCurrentMillis = millis();
                     if (DHTCurrentMillis - DHTPreviousMillis >= (5 * 60 * 1000)) {      // Update every 5 minutes
                        DHTReturn = 1;
                        DHTReturn = dht11.read(DHT11Sensor, &DHTTemperature, &DHTHumidity, NULL);
                        if (DHTReturn == 0) {
                           DHTTemperature =  (DHTTemperature * 18 + 5)/10 + 32;    // adjust from C to F
                           if (DHTTemperature != DHTTemperaturePrevious) {
                             SendToHS(3,DHTTemperature);
                             DHTTemperaturePrevious = DHTTemperature;
                           }
                           if (DHTHumidity != DHTHumidityPrevious) {
                             SendToHS(4,DHTHumidity);
                             DHTHumidityPrevious = DHTHumidity;
                           }        
                           DHTCurrentMillis = millis();
                           DHTPreviousMillis = DHTCurrentMillis;
                        }
                     }
                  }   
                // **************  End DHT11 Sensor *****************   
                
                  }    // end of 'if (IsConnected == true) {'
                
                }
                
                //************Do not change anything after Here*****************

                Comment


                  #9
                  Just finished building another of the motion sensors. Haven't put it in the case yet but thought you might like bare bones pics.

                  Power is going into the nodeMCU on the VIN and GND pins. The white wire goes from the PIR sensor to the nodeMCU on pin D7.

                  It is running the above sketch. Took about 30 minutes to build and most of that was cutting off the end of a USB cable and soldering on 2 positives and 2 negatives and then shrink.
                  Attached Files

                  Comment

                  Working...
                  X