<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: manp242</title>
    <description>The latest articles on Forem by manp242 (@mann_patel).</description>
    <link>https://forem.com/mann_patel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1238864%2Fc5929dae-a432-483d-965c-7869a17b9423.png</url>
      <title>Forem: manp242</title>
      <link>https://forem.com/mann_patel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mann_patel"/>
    <language>en</language>
    <item>
      <title>Alarm clock which splashes water on your face</title>
      <dc:creator>manp242</dc:creator>
      <pubDate>Sun, 24 Dec 2023 06:45:44 +0000</pubDate>
      <link>https://forem.com/mann_patel/water-alarm-clock-using-raspberry-pi-3i2g</link>
      <guid>https://forem.com/mann_patel/water-alarm-clock-using-raspberry-pi-3i2g</guid>
      <description>&lt;p&gt;This isn't a complicated project, and anyone with a decent amount 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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/dp/B08PBQ1N1G?psc=1&amp;amp;ref=ppx_yo2ov_dt_b_product_details" rel="noopener noreferrer"&gt;DC 5V Micro Submersible Water Pump
&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Silicon Pipe - Came with the pump ^^^&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/dp/B00VRUAHLE?psc=1&amp;amp;ref=ppx_yo2ov_dt_b_product_details" rel="noopener noreferrer"&gt;5v Relay Module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.com/ELEMENT-Element14-Raspberry-Pi-Motherboard/dp/B07P4LSDYV/ref=sr_1_9?crid=ER1J5KZAZDK6&amp;amp;keywords=rpi+3b%2B&amp;amp;qid=1703399619&amp;amp;sprefix=rpi+3b%2B%2Caps%2C143&amp;amp;sr=8-9#customerReviews" rel="noopener noreferrer"&gt;Raspberry Pi 3b+ &lt;/a&gt;( you can use almost any kind of RPI ) &lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Amazon-Basics-Performance-All-Purpose-Batteries/dp/B00MH4QM1S/ref=sr_1_1_ffob_sspa?crid=2USYRYQ9G77SA&amp;amp;keywords=9V+battery&amp;amp;qid=1703399666&amp;amp;rdc=1&amp;amp;sprefix=9v+battery%2Caps%2C415&amp;amp;sr=8-1-spons&amp;amp;sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&amp;amp;psc=1" rel="noopener noreferrer"&gt;9V battery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/dp/B01IFP0N3U?psc=1&amp;amp;ref=ppx_yo2ov_dt_b_product_details" rel="noopener noreferrer"&gt;9V Battery Clip
&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.com/dp/B01EV70C78?psc=1&amp;amp;ref=ppx_yo2ov_dt_b_product_details" rel="noopener noreferrer"&gt;Dupont Wire&lt;/a&gt; (female-female and male-female) &lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Wapodeai-Electrical-Temperature-Resistance-Waterproof/dp/B07ZWC2VLX/ref=sr_1_4?keywords=Electric+Tape&amp;amp;qid=1703399739&amp;amp;s=industrial&amp;amp;sr=1-4" rel="noopener noreferrer"&gt;Electric Tape&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;IMPORTANT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Before we get started, I want to explain how each component will work with each other.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;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.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;LET's GET STARTED:&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PART A:&lt;/strong&gt; Connecting the RPI to the relay switch&lt;br&gt;
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.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GND is used to complete the circuit. ( IF YOU DON'T UNDERSTAND THIS YOU MIGHT WANT TO DO SOME RESEARCH: &lt;a href="https://www.youtube.com/watch?v=5NxVmg8ZFEc&amp;amp;ab_channel=bytesizedengineering" rel="noopener noreferrer"&gt;How to use a relay&lt;/a&gt; ) &lt;/li&gt;
&lt;li&gt;VCC is used to power the relay switch&lt;/li&gt;
&lt;li&gt;SIGNAL is used to pass our code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5uffmiy1nwpmi066dur.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5uffmiy1nwpmi066dur.JPG" alt="idk" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PART B:&lt;/strong&gt; Understanding the motor and battery connection&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fow6genkp92si53rvjt67.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fow6genkp92si53rvjt67.JPG" alt="idk" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PART C:&lt;/strong&gt; Adding relay switch between the battery and motor connection&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;COMPLETELY OPTIONAL: &lt;em&gt;In this picture, I used a male-to-female Dupont wire just because my wire for the motor was not long.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6pf3p969xqwemluojbx.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6pf3p969xqwemluojbx.JPG" alt="idk" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PART D:&lt;/strong&gt; Connecting everything &lt;/p&gt;

&lt;p&gt;Now you hopefully understand the whole circuit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The RPI powers the relay switch and gives it the signal on when to turn on and off.&lt;/li&gt;
&lt;li&gt;When the relay switch turns on, it'll finish the circuit between the motor and the battery, activating the motor.&lt;/li&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;_ I attached an empty mechanical pencil at the point of output so the water would shoot out faster._&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9wxnmu27h4hkae3p5vc.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9wxnmu27h4hkae3p5vc.JPG" alt="idk" width="800" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpo0a1b85v76d043bez1b.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpo0a1b85v76d043bez1b.JPG" alt="idk" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part E:&lt;/strong&gt; Coding!!!&lt;/p&gt;

&lt;p&gt;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. &lt;strong&gt;But&lt;/strong&gt; 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&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I &lt;a href="https://www.youtube.com/watch?v=NWBmYnNvN3A&amp;amp;t=383s&amp;amp;ab_channel=CarolineDunn" rel="noopener noreferrer"&gt;connected to my RPI using the VNC viewer&lt;/a&gt; and ran the code in Thonny. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PART F:&lt;/strong&gt; Putting everything together&lt;/p&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7c3w6xcf641j0h803x7.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7c3w6xcf641j0h803x7.JPG" alt="idk" width="800" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5d1bcqhysqpiwg2svn2.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv5d1bcqhysqpiwg2svn2.JPG" alt="idk" width="800" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjtu22jp37tf7dtzera0i.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjtu22jp37tf7dtzera0i.JPG" alt="idk" width="800" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This project was inspired by &lt;a href="https://dev.to/alanjc/water-your-plant-using-a-raspberry-pi-and-python-2ddb#comment-1dcic"&gt;Alan Constantino &lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>raspberrypi</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
