How to build a Water Alarm

Photo by Gavin Allanwood on Unsplash

How to build a Water Alarm

POV: Normal alarms don't work for you

Yahyaa's photo
·Feb 11, 2022·

4 min read

Table of contents

  • Introduction
  • Requirements
  • Steps
  • Closing


I am a deep sleeper. I am sure a couple of people out there are the same. Normal alarms don't wake me. It's always another person or me waking up to my body clock. I had watched Mr Bean's funny videos as a kid and was recently wanting to build a similar water alarm from one of his shows. And build I did.



First, we will do the wiring, then setup up the pi, program it and finally schedule a task that runs the the program everyday at a fixed time.

1. Wiring

Here is the circuit diagram: Circuit Diagram

  • Use the jumper wires to connect the pi to the breadboard
    1. Use the to understand the GPIO Layout.
    2. Connect the PIN 2 (5v) to the positive side on the breadboard.
    3. Connect PIN 14 (Ground) to the negative side on the breadboard.
    4. Connect PIN 16 (GPIO 23) and PIN 18 (GPIO 24) from the Pi to L293D pins PIN 7 and PIN 2 respectively.
  • Connect the pump to the breadboard
    1. Connect the pump's positive end into L293D PIN 3 and negative end L293D PIN 6.
  • Connect the Power Supply
    1. Connect positive terminal of power supply to the positive side of the breadboard.
    2. Connect negative terminal of power supply to the negative side of the breadboard.
  • L293D wiring
    1. Connect PIN 4 to PIN 5 and connect either to the negative side of the breadboard.
    2. Connect PIN 12 to PIN 13 and connect either to the negative side of the breadboard.
  • Breadboard wiring
    1. Connect two positive sides on the breadboard
    2. Connect two negative sides on the breadboard

Now we are done with the wiring. You can refer to the TI Data Sheet for L293D if you want to learn more about it.

2. Setup the Pi

  1. Download the Raspberry Pi Imager tool on your computer.
  2. Press Ctrl/CMD + Shift + X to open the advanced menu.
  3. Check the Enable SSH box.
  4. Scroll down to Configure Wifi and check it.
  5. Enter your WiFi SSID and password and select your country from the drop menu.
  6. Scroll down, check Set Locale Settings and select your timezone and keyboard layout.
  7. Click Save button.
  8. For OS, I selected Raspberry Pi OS Lite 32bit.
  9. Choose your storage and press write.
  10. After it's done, put the SD Card into your Pi and connect pi to power.
  11. Get the IP address from your router and ssh into your pi. For me,
    # Default password - raspberry
    ssh pi@
  12. Install python3 on your pi
    sudo apt-get install python3

3. Program the Pi

  1. Create a new file
  2. Paste this code:
  3. Make your program executable:
    chmod u+x
  4. Run it once to see if everything is working properly

4. Schedule the job

  1. To schedule a task that runs at set intervals, we use crontab. We will schedule a job that runs the alarm script at 6 AM everyday. To edit your crontab file, type:
    crontab -e
  2. Read the comments inside the crontab file to understand how it works. You can also use the website to understand easily. Paste this line after the comments:
  3. Just to test, set the job to run a few minutes from now. If the pump doesn't turn on, you might have missed something. Check to your logs:
    grep -ia cron /var/log/syslog


You might want to grab some tape to tidy up your electronics. Also, I don't have a mechanism to stop the pump, so as I wake up I unplug the pi power supply. I might write a flask app with just a stop button or simply put a physical button, if necessary.

Now you should be able to wake up early in the mornings like the others. Enjoy your early start.

Share this