Announcement

Collapse
No announcement yet.

Arduino - HC-SR04 Ultrasonic Sensor Distance Module

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

  • Arduino - HC-SR04 Ultrasonic Sensor Distance Module

    I have purchased the Arduino and this must be the coolest plugin so far to easily integrate with external devices. I'm looking forward to it and the Arduino. My first experiment would be to monitor the Sump Pump in the basement and check for water level. I noticed that they have these cool devices HC-SR04 Ultrasonic Sensor Distance Module that theoretically should display the water level. Would it be possible to integrate it in your plugin in the future?

    Thanks,
    Aldo

  • #2
    It is possible to do this now with the API sketch in the plugin. You would have to write some code but most of it you could copy and paste.

    Sent from my SM-G925F using Tapatalk
    Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
    X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
    Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
    Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
    Scripts =
    Various

    Comment


    • #3
      Your use case also seems like a good application for a water leak sensor. Of course it depends on the physical characteristics of the location.

      As far as water leak sensors, you can buy them for relatively cheap but you can also make one for next to nothing.

      Comment


      • #4
        This is actually fantastic news, I will give it a try, unfortunately I'm no even close to your knowledge, when you have a chance could you give more input on how you would accomplish it, no rush, I'm waiting for Arduino to come soon.

        Thank you,
        Aldo

        Originally posted by enigmatheatre View Post
        It is possible to do this now with the API sketch in the plugin. You would have to write some code but most of it you could copy and paste.

        Sent from my SM-G925F using Tapatalk

        Comment


        • #5
          Have you ever coded before? If you by chance have some C background, you will have no problems.

          The way I learned Arduino (I do have many years in C development at corporate level) was to get an Arduino, I chose the Uno, a breadboard, some jumpers, and a sensor kit. My kit has 36 different sensor types. Some sensor kits contain a ultrasonic sensor and/or water sensor. You need to download the Arduino IDE and try to connect a sensor to your board. Lots of examples and videos available. Just go to youtube and search for 'arduino 101' and you will get lots of getting started type videos. After you are comfortable with the Arduino, IDE, and a few sensors, then you might be ready for the plugin.

          Arduino IDE
          https://www.arduino.cc/en/Main/Software

          Starter Kit
          https://www.amazon.com/SunFounder-Pr.../dp/B00CXMMDZI

          Comment


          • #6
            I can read code but not actually write them. I got the Arduino to learn so what you gave me is a great start. Thank you all.

            Aldo

            Originally posted by logbuilder View Post
            Have you ever coded before? If you by chance have some C background, you will have no problems.

            The way I learned Arduino (I do have many years in C development at corporate level) was to get an Arduino, I chose the Uno, a breadboard, some jumpers, and a sensor kit. My kit has 36 different sensor types. Some sensor kits contain a ultrasonic sensor and/or water sensor. You need to download the Arduino IDE and try to connect a sensor to your board. Lots of examples and videos available. Just go to youtube and search for 'arduino 101' and you will get lots of getting started type videos. After you are comfortable with the Arduino, IDE, and a few sensors, then you might be ready for the plugin.

            Arduino IDE
            https://www.arduino.cc/en/Main/Software

            Starter Kit
            https://www.amazon.com/SunFounder-Pr.../dp/B00CXMMDZI

            Comment


            • #7
              Here is a link to the steps to implement an ultrasonic sensor. It covers how to wire it and the sketch (code) to interact with the sensor. These types of examples are widely available for most anything you want to do with an Arduino.

              http://www.instructables.com/id/Simp...-SR04-Example/

              Comment


              • #8
                I'm getting ahead of myself here, just thinking aloud, the project seems not to be that difficult, I'm trying to figure out how the plugin would read the values from it, like it is 42 cm from water. Thanks again for all your input.

                Originally posted by logbuilder View Post
                Here is a link to the steps to implement an ultrasonic sensor. It covers how to wire it and the sketch (code) to interact with the sensor. These types of examples are widely available for most anything you want to do with an Arduino.

                http://www.instructables.com/id/Simp...-SR04-Example/

                Comment


                • #9
                  It should be easy as you only need to remove all the serial print lines and add in a check if the value of distance has changed and if so print to Homeseer with SendToHS(1,distance);
                  Then add this to the API sketch.
                  I would send you the code but I am just on my phone so can not type it out.
                  Give me a shout if you get stuck.

                  Greig.

                  Sent from my SM-G925F using Tapatalk
                  Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                  X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                  Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                  Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                  Scripts =
                  Various

                  Comment


                  • #10
                    This is what I call a "forum" and proud of being part of it, you guys rock.
                    On a side note, it sounds corny but the best part of my day is reading posts on this board and listening to all the great people like you guys that make a difference. Looking forward to get my Arduino soon.

                    Aldo

                    Originally posted by enigmatheatre View Post
                    It should be easy as you only need to remove all the serial print lines and add in a check if the value of distance has changed and if so print to Homeseer with SendToHS(1,distance);
                    Then add this to the API sketch.
                    I would send you the code but I am just on my phone so can not type it out.
                    Give me a shout if you get stuck.

                    Greig.

                    Sent from my SM-G925F using Tapatalk

                    Comment


                    • #11
                      Again this is untested code but I think this is what you want. I have removed the LED code and the Serial print and added the command to send it to API device 1.
                      There might be timing problems but best to test it first as changing this may need more code.

                      Code:
                      #define trigPin 13
                      #define echoPin 12
                      int LastDistance = 0;
                      
                      void setup() {
                        pinMode(trigPin, OUTPUT);
                        pinMode(echoPin, INPUT);
                      }
                      
                      void loop() {
                        long duration, distance;
                        digitalWrite(trigPin, LOW);  // Added this line
                        delayMicroseconds(2); // Added this line
                        digitalWrite(trigPin, HIGH);
                        delayMicroseconds(10); // Added this line
                        digitalWrite(trigPin, LOW);
                        duration = pulseIn(echoPin, HIGH);
                        distance = (duration/2) / 29.1;
                        if (distance != LastDistance){
                        SendToHS(1,distance);
                        LastDistance = distance;
                        }
                      }
                      Greig.
                      Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                      X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                      Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                      Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                      Scripts =
                      Various

                      Comment


                      • #12
                        I wrote about my sump pump setup and using Jon00 Database Charting Utility here, see https://board.homeseer.com/showthrea...171875&page=14

                        An update of the setup...

                        I have a low place in my yard near my HVAC unit. Of course the yard is always wet near the HVAC unit, so I ran a 4 inch drain out to the street that also has some of the house downspouts on it. Unfortunately relying on gravity does not allow the water to flow fast enough during a heavy rain, so I had to come up with a plan. I took a plastic 55 gallon drum, put a trash pump in it, and buried it. Then I ran the downspouts and the line from my HVAC unit to a catch basin that leads to the 55 gallon drum. The trash pump takes the rain water and pushes it to the street. I have 4 sensors in the drum that indicate level, (1/4 full, half full, 3/4 full and full) so that I can monitor the level in the tank. Recording the readings from the sensors will allow me to chart the levels in the tank over time and see the performance of the pump. We had a very bad storm on 09-10-2016, the readings gathered from that time period, indicate that the water never made it to the half full sensor. The pump is adjusted to cut on when the tank is between 1/4 and half full. I included a few pictures of the 55 gallon drum with the extender on it as well as the finished product.

                        We have had a significant amount of rain in 2016, more than I have ever seen in White House since we moved here just over 18 years ago. During one of the recent storms we received 6 to 8 inches of rain in just 4 hours. The power did not go out so the pump did its job very well. No standing water in any of the low places. However some of our neighbors did not fare so well and received water under their house and garage. Interesting that the city of White House is higher than Nashville but when that much rain falls in a short amount of time, well it has to go somewhere. I should have mentioned that the pump is obviously reliant on electricity and during storms there is a higher possibility of a power outage. The 55 gallon drum has a 4 inch pipe that is connected at the top of the extender and runs to the street. This pipe is used as an overflow. This way if the electricity is out, the water still has a gravity fed path out to the street. The water will not get out as quick, because the fall rate is not ideal (obviously the reason for a pump), but it is better than not having any path at all.

                        This is picture of the plastic 55 gallon drum with the man hole extender on it
                        Click image for larger version

Name:	sp1.jpg
Views:	2
Size:	48.8 KB
ID:	1190760

                        The tank has 4 level sensors they monitor water level and report their status back to HomeSeer. There is also a temperature sensor that reports its value back to an Arduino that is monitored by HomeSeer.

                        The level sensors are Water Level Monitor Sensor Right Angle Float Switches ZPC1 White. The temperature sensors are Vktech 5pcs 3M Waterproof Digital Temperature Temp Sensor Probe DS18B20
                        Click image for larger version

Name:	level sensor.jpg
Views:	1
Size:	41.6 KB
ID:	1190763Click image for larger version

Name:	temp sensor.jpg
Views:	1
Size:	36.9 KB
ID:	1190764

                        Finished product, notice the grate next to the HVAC unit, the runoff goes into the grate from the concrete and the unit itself, a 4 inch pipe from the grate leads to the 55 gallon drum. There are also 4 downspouts from the house that are routed to the 55 gallon drum.
                        Click image for larger version

Name:	sp3 finished.jpg
Views:	2
Size:	157.3 KB
ID:	1190761Click image for larger version

Name:	sp4.jpg
Views:	1
Size:	163.5 KB
ID:	1190762

                        I have setup Jon00 Database Charting Utility to monitor the levels in the tank, so far the water level in the tank has not gotten above the first sensor and we have had some very heavy rains. I have setup Jon00 Database Charting Utility to monitor the levels in the tank, so far the water level in the tank has not gotten above the first sensor and we have had some very heavy rains. The graph below shows 2 hours of runtime during a storm we had on September 17, 2016.

                        Click image for larger version

Name:	graph.png
Views:	2
Size:	50.7 KB
ID:	1190765
                        Billy Draper

                        Comment


                        • #13
                          Thank you both for the code and for the write up of your configuration. I will try both ways, as of curiosity did you try using the hc_sr04 sensor instead and why did you choose the others instead? I have both set of sensors, I think the hc-sro4 are cool but not sure how effective they are compared to your sensors.

                          Sent from my SM-G935V using Tapatalk

                          Comment


                          • #14
                            You do not need the Void Setup or Void Loop as this is what the HSSteup and HSLoop are doing.

                            Try this.

                            Code:
                            /************************************************************ *
                            *Arduino to Homeseer 3 Plugin API written by Enigma Theatre.*
                            * V1.0.0.140 *
                            * *
                            ************************************************************ */
                            int FromHS[50]; 
                            boolean IsConnected = false; 
                            //************************************************************
                            //**************Declare your variables here******************* 
                            
                            #define trigPin 13
                            #define echoPin 12
                            int LastDistance = 0;
                            
                            //************************************************************ ****
                            void HSSetup() {
                            
                            //************************
                            //Add YOUR SETUP HERE;
                            //************************
                            pinMode(trigPin, OUTPUT);
                            pinMode(echoPin, INPUT);
                            }
                            
                            void HSloop() {
                            if (IsConnected == true) {
                            /*Execute ONLY when HomeSeer is connected*/
                            
                            long duration, distance;
                            digitalWrite(trigPin, LOW); // Added this line
                            delayMicroseconds(2); // Added this line
                            digitalWrite(trigPin, HIGH);
                            delayMicroseconds(10); // Added this line
                            digitalWrite(trigPin, LOW);
                            duration = pulseIn(echoPin, HIGH);
                            distance = (duration/2) / 29.1;
                            if (distance != LastDistance){
                            SendToHS(1,distance);
                            LastDistance = distance;
                            }
                            }
                            }
                            Greig.
                            Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                            X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                            Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                            Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                            Scripts =
                            Various

                            Comment


                            • #15
                              Quick question:
                              I have attached the picture, what the input and output should be set at?

                              After making changes or adding pins, do I need to download the sketch and make your changes into the new uploaded sketch?

                              Than ks, Aldo

                              Originally posted by enigmatheatre View Post
                              Again this is untested code but I think this is what you want. I have removed the LED code and the Serial print and added the command to send it to API device 1.
                              There might be timing problems but best to test it first as changing this may need more code.

                              Code:
                              #define trigPin 13
                              #define echoPin 12
                              int LastDistance = 0;
                              
                              void setup() {
                                pinMode(trigPin, OUTPUT);
                                pinMode(echoPin, INPUT);
                              }
                              
                              void loop() {
                                long duration, distance;
                                digitalWrite(trigPin, LOW);  // Added this line
                                delayMicroseconds(2); // Added this line
                                digitalWrite(trigPin, HIGH);
                                delayMicroseconds(10); // Added this line
                                digitalWrite(trigPin, LOW);
                                duration = pulseIn(echoPin, HIGH);
                                distance = (duration/2) / 29.1;
                                if (distance != LastDistance){
                                SendToHS(1,distance);
                                LastDistance = distance;
                                }
                              }
                              Greig.
                              Attached Files

                              Comment

                              Working...
                              X