Introduction: Sump Pump Water Level: the Hardware

The second part of this tutorial about the software can be found here:

https://www.instructables.com/id/Sump-pump-water-level-The-software/

What you need:


* 2  X pieces of wood 4X6. 1/4'' and the other 1/2'' thick 
* 1 X 3 inches pipe. length varies depending of the deep of your pit.
* A couple of screw
* 1 X 1k resistor
* 1  X Raspberry pi
* 1X HC-SR04 ultrasonic sensor
* Wire





Step 1: The Sensor

The sensor mesure the time it took to an ultrasound to get back to it.

Step 2: Create the Base

First, cut a 3 inches hole in the thicker 4''X6'' piece of wood. Stick the pieces of wood together.

Step 3: Prepare the Base for the Sensor.

Drill two 3/4'' hole in the center of the 3'' hole. The distance between them is 1''. Add 3 screw to hold the pipe.

Step 4: Add the Sensor

Mount the sensor on 2 spacer to keep the sensor level. Stick the sensor to the spacer with hot glue.

Step 5:

Add 8 screw to hold the wired. Optional: add a plexyglass cover to protect your masterpiece.

Step 6: Connection

How to connect to the raspberry:

Pin 1 GND: connect to the ground of the rasp.
Pin 2 Echo to gpio 9
Pin 3 Trig to gpio 11. Add a 1k resistor
Pin 4 VCC to the 3.3V 

Note 1: According to the manual, the sensor used 5v. But it work perfectly at 3.3v.

Note 2: Beware, we see the back of the sensor in this pic, so the order of the pin are reverse.

 


Step 7: Add the Pipe

Add the pipe to the controller and thighten the 3 screw.

Step 8: The Code

First, you need to save the code on the rasp with the extension *.py. Then run the command python myfile.py


Code:


#!/usr/bin/python
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# ultrasonic_1.py
# Measure distance using an ultrasonic module
#
# Author : Matt Hawkins
# Date   : 09/01/2013

# Import required Python libraries
import time
import RPi.GPIO as GPIO

# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# Define GPIO to use on Pi
GPIO_TRIGGER = 11
GPIO_ECHO = 9

# You need to change the variable "compensation" according to the distance from the edge of the pit to the sensor
compensation = -11

print "Ultrasonic Measurement"

# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT)  # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN)      # Echo

# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)

# Allow module to settle
time.sleep(0.5)

# Send 10us pulse to trigger
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
start = time.time()
while GPIO.input(GPIO_ECHO)==0:
  start = time.time()

while GPIO.input(GPIO_ECHO)==1:
  stop = time.time()

# Calculate pulse length
elapsed = stop-start

# Distance pulse travelled in that time is time
# multiplied by the speed of sound (cm/s)
distance = elapsed * 34000

# That was the distance there and back so halve the value
distance = distance / 2
distance = distance + compensation

print "Distance : %.1f" % distance

# Reset GPIO settings
GPIO.cleanup()



Note: You need to change the variable "compensation" according to the distance from the edge of the pit to the sensor

Note 2: The distance are in cm.

Thank to Matt Hawkins for this code

Step 9: Final Result

Voila! All you have to do now is to fixed the sensor in your pit.

Step 10: Next Tutorial

In the next week, I will show you how to present the result of the sensor on a web page.

I'm not as good as I want to in english, so feel free to send me any correction in my text. 

Comments

author
amherstuk made it! (author)2015-07-23

Genuis project. Thank you sooooo much. I had a look around and managed to find a few alternative parts to put a twist on a superb project.

a) I managed to get a waterproof sensor - with same pin outs as the SR04 (apart from it being 5v!). I got off ebay from here: http://www.ebay.co.uk/itm/1pc-Arduino-Ultrasonic-M...

b) Being in the UK - we have a great DIY store called "Screwfix". Found 3 inch gutter pipe, and a handy "box pipe converter" - which I fixed to the end using plastic cement and it acts as a nice enclosure for the small sensor board.

http://www.screwfix.com/p/square-line-black-draina...

http://www.screwfix.com/p/black-downpipe-2-5m/2525...

http://www.screwfix.com/p/floplast-sc250-solvent-c...

c) cut a small square of acrylic, cut hole in middle, threaded and dangled the sensor through - weirdly it gave weird readings if I tried to "mount" it on the plate.

d) used a 10m piece of cat5e (stranded patch cable) and soldered on the connectors on each end.

e) used potting compound to fill the top and encapulate the sensor board and spare cable.....50cm piece of chain to hang in our tank! Make sure you ensure all of the holes are sealed before pouring the potting compound....I had a bit of a leak - yuk!

I've taken the output from the python script - had a simple cronned script written so that it will SMS us when the tank gets too full.....using this project and Huewei adaptor.

http://www.mattiasnorell.com/send-sms-from-a-raspb...

Thanks again Luc - amazing inspiration - scripts worked a treat!

Triston.

IMG_20150702_173420.jpg2015-07-19 17.24.44 (Medium).jpg2015-07-18 16.00.43 (Medium).jpg2015-07-19 02.31.40 (Medium).jpg2015-07-19 02.32.01 (Medium).jpg2015-07-18 16.00.35 (Medium).jpg2015-07-18 17.05.49 (Medium).jpg2015-07-19 17.24.54 (Medium).jpg2015-07-18 17.06.00 (Medium).jpg2015-07-18 16.00.21 (Medium).jpg2015-07-18 16.00.45 (Medium).jpg2015-07-18 16.00.31 (Medium).jpg2015-07-18 17.11.52 (Medium).jpg2015-07-19 17.24.56 (Medium).jpg2015-07-23 15.44.28 (Medium).jpg2015-07-18 16.00.26 (Medium).jpg2015-07-23 15.44.29 (Medium).jpg2015-07-23 15.44.31 (Medium).jpg2015-07-18 15.59.40 (Medium).jpg2015-07-18 17.05.42 (Medium).jpg2015-07-18 16.00.10 (Medium).jpg2015-07-23 13.57.53 (Medium).jpg
author
HelderR4 (author)amherstuk2016-04-19

@amherstuk im trying to use the same sensor as you, the JSN - SR04 but i cant make it to work. Have you used a special code (python)? is it working ok after all these time?

By the way, love the main project idea and yours too.

Regards

author
Luc Moreau (author)HelderR42016-04-19

Hi,

The com between the raspberry and the sensor is done with the file sensor.py
If you open the file, you'll see the code required 2 library: import time and import RPi.GPIO as GPIO. if you can run the python file manually, the problem is probably permission. You'll find the answer in the comment section of the software part.

My system is not running anymore . I use my blackberry for another task (kodi). Maybe later, I will do a arduino version of it. My goal is to build a lot of these sensor and send all the info to a central web server.

author
HelderR4 (author)Luc Moreau2016-04-26

Thanks for the help.. But i think my problem is with the sensor.. Im waiting for a hc-sr04 to confirm. Anyone with this sensor JSN-SR04 that can help me??

author
LarryE1 (author)2015-05-29

This has been intriguing project. I was able to use your idea in setting up my raspberry pi to track the water usage for my power garden. I have set up a WordPress page with MySQL on the RP to track the the current water level. The project page is at: smarttowergarden.com. I have set up a blog with hurdles that I had to overcome in order to make it work.

author
Luc Moreau (author)LarryE12015-05-31

glad you like my project. I read on your blog that the level is not acurate when temperture is too high? Why not use an usb temperture to modify the result? I use this temperatur sensor to monitor the temperatur of my server room an send an email if temp is high.

http://www.cafr.ebay.ca/itm/USB-Temperature-Sensor...

author
LarryE1 (author)Luc Moreau2015-05-31

Thank you for your comment. I'm currently getting the temperature from Gateway Airport. It's about 25 miles away from my home. I do have the temperature module but I have not installed it yet. Again thank you for your sump pump project. I need to look into the USB temperature sensor. I didn't know one existed. That would even work better.

thanks agin.

Larry E

author
narinder2015 (author)2015-01-14

you are great. I was Looking something similar. I will contact you for more aggressive version of this project. I will also pay you if we came to some solution of my problem.

author
SirAremssy (author)2014-12-29

I dnt know if you have a better way of doing it.
All I want to do is to monitor the level of the underground tank
And show the readings on my laptop.
Even if it's gonna be ordinary digital underground measuring
Tape. Am counting on you bro. I will be waiting for you reply.

author
SirAremssy (author)2014-12-29

I dnt know if you have a better way of doing it.
All I want to do is to monitor the level of the underground tank
And show the readings on my laptop.
Even if it's gonna be ordinary digital underground measuring
Tape. Am counting on you bro. I will be waiting for you reply.

author
SirAremssy (author)2014-12-29

Hello, nice work. I want to do a project that will measure an underground petrol tank and give me the readings on my laptop. Pls be my tutor for the project.. Aremsajos83@gmail.com. Thanks

author
Luc Moreau (author)SirAremssy2014-12-29

Do you have a specific question?

Rasp Pi connect to the sensor with 5 volt. Beware of the risk of spark.

author
SirAremssy (author)Luc Moreau2014-12-29

I don't know if you have a better way if doing that.
All I want is to monitor the level of the underground tank
And show the readings on my system. It's gonna be a very profitable project if I can make it Done without any risk.

author
SirAremssy (author)2014-12-29

Hello, nice work. I want to do a project that will measure an underground petrol tank and give me the readings on my laptop. Pls be my tutor for the project.. Aremsajos83@gmail.com. Thanks

author
stefano_62 (author)2014-04-04

Hi, it is possible to make many sequential (4) measure and calculate the average to a better measurement?

author
Luc Moreau (author)stefano_622014-04-04

Hi Stephano,


Seem my first reply never appears. So it is:

What I do is the median instead of average. With average, if one data is really out of range, it will affect the average value. With the median, I'll take the middle value and if, for any reason, one the value is really out of range, it doesn't matter.

In the file sensor.py, at line 18, the loop read the distance 5 times, then sort the result and take the third value. I think more accurate this way.

for x in range(0, 5):

..

..

listvalue.append(mesurement)

listvalue.sort()

print listvalue[2]

The value[2] is the third value

author
foster24 (author)2014-02-21

How long can be cable between raspberry and ultrasonic sensor? Because for me would be best option to have only sensor in well and RPi in separate dry place. Thx.

author
Luc Moreau (author)foster242014-02-22

I use a 25 feet cable. For some reason, I have to power the sensor with the 5v pin. I guess it's because of the distance of the câble. It's running at home for a month now, scanning at every minute. I also add a line to the web page for auto refresh of the page at every minutes. I also add a led on the yellow and green wire. It blink when the sensor is running.

About This Instructable

28,707views

42favorites

License:

More by Luc Moreau:Precise glass bottle cutting jigSump pump water level: The softwareSump pump water level: The hardware
Add instructable to: