DEV Community

manp242
manp242

Posted on

Alarm clock which splashes water on your face

This was my first ever project with a Raspberry Pi. This isn't a complicated project, and anyone with a little bit of coding knowledge can achieve it. I am just messing with random tools to make a cool little project. Here are all the components I used in this project:

IMPORTANT

Before we get started, I want to explain how each component will work with each other.

RPI (Raspberry Pi) is used to power the relay switch and to tell the relay switch when to turn on and off. The relay switch will be in the middle of the connection between the motor and the battery and turn on at a specific time, which will be provided by our code in RPI.

LET's GET STARTED:

PART A: Connecting the RPI to the relay switch
Firstly, I attached the ground wire from the RPI (GPIO Pin 6) to the GND of the relay. Then I connected the 5V wire (GPIO pin 2) to the VCC pin of the relay. Finally, I connected the GPIO pin 40 to the SIGNAl on the relay.

  • GND is used to complete the circuit. ( IF YOU DON'T UNDERSTAND THIS YOU MIGHT WANT TO DO SOME RESEARCH: How to use a relay )
  • VCC is used to power the relay switch
  • SIGNAL is used to pass our code

idk

PART B: Understanding the motor and battery connection

In the image below you can see that the black wires from both the motor and battery are connected, completing the circuit’s ground connection. Connecting the red wires provides power to operate the motor.

idk

PART C: Adding relay switch between the battery and motor connection

Now think of a relay switch as just a switch between the 2 red wires connecting the battery and the motor. I want the wires to only connect at a specific time and for a certain amount of time; that's why I use the relay switch. The relay switch has three output holes: common, normally open, and normally closed. Normally closed means that the circuit is normally complete. Normally open means that it's normally NOT closed. Common is just used to complete the circuit. I have connected our battery's red wire (power wire) to the open port because I want to control when the circuit is closed, and I have connected the red wire from the motor to the common port. I used electric tape to tape the two black wires. Now every time I turn on the relay switch, the two red wires connect, completing the circuit and turning the motor on.

COMPLETELY OPTIONAL: In this picture, I used a male-to-female Dupont wire just because my wire for the motor was not long.

idk

PART D: Connecting everything

Now you hopefully understand the whole circuit:

  • The RPI powers the relay switch and gives it the signal on when to turn on and off.
  • When the relay switch turns on, it'll finish the circuit between the motor and the battery, activating the motor.
  • The motor will be inside a cup of water, which will then take the water from that and output it through a hole on the top, where I connected a silicon pipe.

_ I attached an empty mechanical pencil at the point of output so the water would shoot out faster._

idk

idk

Part E: Coding!!!

Tbh, I am not the best at coding, but for this project, I invested a good amount of time coding and trying different things. First, I tried to just launch water on my face but realized that it wasn't the best because all the water would hit exactly one spot. But here's the code for that if you want to experiment with it. You will want to edit the time you want to wake up

import RPi.GPIO as GPIO
import time
import datetime
GPIO.setmode(GPIO.BCM)

relay_pin = 21

# Set the pin as output
GPIO.setup(relay_pin, GPIO.OUT)

def activate_relay():
    print("Activating relay switch...")
    GPIO.output(relay_pin, GPIO.HIGH)  # Turn on the relay
    time.sleep(10)  # Keep the relay on for 10 seconds
    GPIO.output(relay_pin, GPIO.LOW)  # Turn off the relay
    print("Relay switch deactivated.")

try:
    while True:
        now = datetime.datetime.now().time()
        print("Current Time:", now)  # Print the current time
        # CHANGE THE TIME ACCORDING TO YOUR PREFRENCE, THE CODE USES MILITARY TIME
        if now.hour == 23 and now.minute == 30:
            activate_relay()
            break  
        time.sleep(5)  

except KeyboardInterrupt:
    pass

finally:
    GPIO.cleanup()
Enter fullscreen mode Exit fullscreen mode

I didn't like how the code above worked, so I changed it so it would burst the water out in pulses instead of a steady stream. I also made the code so that the pulse would differ every time. You will want to edit the time you want to wake up

import RPi.GPIO as GPIO
import time
import datetime
import random

GPIO.setmode(GPIO.BCM)
relay_pin = 21
GPIO.setup(relay_pin, GPIO.OUT)

def spray_water():
    for _ in range(30): # CHANGE ACCORDING TO YOUR PREFERENCE
        on_duration = random.uniform(0.2, 0.9)# CHANGE ACCORDING TO YOUR PREFERENCE
        off_duration = 0.3 # CHANGE ACCORDING TO YOUR PREFERENCE

        GPIO.output(relay_pin, GPIO.HIGH)
        time.sleep(on_duration)
        GPIO.output(relay_pin, GPIO.LOW)
        time.sleep(off_duration)
    print("Water spraying completed.")

try:
    # AGAIN, CHANGE THE TIME ACCORDING TO YOUR PREFRENCE, THE CODE USES MILITARY TIME
    target_time = datetime.time(20, 2)

    while True:
        now = datetime.datetime.now().time()
        print("Current Time:", now)

        if now.hour == target_time.hour and now.minute == target_time.minute:
            spray_water()
            break

        time.sleep(5)  # CHANGE ACCORDING TO YOUR PREFERENCE

except KeyboardInterrupt:
    pass

finally:
    GPIO.cleanup()
Enter fullscreen mode Exit fullscreen mode

I connected to my RPI using the VNC viewer and ran the code in Thonny.

PART F: Putting everything together

I took an empty box, made a couple of holes with a knife, put everything in the box, and got the wiring out of the holes. I kept the battery inside the box because I didn't want water to get on the battery or wires.

idk

idk

idk

This project was inspired by Alan Constantino

Top comments (2)

Collapse
 
rivercory profile image
hyeonho

You're serious about waking up...

Collapse
 
mann_patel profile image
manp242

lol I would never wake up on time even when I have an alarm set for each minute πŸ˜‚