Download Print this page

Advertisement

Quick Links

A warm welcome!
Thank you very much, for choosing in favour of our AZ-Delivery HC-SR501
PIR module. On the following pages, we will show you how to use and set up
this practical device .
Have fun!

Advertisement

loading
Need help?

Need help?

Do you have a question about the HC-SR501 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for AZ-Delivery HC-SR501

  • Page 1 A warm welcome! Thank you very much, for choosing in favour of our AZ-Delivery HC-SR501 PIR module. On the following pages, we will show you how to use and set up this practical device . Have fun!
  • Page 2 Areas of application Education and teaching: Use in schools, universities and training centres to teach the basics of electronics, programming and embedded systems. Research and development: Use in research and development projects to create prototypes and experiments in the fields of electronics and computer science. Prototype development: Use in the development and testing of new electronic circuits and devices.
  • Page 3 If the product complies with the requirements of the RoHS Directive (2011/65/EU) and does not contain any hazardous substances in quantities exceeding the permitted limits, residues may still be present. Observe the following safety instructions to avoid chemical hazards: Caution: Soldering can produce vapours that can be harmful to health. Note: Use a soldering vapour extractor or work in a well-ventilated area.
  • Page 4: Table Of Contents

    Table of contents Introduction Properties Setting the hardware functions Specifications The pin assignment Setting up the Arduino IDE How to set up the Raspberry Pi and Python Connecting the module to the ATmega328p microcontroller Example sketch Connecting the module to the Raspberry Pi Python script...
  • Page 5: Introduction

    Introduction The HC-SR501 PIR module is a device that can recognise changes in infrared light. For example, human activity if it is within the detection range of the module. The module is based on infrared technology and uses a pyroelectric passive infrared sensor, or PIR for short. It consists of a pyroelectric sensor and some additional electronic components.
  • Page 6: Properties

    Properties • Automatic induction • Light-sensitive control • Temperature compensation • Two-way release • Induction blocking time • Wide operating voltage range • Micro power consumption • High signal power The automatic induction function switches the output to HIGH if the object is within the detection range.
  • Page 7 The two-way trigger function has two modes that can be set using the jumper on the circuit board. The first mode is the non-repeatable trigger. In this mode, the output is automatically set to the LOW state after a certain delay when it is in the HIGH state.
  • Page 8 Customisation of hardware functions The HC-SR501 module has two trim potentiometers, T1 and T2. The sensitivity is set with the trimming potentiometer T1 and the delay of the output with the trimming potentiometer T2. The Jumper J1 is used setting the temperature compensation.
  • Page 9 To use the module in this mod, simply remove jumper J1 and connect the power supply cable to pin H (pin 1 of J1). There are two trim potentiometers on the module which are used to adjust the sensitivity and delay. The sensitivity can be adjusted by turning the trim potentiometer T1 clockwise (CW), which increases the distance measuring range to approx.
  • Page 10: Specifications

    Specifications Voltage of the power supply: 5V DC Operating temperature: from -15 to +70℃ Locking period: 200 milliseconds Detection range: 110 degrees Detection range: up to 7 metres from 2.5 sec. (standard) up to 10 sec. Block time: L - Deactivate, H - Activate trigger trigger methods: repetition LOW - 0V, HIGH - 3.3V (logic level)
  • Page 11: The Pin Assignment

    The pin assignment The HC-SR501 PIR module has three pins. The pin assignment is shown in the following illustration: Note: The preferred operating voltage range is 5 V. The output voltage at the digital pin is in the range of 3.3 V.
  • Page 12 To set up the Arduino IDE If the Arduino IDE is not installed, follow the link and download the installation file for the operating system of your choice. Windows users double-click on the downloaded .exe file and follow the instructions in the installation window.
  • Page 13 For Linux users, download a file with the extension .tar.xz, which must be unpacked. After unpacking, change to the unpacked directory and open the terminal in this directory. Two .sh scripts must be executed, the first is called arduino-linux- setup.sh and the second is called install.sh. To execute the first script in the terminal, open the terminal in the extracted directory and execute the following command: sh arduino-linux-setup.sh user_name...
  • Page 14 A text editor is pre-installed on almost all operating systems (e.g. Windows with Notepad, Linux Ubuntu with Gedit, Linux Raspbian with Leafpad etc.). All of these text editors are perfectly adequate for the purpose of the e-book. Next, you need to check whether your PC can recognise the microcontroller board.
  • Page 15 If the Arduino IDE is used under Windows, the port names are as follows: For Linux users, the name of the connection is, for example /dev/ttyUSBx, where x is an integer between 0 and 9.
  • Page 16: How To Set Up The Raspberry Pi And Python

    All this is explained in detail in the free eBook: Raspberry Pi quick start guide Python is already pre-installed on the Raspbian operating system. Connecting the module to the ATmega328p microcontroller Connect the HC-SR501 PIR module to the ATmega328p as shown in the following connection diagram:...
  • Page 17 Colour of PIR pen MC pen the cable Red cable Blue cable Black cable Sketch example #define OUT_PIN 2 uint8_t output_value = 0; bool motion_detected = false; void setup() { Serial.begin(9600); pinMode(OUT_PIN, INPUT);...
  • Page 18 delay(60000); void loop() { output_value = digitalRead(OUT_PIN); (output_value) { Serial.println("Object detected!"); motion_detected = true; delay(3000); otherwise Serial.println("No object!"); (motion_detected) { Serial.println("Wait!"); delay(6000); Serial.println("Ready..."); motion_detected = false; Upload the sketch to the ATmega328p and start the Serial Monitor (Tools > Serial Monitor). The result should look like the following picture:...
  • Page 19 Sketch starts with the creation of a macro called OUT_PIN. It represents the digital output pin of the ATmega328p, which is used to connect the sensor output pin. Next, two variables called output_value and motion_detected created. output_value variable saves the status of the output pin. The motion_detected variable is used to display the messages in the serial monitor.
  • Page 20: Connecting The Module To The Raspberry Pi

    Wait! is displayed in the serial monitor, followed by a delay of six seconds. After this, the message Ready... is displayed in the serial monitor. Connecting the module to the Raspberry Pi Connect the HC-SR501 PIR module to the Raspberry Pi as shown in the following connection diagram:...
  • Page 21 Physical RTC pin Raspberry Pi Colour of the cable needle cable Blue GPIO14 cable Black cable...
  • Page 22: Python Script

    Python script import RPi.GPIO GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) PIR_PIN # Assignment of GPIO4 pin 7 to PIR GPIO.setup(PIR_PIN, GPIO.IN) # Set up GPIO pin PIR as input print('Sensor initialised . . time.sleep(60) # Give the sensor 60 seconds to start up print('Active') pir(pin): print('Motion...
  • Page 23 Save the script under the name pir.py. To execute the script, open the terminal in the directory in which you saved the script and execute the following command: python3 pir.py The result should look like the following picture: To end the script, press 'CTRL + C' on the keyboard.
  • Page 24 The script starts with the import of two libraries, Rpi.GPIO and time. The GPIO pin names are then set to BCM and all warnings relating to the GPIO interfaces are deactivated. Next, the pin mode of GPIO pin 4 is set to input, followed by a delay of 60 seconds to warm up the sensor.
  • Page 25 Next, the try-except-finally code block is created. An infinite loop is created in the try code block, in which a pause of 100 microseconds is inserted so that the loop itself does not block the Raspberry Pi. The exception code block is executed when the key combination 'CTRL + C' is pressed on the keyboard.
  • Page 26 Now it's time to learn and create your own projects. You can do this with the help of many example scripts and other instructions that you can find on the Internet. If you are looking for high-quality microelectronics and accessories, AZ-Delivery Vertriebs GmbH is the right address for you. You will receive numerous application...