How to build a Water Alarm

POV: Normal alarms don't work for you

·

4 min read

Introduction

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 watched Mr Bean's funny videos as a kid and recently wanted to build a similar water alarm from one of his shows. And build I did.

Requirements

Steps

First, we will do the wiring, then set up the pi, program it and finally schedule a task that runs the program every day 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 https://pinout.xyz 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 of 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 to L293D PIN 3 and the negative end to L293D PIN 6.
  • Connect the Power Supply

    1. Connect the positive terminal of the power supply to the positive side of the breadboard.

    2. Connect the negative terminal of the 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 the 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 the Pi to power.

  11. Get the IP address from your router and ssh into your pi. For me,

# Default password - raspberry
ssh pi@192.168.0.110
  1. Install python3 on your pi
sudo apt-get install python3

3. Program the Pi

  1. Create a new file alarm.py:
nano alarm.py
  1. Paste this code: %[gist.github.com/yaamas/1675e05a555568b496a2..

  2. Make your program executable:

chmod u+x alarm.py
  1. Run it once to see if everything is working properly
python3 alarm.py

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 every day. To edit your crontab file, type:
crontab -e
  1. Read the comments inside the crontab file to understand how it works. You can also use the website https://crontab.guru/ to understand easily. Paste this line after the comments: %[gist.github.com/yaamas/1bcc53ed064fd19c71ca..

  2. 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 your logs:

grep -ia cron /var/log/syslog

Closing

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.