Skip to content
Free Shipping Over $150*

Raspberry Pi Projects

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.

Sample Block Quote

Praesent vestibulum congue tellus at fringilla. Curabitur vitae semper sem, eu convallis est. Cras felis nunc commodo eu convallis vitae interdum non nisl. Maecenas ac est sit amet augue pharetra convallis.

Sample Paragraph Text

Praesent vestibulum congue tellus at fringilla. Curabitur vitae semper sem, eu convallis est. Cras felis nunc commodo eu convallis vitae interdum non nisl. Maecenas ac est sit amet augue pharetra convallis nec danos dui. Cras suscipit quam et turpis eleifend vitae malesuada magna congue. Damus id ullamcorper neque. Sed vitae mi a mi pretium aliquet ac sed elitos. Pellentesque nulla eros accumsan quis justo at tincidunt lobortis deli denimes, suspendisse vestibulum lectus in lectus volutpate.
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

Recently Viewed

Have Questions?
Back In Stock Notification
this is just a warning
Login