A simple example to use a Passive InfraRed sensor, the HC-SR501, from the "Elegoo37-1 Sensor Kit v2" that Elegoo sent me.
Elegoo did a very great job for the price of the components kit. I strongly recommand this kit for begineer's projects like this one.
This project is also compatible with every HC-SR501 variants and some others PIR sensors. This project includes a python code that is really simple to use.
In this image of the HC-SR501 infrared presence detector seen from below, the different elements are shown. To set the operation you have a jumper to set the operating mode (with or without retriggering). The module is supplied with + 5v, but a voltage regulator reduces this voltage to 3.3v. The module output is also 3.3v, which allows the output to be directly connected to a GPIO input. If you have a module which outputs 5v, refer to the page on Resistors for the calculation of the divider bridge to use.
- Supply voltage: 5V - 20V
- Consumption: 65mA
- TTL output: 3.3V, 0V
- Time during which the output is at 1: Adjustable (3s to 5min)
- Ti locking time: ˜0.2 sec to 3s depending on manufacturer
- Trigger: with retrigger, without retrigger
- Sensitivity: less than 120 °, up to 7 meters
- Temperature: - 15 to + 70 ° C
- Dimension: 32 * 24mm, distance between mounting holes 28mm, M2 screw Lens diameter: 23mm
There is a very little manipulation to connect 3 pins of the sensor on the GPIO.
The HC-SR501 module is connected to the 5v power supply available on the GPIO connector of the Raspberry Pi. The orange wire brings the voltage of + 5v and the black wire brings the ground. The output of the module is connected by a blue wire to pin 7 of the GPIO connector (this corresponds to GPIO 4). See details in shematics.
Python is required. Install it before doing anything.
Clone code exemple in this gist where you want in your RPi.
git clone https://gist.github.com/wdelenclos/e8a95fbf3e15a06f46eabf3f395ab698#file-app-py
Open your command line and launch the script :
python app.py
Your code should display "Detected" when something is detects.
Enjoy!
Comments
Please log in or sign up to comment.