Motion sensing is cool - it has lots of real-world uses in applications like home automation, security, robotics, and more. Use this project to implement your own PIR Motion Sensor using the PSoC Analog Coprocessor!
This example demonstrates how to measure the voltage signal from a PIR motion sensor and detect the movement of an infrared (IR) emitting object (like a person). The measured PIR motion sensor signal and the motion detection status are sent over I2C to a host PC. The RGB LED turns ON whenever motion is detected.
PIR Motion Sensing – Theory of Operation (the sciency stuff behind it)The PIR motion sensor is based on the pyroelectric effect, where certain materials generate a voltage when exposed to infrared radiation. This radiation is the portion of the electromagnetic spectrum that falls between microwaves and visible light. Infrared radiation has wavelengths longer than the visible light but shorter than microwaves. Humans at normal body temperature radiate strongest in the infrared at an approximate wavelength of 10 μm.
The PIR motion sensor uses infrared sensitive materials as the sensing elements. It is packaged with a field effect transistor (FET) in the source follower mode. The FET is required to buffer the high-impedance output of the sensor element. When the sensor element is exposed to infrared radiation, a voltage is generated across the element. Most common PIR motion sensors have two or four sensing elements. These elements are arranged such that the voltage generated by one is subtracted by the other. This arrangement cancels the common signal and generates a voltage only when there is a difference in the incident infrared radiation level on the sensing elements.
The sensor package is designed to have a unique field-of-view for each element. When an IR radiating source moves across the fields of view, the sensor generates a differential signal. For a 90° field-of-view or more, a Fresnel lens is mounted on the PIR motion sensor. It improves the sensitivity and thereby the detection distance.
The PSoC Analog Coprocessor is a neat chip. Not only is it an ARM Cortex-M0+ microcontroller, it also has a whole bunch of real programmable analog hardware that can be used to make real analog circuits to help interface with the real world - things like analog filters, amplifiers, ADCs, DACs, etc.
The PIR motion sensor implementation on the CY8CKIT-048 PSoC Analog Coprocessor Pioneer Kit consists of five stages: a bias circuit for the PIR motion sensor, a first-stage amplifier, a high-pass filter (HPF), a second-stage amplifier, and an ADC. In the main stages of the PIR motion sensor implementation, the two amplifiers are implemented in the PSoC Analog Coprocessor.
The PSoC Analog Coprocessor Pioneer Kit has a dual-element PIR motion sensor (ZRE200GE). The voltage signal generated by the sensor is AC-coupled (using C48) and clamped to the internal reference voltage VREF. The typical sensor output voltage is in the order of several millivolts and varies depending on the strength of the incident infrared radiation. To detect the motion of a human body at a distance of 10 feet, a gain of >1000 is required. A single-stage amplifier with such a high gain causes the amplifier output to saturate due to the amplification of the input offset voltage. Thus, a two-stage amplifier is best suited for amplifying with high gain.
The total gain is split between two stages. The first-stage amplifier uses a non-inverting amplifier configuration using an internal Opamp and external gain setting resistors – R118 and R119. The second-stage amplifier uses a PGA Component. The first stage amplifier gain is set to 681 and the PGA gain is set to 1 on startup. However, the second-stage amplifier gain changes depending on the detection distance required – 3 feet, 10 feet, or 20 feet.
A High Pass Filter (HPF), made using external passive components C91 and R147, is introduced between the first and the second amplifier stages to eliminate the offset voltage.
The PIR motion sensor and gain stages use a 1.2-V bandgap voltage as the reference voltage. The bandgap voltage is independent of supply voltage fluctuations and hence provides a stable voltage reference. This voltage is generated using a programmable reference component, PVref, and is buffered using an Opamp.
The output of the second-stage PGA is connected to the Scanning SAR ADC Component. The Scanning SAR ADC results are compared against threshold values to detect the motion of an IR emitting object. When motion is detected, the LED turns ON for 5 seconds.
In addition to indicating the status on an LED, multiple data such as PIR raw count, detection thresholds, and detection status are sent to a host PC using I2C. The host PC sets the desired detection distance over I2C.
To try out this project, follow these steps:
1. Download and open this project in PSoC Creator. Alternatively, if you have the kit software installed, you can select the CE211301_PIR_Motion_Sensing.cywrk file in the PSoC Creator Start page, under Examples and Kits > Kits > CY8CKIT-048. Select a location to save the code example.
2. Build the project; select the PSoC Creator menu item Build > Build CE211301_PIR_Motion_Sensing.
3. Connect the PSoC Analog Coprocessor Pioneer Kit to your computer’s USB port, as described in the section Hardware Setup.
4. Program the PSoC Analog Coprocessor device; select Debug > Program.
You can now move your hand over the PIR Motion Sensor and observe the LED turn on!
5. Configure the BCP software as described in the section Software Setup below.
6. Select File > Open File. Open the CE211301_PIR_Motion_Sensing.iic
file, from the following path: \CY8CKIT-048 PSoC Analog Coprocessor Pioneer Kit\\Firmware\PSoC Analog Coprocessor\BCP Command\
This file contains the read and write commands to be executed by the BCP. The commands appear on the panel. To set the detection distance, use command #1 - “w 08 00 03”
. To execute the command, click on the instruction and then click the Send
button. See the comments in the BCP for more details on the instruction.
7. To read the sensor data, click on command #2 and then click the Repeat button. This reads the data continuously.
Go to the Chart tab and observe the plot of the four values – PIR Motion Sensor raw data, high threshold, low threshold, and motion detection status – that are read from the PSoC Analog Coprocessor device.
8. Move across the PIR Motion Sensor within the range specified using Command #1. Observe that the red LED turns ON for 5 seconds when the motion is detected. Note that because of the higher sensitivity of the 20-feet mode, the LED may be ON continuously if you are close to the sensor. Make sure the red LED is OFF before making any movement.
(Note - this software is automatically installed when you install PSoC Creator or PSoC Programmer). This section describes how to set up the Cypress Bridge Control Panel (BCP) software for viewing sensor data sent over I2C.
Follow these steps to configure the BCP:
1. Open the BCP from: Start > All Programs > Cypress > Bridge Control Panel > Bridge Control Panel.
2. Select KitProg2/
under Connected I2C/SPI/RX8 Ports (see Figure 6). Note that the PSoC Analog Coprocessor Pioneer Kit must be connected to the USB port of your computer.
3. Select menu item Tools > Protocol Configuration, navigate to the I2C tab, and set the I2C speed to ‘100 kHz
’. Click OK.
4. Select menu item Chart > Variable Settings and Load the CE211301_PIR_Motion_Sensing.ini
file from the following path: \CY8CKIT-048 PSoC Analog Coprocessor Pioneer Kit\\Firmware\PSoC Analog Coprocessor\BCP Command\. Click OK. See Figure 7.
This file includes the variable names, their data type, and their signs, to represent the data sent over I2C.
Comments