Facebook Twitter Instagram Pinterest YouTube
    Trending
    • Add Kodi to RetroPie Menu
    • Disable Auto-login in Raspberry Pi OS
    • Raspberry Pi Cloud Storage with MEGA
    • RetroPie Temperature Monitor from Menu
    • Pi Pico Pinout and Power Pins
    • Install Arduino IDE on Raspberry Pi
    • Raspberry Pi 400 SSD Upgrade
    • Raspberry Pi Temperature Monitoring
    Facebook Twitter Instagram Pinterest YouTube RSS
    Raspberry Pi SpyRaspberry Pi Spy
    • Home
    • Categories
      • General
      • Hardware
      • Programming
      • Python
      • Software
      • Tutorials & Help
    • BerryClip
      • BerryClip Instructions
      • BerryClip Plus Instructions
      • Videos & Reviews
    • Buy
      • Buy Pi
      • Buy Pi Accessories
      • Buy Books
    • Tools
      • Ultimate Raspberry Pi Alexa Skill
      • Pi Power Estimator App
      • Pi-Lite 14×9 LED Matrix Sprite Editor
      • RPiREF Pin-out Reference App
      • Simple Ohm’s Law Calculator
      • Web Sites & Links
    • Tutorials & Help
        Featured
        November 9, 20200

        Raspberry Pi Temperature Monitoring

        Recent
        May 6, 2022

        Add Kodi to RetroPie Menu

        February 26, 2022

        Disable Auto-login in Raspberry Pi OS

        February 2, 2022

        Raspberry Pi Cloud Storage with MEGA

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Hardware»Sensors»Waterproof Ultrasonic Distance Measuring Module
      Waterproof Ultrasonic Sensor

      Waterproof Ultrasonic Distance Measuring Module

      9
      By Matt on October 23, 2016 Sensors, Tutorials & Help

      In order to measure the water level in my water butt I decided to try a waterproof ultrasonic distance measuring module. This operates in the same way as the standard ultrasonic modules I used in my previous Ultrasonic Distance Measurement Using Python tutorial.

      The waterproof ultrasonic sensor I ordered looks like this :

      Waterproof Ultrasonic Sensor

      It consists of :

      • Waterproof transducer
      • Cable
      • Control board
      Waterproof Ultrasonic Sensor
      Waterproof Ultrasonic Sensor

      The control board has the same four connections as the HR-SR04 modules :

      • Trigger
      • Echo
      • 5V
      • Ground

      The module provides measurements within a range of 25cm – 450cm. The transducer itself looks like the device you would find in a car reversing sensor system rather than the twin-transducer arrangement of the classic HR-SR04 module.

      Connecting To The Pi

      The module can be powered from the Pi’s 5V and Ground pins. I used Pin 2 and Pin 6 on the Pi’s GPIO header.

      The input pin on the module is called the “trigger” as it is used to trigger the sending of the ultrasonic pulse. It works just fine with a 3.3V signal from the GPIO so I connected the trigger directly to Pin 16 (GPIO23).

      Voltage DividerThe module’s output is called the “echo” and needs a bit more thought. The output pin is low (0V) until the module has taken its distance measurement. It then sets this pin high (+5V) for the same amount of time that it took the pulse to return. So our script needs to measure the time this pin stays high. The module uses a +5V level for a “high” but this is too high for the inputs on the Pi which only like 3.3V. In order to ensure the Pi only gets hit with 3.3V we can use a basic voltage divider. This is formed with two resistors.

      If R1 and R2 are the same then the voltage is split in half. This would give us 2.5V. If R2 is twice the value of R1 then we get 3.33V which is fine. So ideally you want R2 to be between R1 and R1 x 2. In my example circuit I used 330 and 470 ohm resistors. An alternative would be to use 1K and 1K5 values.

      Here is a diagram of my final circuit. I chose GPIO23 and GPIO24 but you can use any of the 17 available GPIO pins on the GPIO header. Just remember to update the Python script accordingly.

      Ultrasonic Module Circuit
      Ultrasonic Module Circuit

      I used a small piece of breadboard to create the voltage divider :

      Waterproof Ultrasonic Sensor

      The White wire is connected to the Echo pin, the Purple wire to GPIO24 and the Blue/Black wires to Ground. Ignore the blue resistors as they are not used in this case.

      Python Scripts

      To test my module I used the same script as I used in my previous Ultrasonic sensor articles. Although this time I made some improvements.

      There are two example Python scripts which you can download and try.

      ultrasonic_1.py
      A script to take a single reading and display the result in centimetres.

      ultrasonic_2.py
      A script to take continuous readings and display the result in centimetres.

      You can download them directly to your Pi using :

      wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/ultrasonic_1.py

      and :

      wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/ultrasonic_2.py

      Once downloaded they can be run using :

      python ultrasonic_1.py

      and :

      python ultrasonic_2.py

      If you have it installed the scripts should also work under Python 3 :

      python3 ultrasonic_1.py

      You can use any GPIO pins you like amend your Python script accordingly.

      Speed of Sound

      The calculation that is used to find the distance relies on the speed of sound. This varies with temperature so I updated these scripts to calculate the correct value to use based on a defined temperature. You can change this value if required or perhaps measure it dynamically using a temperature sensor.

      Water Butts

      I like big water butts and I can not lie. I’m in the process of laying down some concrete to form a more suitable base for my water butts but once they are setup I will be fixing this sensor into the lid of one of them. I’ll write a new post detailing that but it is most likely to be a spring project next year.

      Accuracy

      Here are some points about accuracy :

      • You get better readings from a solid flat surface with no other nearby objects. The sensor sends out pulses that form a “cone” so anything that gets in the way will affect the results.
      • The accuracy of the distance measurement is dependent on timing. Python under Linux is not ideal for precise timing but for general messing about it will work OK. To improve accuracy you would need to start looking at using C instead.
      • When the GPIOs are configured the module needs some time before it is ready to take its first reading so I added a 0.5 second delay to the start of the script.

      Buying This Waterproof Ultrasonic Sensor

      Here is a link to the Waterproof Ultrasonic Module Distance Measuring Transducer Sensor I ordered from eBay. These devices are available from other sellers and you can view the selection by searching eBay for “Waterproof ultrasonic module sensor”.

      Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticleModMyPi PiOT Relay Board for Raspberry Pi
      Next Article RGB LED Christmas Tree by PocketMoneyTronics

      Related Posts

      Add Kodi to RetroPie Menu

      Disable Auto-login in Raspberry Pi OS

      Raspberry Pi Cloud Storage with MEGA

      9 Comments

      1. pd on October 27, 2016 2:52 pm

        Why not link to where you ordered the sensor?

        What is the sensor’s reasonable effecive distance range?

        Reply
        • Matt on October 27, 2016 6:46 pm

          I’ve updated the post to include a link to the sensor I ordered from eBay. The range of the device is 4.5m but that assumes there isn’t any clutter in the surrounding area that will create sound wave reflections. I tested it up to around 2m.

          Reply
      2. Aravind on September 15, 2017 7:28 am

        Does this system work if submerged (obly the sensor)for more than half an hour underwater?(for navigation of an AUV)

        Reply
        • Matt on September 21, 2017 10:11 pm

          I’m not sure but I don’t think this sort of sensor is designed to be used underwater.

          Reply
      3. JP on March 3, 2019 1:44 am

        Matt, I am not an electrical engineer, but I love to create new things. I was wondering if such a transducer can be used with the PI on my boat to identify objects at night time. For example getting closer and closer to the dock or another boat.

        Reply
        • Matt on March 5, 2019 10:29 pm

          Over a limited range it would probably work. The only way to be sure is to test it. It would not be too similar from car parking sensors.

          Reply
      4. Mike on February 18, 2020 1:41 am

        This is great – do you think it would work if housed in a cap of a PVC pipe? Shooting downward to water as it rises / lowers in the pipe? Or do you think there would be interference from the sides of the PVC? I’m thinking 4″ dia max pipe – ~5′ in length.

        So it sounds too that the sound will echo off water? Or would I need a float to provide a hard surface to echo?

        I’m completely new to any of this Raspberry stuff, but I really need a come up with a more affordable sensor to monitor stream levels. Thinking I’d ziptie a pvc pipe to a T-post driven into the streambed. Add a cap containing the sensor components (sealed in some way). Problem is, I’d need to have this run during the winter months (cold, wet environment). Battery powered… hrmm Think that’s even possible? I’d love to give it a try.

        Thanks for your site!

        Reply
        • Matt on February 20, 2020 9:13 am

          The sides of pipe could cause reflections. However they would be fairly consistent. The distance measurement would be incorrect but that doesn’t matter as long as it gave you predictable results for a set water level. The only way to be sure is to try it!

          Reply
      5. Sam on October 10, 2021 3:15 pm

        Hy Matt
        Many thanks for the good tutorial
        I’ve found a little mistake in the code (both ultrasonic_1.py and ultrasonic_2.py)
        The speed of sound is in cm/s so the multiplier for temperature difference has to be multiplied itself by 100. Because the temperature offset multiplied by 0.6 gives you the offset in meters.

        speedSound = 33150 + (0.6*temperature*100)

        Best regards Sam

        Reply

      Leave A Reply Cancel Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      January 7, 2022

      RetroPie Temperature Monitor from Menu

      January 24, 2021

      Pi Pico Pinout and Power Pins

      Categories
      • 1-wire
      • 3D Printing
      • Add-ons
      • BBC Micro:bit
      • BerryClip
      • Books
      • Camera Module
      • Cases
      • Events
      • General
      • Hardware
      • I2C
      • Infographics
      • Interfaces
      • Minecraft
      • Model A+
      • Model B+
      • News
      • Pi Models
      • Pi Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      3D Printing Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter LCD LED Linux media Minecraft Model A Model B motionEyeOS PCB photography photos Pi-Lite portable power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI temperature ultrasonic video
      Raspberry PI Related
      • Adafruit Blog
      • Average Maker
      • Official RaspBerry Pi Site
      • Raspberry Pi Pod
      • RasPi.tv
      • RaspTut
      • Stuff About Code
      Tech Resources
      • MattsBits – Pi Resources
      • Microbit Spy
      • Technology Spy
      Archives
      About

      Unofficial site devoted to the Raspberry Pi credit card sized computer offering tutorials, guides, resources,scripts and downloads. We hope to help everyone get the most out of their Pi by providing clear, simple articles on configuring, programming and operating it.

      Popular Posts
      September 19, 2014

      Top 5 Reasons The Raspberry Pi Sucks

      July 27, 2012

      16×2 LCD Module Control Using Python

      October 20, 2013

      Analogue Sensors On The Raspberry Pi Using An MCP3008

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      Facebook Twitter Instagram Pinterest YouTube RSS

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2022 - All Rights Reserved - Matt Hawkins

      Type above and press Enter to search. Press Esc to cancel.