Sump Pump Water Level: the Software





Introduction: Sump Pump Water Level: the Software

This is the second part of my sumppump water level sensor.  

You can find the first part on how to built a water level sensor, here:


-Raspberry Pi with
        Sendmail or postfix if you want a email warning.

What the software will do:

The command part
This part is invisible to the user and is (and should be ) independent of the webpage.
Using cron, it will read the water level every minute and save the information to a file. If the water level reaches a certain level, an email will be sent. This is the most important part.

The Web page
In this part, the web page reads the information from the file written by the cron job and displays an image of your pit.

Step 1: Download and Copy the Software

Download the zip file and uncompress it to the webfolder of your Raspberry. I recommend creating a subfolder at the root of your www folder. Typically, the folder path is /var/www/sumppump.

Step 2: Ajust the Preferences

Open the file "chklevel.php" with a text editor and change the line 3 to reflect the path to the folder where you copy all the files.


Save and close the file.


Open the file "preference.php". All the preferences are explained in the comments.

The $levelamber and $levelred variables change the color of the led on the webpage and sends an email to the $to variable.

Be careful: If you set the $preferunit to cm, be sure to set all other measements to cm. The same thing applies in reverse cms to inches."

Refer to this images for the definition of some variables

Step 3: Schedule the Cron Task

Connect to your Raspberry as root and type this command to edit the scheduled task

crontab -e

Add this line to your crontab file:

* * * * * php /var/www/sumppump/chklevel.php

This will instruct to run the php script at every minutes of every hour of every...

Save the file with ctrl-o and ctrl-x to close the file.

Step 4:

Voila. If you type in http://myserver/sumppump in your browser , you should be able to see your sumppump.

Note that it's not really a dynamic image of your pit. In fact, what compose the image is a table of three row containing a top image with the sensor, a middle one with the grey background, and a third one with the blue background. The height of the row is determine by the level of water.

*** This code was test in my system only. If you encounter any bug, please write a comment at the bootom of the page.



    • Epilog Challenge 9

      Epilog Challenge 9
    • Paper Contest 2018

      Paper Contest 2018
    • Science of Cooking

      Science of Cooking

    We have a be nice policy.
    Please be positive and constructive.




    Amendments to post: Sorry id errors

    made a different setup connected to a 12v battery.

    The setup is on all
    the time and the battery is charged by a solar panel. There is a vertical float switch down the pipe which initiates a relay
    to switch on a 12v diesel pump to extract the water. The water trickles into the sump which makes the pump jump in and out
    about every 2/3 seconds. Can I include your sensor to monitor the water levels
    and control the pump using a 12v battery?

    Hi There

    is this post still monitored? Just found it.

    I Like this little project. I want to take it further by connecting an extraction pump by switching on a 12v fish tank or diesel pump to start pumping out the water (a) when it gets to a high level and (b) switch off the pump when the water level reduces back to the low level.

    I made a different setup connected to a 12v battery. The setup on all the time. There is a horizontal float switch which initiates a relay to switch on the pump to extract the water but it jumps in and out every 2/3 seconds. Can I include your sensor to monitor the water levels and control the pump using a 12v battery?

    Hi Luc,

    Thanks for posting this guide! I'm having trouble with the code. Could you help me? I'm having many issues, but I'm currently troubleshooting. When I try to run chklevel.php directly I get the following message

    pi@raspberrypi /var/www/sumppump $ sudo php chklevel.php
    sh: 1: /var/www/sumppump/ Permission denied
    PHP Notice: Undefined offset: 0 in /var/www/sumppump/chklevel.php on line 13

    Mesure final -11cm

    Mesure final -4.3pouce
    0 have been send sh: 1: /usr/sbin/sendmail: not found
    Message cannot be send

    Change permission of to 777 or 755. All other error are because cannot execute.

    And make sure you can write to result.php

    Now that I have been able to measure, I don't think it's measuring correctly. I measured about 7 inches of water, but it displays 11.4 inches.

    Substract 4,4 from $compensation

    Line now reads: $compensation=-4.4;

    But it is still about 4-5inches too high.

    Thanks, that clears some stuff up. For my cron I would run:

    3 * * * * /path/to/php /var/www/html/chklevel.php

    I tried running the script manually, and it puked out some errors:

    pi@pi /var/www/html $ ./chklevel.php

    ./chklevel.php: line 1: ?php: No such file or directory

    ./chklevel.php: line 2: //: Is a directory

    ./chklevel.php: line 3: syntax error near unexpected token `'/var/www/html/''

    ./chklevel.php: line 3: `chdir('/var/www/html/');'

    is the $deep in cm? Is that from sensor to bottom of pit? Also, what does compensation equate to? Should that be preset as well from 11? Is that in cm or inches?

    Hi Anthony,

    chklevel.php is a php file, not a bash. If you want to run it manually, do:

    php chklevel.php

    I assume you have apache and php install on your rasp.