Interface a PIR Sensor
Last updated May 2019
Introduction
Welcome to ProteShea – in this project, we’ll be replacing the DHT11 temperature and humidity sensor from Project 10 and interfacing a Passive InfraRed (PIR) sensor with the Arduino Uno. The PIR sensor can detect movement up to 30′ away at 180 degrees. This can be useful in motion-activated projects such as a security system or automatic lighting in an office or classroom.
Disclaimer
ProteShea, LLC is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Some links may be affiliate links, in which ProteShea, LLC earns a commission if you use that affiliate link. Please note that this is at no additional cost to you and helps us in creating more content.
Here’s what you’ll need to get started:
16x2 Character LCD
Please see Project 9 on how to interface the 16×2 LCD in 4-bit mode. You should have pins 4, 6, and 11-14 of the LCD connected to Uno pins 2,3, and 4-7, respectively. The LCD is mounted to the Modulus Canister via the 16-pin, right-angle female header soldered to the 1-to-1 link, as shown in the image below.
Passive InfraRed (PIR) Sensor
The PIR sensor that we are using consists of 4 pins: GND, VCC, OUT, and EN. It can measure movement up to 30′ away which can be adjusted with the potentiometer on the module. Within the dome-shaped lens (used to focus the incoming light onto the detectors), there are two slots that can detect different levels of infrared (IR) light or radiation. The sensor does not detect motion when the detectors sense the same amount of IR. The motion is detected when the detectors measure two different levels of IR. The levels of IR can vary from object to object since each one emits different amounts of heat energy.
A table is shown below that outlines the specifications for the PIR sensor that we are using. The datasheet is also available here.
If you completed Project 10, remove the DHT11 sensor and insert the PIR sensor. You should have the 4-pin R/A female header soldered to Modulus. There should also be a 4-pin single-row male header soldered adjacently to the R/A female header. This is used so we can wire-wrap. You have to create a solder bridge between each contact to connect the respective pins on the female header to the male header.
Once the headers are soldered on, plug the Modulus Canister into the 4×26-pin connector on the FuelCan, and insert the PIR sensor as shown below. Using the image below as reference, wire-wrap the leftmost pin of the male header to the GND vector on Modulus and the second pin from the left to +5Vdc on the 4×26-pin breakout. The third and fourth pins from the left are OUT and EN, respectively. Use a 12″ F/M to route the OUT pin to pin 8 on the Uno, and the EN pin to pin 9 on the Uno.
If you are using a breadboard, the wiring schematic is shown below.
FuelCan Wiring
First, mount the Arduino Uno to the FuelCan’s prototyping area. If you are using a breadboard instead of Modulus, place the breadboard in the bottom storage compartment to limit the length of the jumper wires. You’ll need to supply +5V and GND to the power and ground rails on the breadboard by using the provided banana jack to test-lead clip cables. You will need two male header pins to mount the test-lead clips on the breadboard side. Plug the Type A side of the USB cable into USB1 receptacle and the Type B side into the Uno’s receptacle. Power up the FuelCan with the AC-DC power adapter.
For additional information about the Fuelcan-910, click here.
Software
Once the wiring is complete and the FuelCan is powered up, we can now load the sketch onto the Uno. The sketch is below. The PIR sensor is enabled in void setup (). In void loop (), the OUT pin from the sensor is polled – if the pin goes HIGH, “Motion detected” is displayed on the LCD. If the OUT pin is LOW, “No motion” is displayed on the LCD.
There is a nomotionflag within the sketch which limits the amount of times we write to the LCD. For example, if the flag equals zero, we display “No motion” on the LCD. Once it is displayed, the flag gets set to one and it will not keep writing “No motion” if no movement is detected. When movement is detected, the flag gets reset to zero, and “Motion detected” is displayed on the LCD.
About Author
Eric Shea is the founder of ProteShea and is an electrical engineer. He wishes to have a major impact on bridging the gap between engineering theory and real-world applications. He has worked at Kratos Defense, SpaceX, Air Force Research Laboratory, and Polaris Industries. He received a M.S. in electrical engineering from the University of Pittsburgh and a B.S. in electrical engineering from the University of Florida.