Raspberry Pi Projects

Interface PIR Sensor With Raspberry PI – Tutorial

Introduction

In this guide, we will show you how to use a PIR sensor with Raspberry Pi and write Python code to detect motion. PIR Sensors are used to detect movement and are often used in security systems. In this guide, we will use a PIR Sensor to turn an LED on when movement is detected.  In this tutorial, you will learn how to set up a PIR sensor with a Raspberry Pi. You will also learn how to use the PIR sensor to detect when someone enters the room. check Also How to Setup a Raspberry Pi for the First Time | Getting Started with Raspberry Pi

Required Material

What is a PIR sensor?

Interface PIR Sensor With Raspberry PI
PIR Sensor

A passive infrared sensor (PIR sensor) is an electronic sensor that t is used to detect the presence of an object or person and measure it. infrared (IR) light emitted from objects in their field of view. They are most often used in PIR-based motion detectors. A PIR sensor is a sensor that detects motion. PIR sensors are commonly used in security systems and are used to detect when someone is in a room.

PIR sensors are used in a variety of applications, including security systems, automatic lighting controls, and energy-saving devices.

PIR sensor Applications

The applications of this circuit include :

  • Security systems
  • Automatic photographs
  • Robot sensors

How does a PIR sensor work?

PIR sensors can also be used to detect the movement of objects, such as in a motion detector. PIR sensors work by detecting the infrared radiation emitted by objects. When an object is heated, it emits infrared radiation. This radiation is invisible to the human eye but can be detected by a PIR sensor. The sensor contains a special material that is sensitive to infrared radiation. When the sensor is exposed to infrared radiation, the material produces a small electrical current. This current is then used to trigger an alarm or activate a camera. PIR sensors are very sensitive, and can even detect the heat emitted by a human body.

Interface PIR Sensor With Raspberry PI

The Raspberry Pi is a series of small single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in academies and developing countries. and PIR sensors are a simple and useful way to add security to a home or office. What is Raspberry Pi And Their Uses – Beginner’s Guide

How to set up a PIR sensor with Raspberry Pi?

Raspberry Pi GPIO pin

The GPIO pins can be used to interface the Pi with external devices such as sensors, motors, and LEDs. They can also be used to interface the Pi with other computers and devices such as Arduino.

The pinout of the GPIO header is shown below:

Raspberry Pi GPIO pin
Image Credit -Raspberrypi.UK

The GPIO provides the following power and interface options :

  • 3.3V (2 pins)
  • 5V (2 pins)
  • Ground (8 pins)
  • General-purpose input and output
  • PWM (pulse width modulation)
  • I2C
  • I2S
  • SPI
  • Serial

These allow a huge range of sensors, motors, and LEDs to be connected to the Raspberry Pi.

Schematic Diagram of PIR Sensor With Raspberry PI

Here is a circuit diagram of the PIR Sensor and Raspberry Pi :

Wire colour Sensor Raspberry pi
① Red 5V
② Yellow OUT GPIO 20
③ Black GND

pir-sensor-with-raspberry-pi

Now, connect your Raspberry Pi GPIO PIN to the PIR motion sensor as per the connection diagram above:

4 Pir sensor with Raspberry tutorial scaled

Python Code Script for PIR Sensor With Raspberry PI

This program can read the sensor signal when motion detects and print it on the serial monitor.

Copy the following code and paste into Thonny IDE and save it as a Python file: Main.py

Create a new python file PIR.py and enter the following code.
To run the code, open the terminal and go to the directory where your PIR.py is located. Then enter the command ” sudo python PIR.py ” and hit enter

Getting started with Raspberry PI:- https://projects.raspberrypi.org/getting-started-with-raspberry-pi

When run the script waits for the output pin to reach Low. It then prints a message on the screen every time the output changes. This is either when motion is detected (output changes to High) or the device sees no motion (output changes to Low).

Try modifying the reset time by rotating the “time” resistor clockwise by a few degrees. Run the script again, trigger the device, and then wait to see how long it takes to go back to the ready state.

Applications

The applications of this Project:

  • Security systems
  • Automatic doors
  • Robot sensors

Conclusion

 

Read Similar Articles:

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Ad
Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker