Experiment 16: Human Infrared Pyroelectric Sensor Experiment
From Diustou Wiki
Contents
Instructions for Use
- The sensor module has an initialization period of about one minute after power-on, during which it may output 0-3 times intermittently. After one minute, it enters standby mode.
- Avoid direct exposure of the lens on the module surface to light sources and other interference as much as possible to prevent false triggering caused by interference signals. Also, avoid using the module in environments with flowing air, as air can also interfere with the sensor.
- The sensor module uses a dual-element probe with a rectangular window. The dual elements (A and B) are located at the two ends of the longer side. When a human passes from left to right or right to left, there is a difference in the time and distance at which the infrared spectrum reaches the dual elements. The greater the difference, the more sensitive the sensor is. When a human approaches the probe head-on or moves vertically (top to bottom or bottom to top), the dual elements do not detect a change in the distance of the infrared spectrum, resulting in no difference. Therefore, the sensor is not sensitive or does not work. When installing the sensor, the direction of the dual elements should be as parallel as possible to the direction with the most human activity to ensure that the human is sensed by the dual elements successively when passing by. To increase the sensing angle range, this module uses a circular lens, allowing the probe to sense in all directions. However, the left and right sides still have a larger sensing range and stronger sensitivity than the top and bottom directions. Installation should still follow the above requirements as much as possible.
Arduino
Experimental Phenomenon
- The measurement status of the module is printed on the serial port.
Circuit Connection
Reference Program
#define SEN 2 void setup() { Serial.begin(9600); pinMode(SEN, INPUT); } void loop() { int SensorState = digitalRead(SEN); Serial.println(SensorState); delay(100); }
Raspberry Pi
Circuit Connection
Program Execution
Python
- Install the gpiozero library
- You can use the following command to install the library:
sudo apt update sudo apt install python3-gpiozero
- For other systems on the Raspberry Pi, you can use the following command to install the library:
sudo pip3 install gpiozero
- Run the following command to view the GPIO pin definitions on the Raspberry Pi:
pinout
- Download the Raspberry Pi reference example, unzip the file, copy it to the user directory, and run it:
cd raspberrypi/16/python_gpiozero python sensor.py
- At this point, you can see the Raspberry Pi running the traffic light program correctly. To exit, press ctrl+C.
- Command description: gpiozero.MotionSensor(pin, pull_up, active_state, queue_len, sample_rate, threshold, partial)
- Main parameters:
- pin: GPIO pin number;
- pull_up: Internal pull-up/pull-down resistor setting,
- When set to True, the GPIO pin is pulled high through an internal pull-up resistor.
- When set to False (default), the GPIO pin is pulled low through an internal pull-down resistor.
- When set to None, the GPIO pin is floating, and gpiozero cannot guess the active state, so active_state must be set.
- active_state:
- When set to True, the software pin state is also "high" when the hardware pin state is "high".
- When set to False, the input polarity is reversed, so when the hardware pin state is "high", the software pin state is "low".
- When pull_up is set to None, use this parameter to set the unknown pin active state.
- When pull_up is set to True or False, the pin's active state is automatically assigned.
- queue_len: The length of the queue used to store values read from the sensor. The default value is 1, effectively disabling the queue. If your motion sensor is particularly "jittery", you may want to increase this value.
- sample_rate: The intent value for the number of values to read from the device (and append to the internal queue). The default value is 10.
- threshold: The default value is 0.5. When the average of all values in the internal queue is above this value, the sensor is considered "active" by the property, and all events are triggered.
- partial: When set to False (default), the object will not return the value of is_active until the internal queue is full. Set this to True only if you need values immediately after object construction.
- Main parameters:
- For more commands, please refer to the gpiozero documentation