Raspberry Pi Pico and PIR Sensor
by Ramatronics Laboratory in Circuits > Sensors
2885 Views, 2 Favorites, 0 Comments
Raspberry Pi Pico and PIR Sensor
INTRODUCTION:
In this instructables, I am going to show you how you can interface a PIR sensor to raspberry pi pico. PIR stands for passive infrared sensor. It is a sensor that is used to detect the motion of the objects. Using this sensor we can create a motion detected, so whenever any object passes or moves in front of the PIR sensor it detects them and produces a signal on its output pin. Here I am using a buzzer and led so whenever the motion is detected, the buzzer starts weeping and led starts flickering faster. If no motion is detected by the sensor, the led turns on and off for specific duration the buzzer remains silent 😶.
Reference:
https://www.componentsinfo.com/hc-sr501-module-pinout-datasheet/
Supplies
Hardware Requirements:
https://quartzcomponents.com?sca_ref=3671286.DzEptz4I3w
Raspberry Pi Pico
https://quartzcomponents.com/products/raspberry-pi-pico?_pos=3&_sid=8b8404eba&_ss=r
PIR Sensor
https://quartzcomponents.com/products/hc-sr501-pir-sensor?_pos=2&_sid=4e7b34192&_ss=r
Buzzer
https://quartzcomponents.com/products/piezo-buzzer?_pos=3&_sid=508109a6b&_ss=r
LED(color = Red, size = 5mm)
https://quartzcomponents.com/products/red-5mm-led?_pos=1&_sid=255c8c547&_ss=r
Resistor(330 Ohm 1/4 W)
Jumper Wires(male-to-male)
https://quartzcomponents.com/products/65pcs-breadboard-jumper-cable?_pos=7&_sid=2e644b9bd&_ss=r
Bread Board
Software Requirements:
Thonny Micro python IDE
Working of PIR Sensor
HC SR501 PIR Motion Sensor Module Explained / Description
HC SR501 PIR motion sensor also called Pyroelectric, Passive infrared or IR motion sensor. As shown in above image these are small approximately 1.2 x 0.9 inch sized printed circuit board with the PIR motion sensor mounted on the front side and covered by a white fresnel lens that increases the performance of the lens and at the same time protect it. The backside of the PCB is the circuitry with chip and all the components require for processing the information received from the sensor.
Module sensitivity & time delay adjustments
The back side circuitry also contains two variable resistors / adjusters, one variable resistor is given to adjust the sensitivity of the module or in other words we can say the detection range of the module and other one is used to adjust how much time the output will remain high after the PIR module has detected an activity.
Trigger Modes (Optional Modes)
There are two trigger modes in the module marked with the letter “L” and “H” that is also shown in the image above. These are optional modes and there is no need to work on these modes to use the module. By default the module is set on its most common trigger mode. But in case you want to use them then the points are given. To select any mode just connect it with the middle point, you can also use a jumper by soldering three pins on these points. But first it is important to understand what each mode does.
- Trigger Mode “L”
Trigger mode “L” is called single trigger mode. By selecting trigger mode “L” the output will goes high only one time until the time delay period is completed. No matter how many time an object is moved in front of the sensor’s detection range.
- Trigger Mode “H”
Trigger mode “H” is called repeat trigger mode. By selecting trigger mode “H” the output will goes high as many times as the object moves in the detection range of the sensor hence, the time delay started again each time a single motion is detected.
Temperature & light sensing (Optional Modes)
To further enhance the module performance you can also use the temperature sensing and light sensing functions / features of the module. For doing so you don’t have to do any complex thing only you have to add a sensor for each that’s it and after that all the measurement work is done by the BSS0001 chip. By closely looking at the PCB back side you will find 2 holes marked RT and 2 holes marked as RL.
RT
The 2 holes / points marked RT is given to solder a thermistor. A thermistor is a temperature sensing resistor whose resistance changes when the temperature around it changes. Using a thermistor increases the module performance when the temperature goes above +32 Celsius. The thermistor should be mounted from front side of the PCB.
RL
Using the RL feature makes the module to only work in dark which saves battery life a lot by only activating the module in dark / night. For using this feature you only have to solder a LDR or light dependent resistor. An LDR is a light sensing resistor whose resistance changes when the amount of light changes on its surface. The LDR should be mounted from front side of the module.
Working:
The PIR motion sensor module or PIR motion sensing technology works by sensing the change occurs in the infrared radiation or heat generated by a human or animal body in movement or motion. When the pyroelectric sensor detects this phenomenon, it sends an output signal that is further processed by the BISS0001 chip. BISS001 is a low power, high quality and reliable PIR signal processing chip which is built with CMOS technology. After the signal is processed by the chip and if the signal is true then the output of the chip goes high for a certain amount of time that can be adjusted with the variable resistor used in this module.
HC SR501 Module Features & Technical Details
- Wide operating voltage range from 4.8V to 20V
- Low power consumption in idle mode only 50uA and 65mA in fully active mode.
- High reliability
- Adjustable sensitivity or detection distance
- Adjustable output time delay (Adjust how much time the output will remain high after the sensor detects a signal)
- Can be used separately without any additional microcontroller or platform like Arduino or Raspberry Pi etc. But you can use them to enhance your project.
- Light sensing control feature (Optional)
- Temperature sensing control feature (Optional)
- Low cost
- Using BISS0001 high quality PIR processing chip
- 120 degree detection angle
- 3 to 7 meters or more detection range
- Easy to communicate with any platform like Arduino or Raspberry Pi etc. and also with all microcontrollers.
- Easy to communicate with analog circuits
Applications
Home Security
Office / Work Place Security
Saving Power (Switch ON appliances only when someone is present)
Human Detection
Animal Detection
Industrial Equipment Automation
Making a Prototype Circuit on Bread Board
To make a prototype circuit on a bread board, fix your raspberry pi pico on the bread board. Also fix the LED, buzzer and resistor on the bread board as shown in the diagram. After placing all the components on the bread board. Now make the proper wiring collection among them with the help of given circuit images and following wiring scheme:
Raspberry pi pico
VBUS----------->+Ve Rail(line) of the bread board
GND------------>-Ve Rail(line) of the bread board
Buzzer
Vcc--------------> GPIO-14
GND------------> GPIO-15
PIR Sensor
Vcc------------>+Ve Rail(line) of bread board.
GND----------->-Ve Rail(line) of bread board.
OUT----------->GPIO-16
LED
Anode------------->GPIO-15(In series with a 330 ohm Current limiting resistor).
Cathode---------->-Ve Rail(line) of the bread board.
Note: After making all wiring connections, recheck all the connected before powering the circuit using an USB cable.
Writing the Micro Python Program
The micro python code for motion detector is following:
import machine
import utime
sensor_pir = machine.Pin(16, machine.Pin.IN)
led = machine.Pin(15, machine.Pin.OUT)
buzzer = machine.Pin(14, machine.Pin.OUT)
def pir_handler(pin):
print("ALARM! Motion detected!") #print the message.
for i in range(50):
led.toggle()
for j in range(25):
buzzer.toggle()
utime.sleep_ms(3)
sensor_pir.irq(trigger = machine.Pin.IRQ_RISING, handler = pir_handler)
while True:
led.toggle() #toggle the led.
buzzer.off() #turn off buzzer.
utime.sleep(5) #delay for 5 seconds.
After writing the above program save it on your raspberry pi pico board with name of the file as main.py and click on run.