website
Skip to content

Raspberry Pi

Raspberry Pi Project #4 - Making an Alarm Circuit Using Raspberry Pi and Relay Module

by Yasir Cicek 01 Mar 2023

In this project, an alarm circuit will be made using a motion detector and a relay module to trigger the Raspberry Pi boards.

Required Materials:

How Does a Relay Work?

When a relay module receives a logic 0 signal (0 V) from the “IN” pin, the NO and COM terminals complete the circuit. If it is desired to use it in reverse, the NC (normally closed) terminal would be used instead of the NO (normally open) terminal. Relays can be used in High Voltage AC mains voltage. However, someone who does not have enough knowledge about relays should be careful.

 

Raspberry Pi Motion Sensitive Relay Module Wiring Diagram    

 

Raspberry Pi Motion Sensitive Relay Module Python Code   

import time

import RPi.GPIO as io

 

io.setmode(io.BCM)

pir_pin = 24

power_pin = 23

io.setup(pir_pin, io.IN)

io.setup(power_pin, io.OUT)

io.output(power_pin, True)

while True:

    if io.input(pir_pin):

        print(POWER ON)

        io.output(power_pin, False)

        time.sleep(20)

        print(POWER OFF)

        io.output(power_pin, True)

        time.sleep(5)

        time.sleep(1)

 

Thanks to this code, the PIR sensor triggers the relay after detecting any motion and stays open for 20 seconds. Later, the relay closes, and after 5 seconds, this loop starts again. This simple motion detector can be used as a security system by connecting the output of the relay to an alarm or video recorder, etc.

Keep Learning More about Raspberry Pi    

Raspberry Pi is a platform with many advantages and is admired by other developers. With the support and convenience in electronic projects, computer science, and robotics studies, Raspberry Pi makes learning enjoyable, and this module is developing day by day. Don’t you also want to improve further? We take you on a journey with Raspberry Pi to improve your Linux knowledge, dive into the electronics world, and carry out fun projects. Keep following the Raspberry Pi training series that has been prepared for you.

Prev Post
Next Post
Someone recently bought a
[time] ago, from [location]

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Robotistan
Have Questions?
Back In Stock Notification
this is just a warning
Login
Shopping Cart
0 items