Ever dreamed of bringing your motorized props, animatronics, attractions, and exhibits to life with responsive movements triggered by unsuspecting visitors? The key to achieving this motion-activated magic lies in the dynamic duo of PIR sensors and Arduino.
In this comprehensive guide, I’ll delve into the exciting world of how to use a PIR sensor with Arduino, guiding you through the process of connecting and wiring a PIR sensor to an Arduino seamlessly. I’ll even equip you with PIR sensor and Arduino code examples tailored to your specific project, whether it’s a menacing animatronic suddenly jolting awake or a captivating exhibit unveiling its secrets upon visitor approach. So, buckle up and get ready to unleash the interactive potential of your motion-activated creations!
In this Arduino and PIR Sensor Wiring and Code Tutorial:
How Do PIR Sensors Work?
Every object emits some form of infrared radiation, and the amount of radiation increases with the object’s temperature. PIR (Passive Infrared) sensors are ingenious devices that are specifically tuned to detect the infrared radiation naturally emitted by living beings. Humans and animals, being warmer than the background, emit a different infrared signature than inanimate objects and surroundings. PIR sensors are designed to detect such differences within their field of view, which is typically around 100 degrees.
This capability makes them perfect for security systems and automatic lighting projects where you want to turn on a camera or illuminate an area if movement is detected. But aside from daily life use cases, PIR sensors are indispensable for triggering motorized props in haunted attractions, interactive exhibits or even homemade props on your lawn or porch during the holidays.
You can wire PIR sensors to LEDs, servos, motors, sound modules and more through a relay or connect them to a microcontroller like an Arduino to orchestrate all kinds of motion-activated movements and effects.
A PIR sensor consists of two main parts:
Fresnel Lens
Sitting on top of the actual sensor is a large, white, dome-shaped plastic cover, called the Fresnel lens.

It’s a key component that significantly improves a PIR sensor’s functionality by performing several important jobs:
- Focuses Infrared Signals: The primary function of the Fresnel lens is to focus the infrared radiation from the environment onto the pyroelectric sensor underneath it. Without this lens, the sensor would have a much narrower and less effective detection range.
- Increases Detection Area: The Fresnel lens is designed with multiple hexagons, each angled slightly differently. This design allows the lens to capture infrared radiation over a wider area and direct it towards the sensor. It effectively expands the sensor’s field of view, enabling it to detect motion across a broader area.
- Creates Detection Zones: The unique structure of the Fresnel lens divides the sensor’s field of view into multiple zones of sensitivity. When an object moves from one zone to another, the difference in the infrared radiation levels between the zones triggers the sensor. This zoning is key to the PIR sensor’s ability to detect movement rather than just the presence of heat.
Pyroelectric Sensor
If you pop off the Fresnel lens, it will reveal the pyroelectric sensor, which looks like a black rectangular window. The pyroelectric sensor is the heart of a PIR sensor, converting the infrared radiation changes caused by motion into electrical signals that can be processed to trigger various actions.

Pyroelectricity refers to the property of certain materials to generate a temporary voltage when they are heated or cooled. When the IR radiation from a warm body, like a human or animal, enters the PIR sensor, it passes through the Fresnel lens and reaches the pyroelectric element. As this element warms up due to the incoming IR radiation, it undergoes a change in polarization, generating a temporary voltage. This change is more pronounced when there’s movement across the sensor’s field of view, causing fluctuations in the amount of IR radiation reaching the sensor.
Most pyroelectric sensors in PIR devices have two slots or sections made of pyroelectric material, and they are wired in such a way that they cancel each other out under steady conditions. When there is no movement, both halves detect similar levels of IR, resulting in no differential change. If a warm object moves across the sensor’s field of view, one section warms up before the other, creating a differential change in voltage. This difference is what the PIR sensor circuit detects as motion.
The PIR sensor then outputs a signal (usually high voltage) to indicate that motion has been detected. This high signal can be used to trigger other components like motors and servos found in props, room lighting, cameras and more.
How to Adjust PIR Sensor Settings
PIR sensors usually come with adjustment options that allow you to customize their performance according to specific needs or applications. These adjustments typically involve sensitivity to motion, the time delay before the sensor resets after detecting motion, and sometimes the mode of operation regarding how the sensor responds to detected motion.
Here’s a closer look at these adjustment options:
1. Time Delay Potentiometer Knob on PIR Sensor
The time delay knob controls how long the sensor output remains in the high (active) state after detecting motion. Once the PIR sensor detects motion and triggers, the output signal is sent to activate the connected device (like turning on a light or triggering a motor). The time delay adjustment determines how long this signal stays high before returning to the low state, effectively determining the minimum duration for which the connected device remains activated after motion is no longer detected.

The potentiometer located on the left is used for adjusting the time delay. Turning it clockwise increases the duration that the sensor remains triggered after detecting motion, while turning it counter-clockwise decreases this duration. Time delays can typically range from a few seconds to several minutes, depending on the sensor model.
2. Sensitivity Potentiometer Knob on PIR Sensors
The sensitivity knob is just to the right of the time delay knob and adjusts the sensor’s range or how sensitive it is to motion. This adjustment changes how much infrared radiation change is needed to trigger the sensor. The sensitivity is primarily about the distance from the sensor at which motion can be detected, and sometimes, how subtle the motion can be to trigger a detection.

Turning the sensitivity potentiometer clockwise increases sensitivity and expands the detection range, allowing the sensor to pick up smaller or more distant movements. This setting is preferred in situations where you need to monitor a larger area or want to make sure no movement goes undetected, even if it’s minor or far from the sensor. For most PIR sensors, this allows it to detect movement up to 7 meters (21 feet) away.
As you may have guessed, turning the sensitivity knob counter-clockwise, decreases sensitivity. This means the PIR sensor will only detect motion that is closer or more significant, usually to up 3 meters (9 feet). This setting helps to avoid false triggers from distant or small sources of motion, such as small animals or distant movements.
3. Trigger Mode Selection on a PIR Sensor
The jumper on a PIR sensor is a small, removable connector that allows you to select between different operational modes. It alters how the PIR sensor reacts to detected motion in terms of triggering its output signal.

The two common positions for this jumper are labeled “L” (Low) and “H” (High), and they change how the sensor reacts to continuous motion within its detection range.
Single Trigger Mode (L Position)
When the jumper is in the “L” position, the sensor is set to a “Single” or “Non-Repeatable” trigger mode. In this mode, once the sensor detects motion and triggers, it will not trigger again until the time delay period has expired, regardless of whether there is continued motion in front of the sensor.

This means the sensor’s output will go high for the duration set by the time delay knob and stay high until the delay period is over, even if motion continues to be detected during this time. It effectively “locks out” any new motion detection events until the initial time delay has fully elapsed. Then the output returns to low and is ready to be triggered by motion again.
This mode is useful for projects where you want a single, uninterrupted activation period per motion event.
Repeatable Trigger Mode (H Position)
The “H” position puts the PIR sensor in a “Repeatable” trigger mode. In this configuration, every time the sensor detects new motion while the output signal is still high, it resets the time delay timer.

This means that if there is continuous motion in front of the sensor, the output can stay high for significantly longer than the initially set time delay, as it keeps getting extended with each new detection of movement.
This mode is particularly useful for projects where you want to ensure that a device stays activated as long as there is movement in the area, such as in lighting control systems where lights should remain on as long as people are moving around.
PIR Sensor Pinout
The pinout for a typical PIR sensor is relatively straightforward, consisting of three main pins. These pins are used to connect the sensor to a power source and to an output device, like a microcontroller (e.g., Arduino) or directly to an LED or relay module for simple applications.

Here’s a breakdown of the standard pin configuration:
- VCC (Power): This pin is used to connect the sensor to the power supply. The voltage requirements can vary slightly depending on the specific model of the PIR sensor, but most sensors operate within a range of approximately 5V to 12V, although 5V is commonly used. This makes them compatible with a wide variety of microcontrollers and battery-powered projects.
- OUT (Output): This center pin is the PIR sensor’s output signal. When the PIR sensor detects motion, the OUT pin will go high (3.3V) and can be used to trigger an external circuit or microcontroller input pin. The output of this pin will depend on whether the PIR sensor detects motion and the configuration of the trigger mode (repeatable/non-repeatable as determined by the sensor’s jumper position).
- GND (Ground): This pin is connected to the ground line of the power supply. It completes the circuit for the PIR sensor’s power supply and provides a common ground reference for the sensor and the connected microcontroller or output device.
How to Wire a PIR Sensor to an Arduino
Wiring a PIR sensor to an Arduino is a straightforward process that involves connecting three essential pins from the PIR sensor to the Arduino board: VCC, OUT, and GND.
What You Need:
- Arduino board (Uno, Nano, Mega, etc.)
- PIR motion sensor
- Breadboard (optional for easier prototyping)
- Jumper wires
- LED (optional to use as a visual indicator)

PIR and Arduino Wiring Steps
- VCC Pin: Connect the VCC pin of the PIR sensor to the 5V pin on the Arduino. This will power the PIR sensor.
- GND Pin: Connect the GND pin of the PIR sensor to one of the GND (Ground) pins on the Arduino. This establishes a common ground for the circuit.
- OUT Pin: Connect the OUT pin of the PIR sensor to a digital input pin on the Arduino. Any digital pin can be used, but for this example, let’s use pin 12.

After wiring your PIR sensor to the Arduino, we should test it to see if we wired it up correctly.
Pir Sensor Arduino Example Code
Before we hook up any other components to our Arduino circuit like LEDs, servos, etc that we want to be motion-activated by the PIR sensor, let’s see how the PIR works using the Arduino IDE’s serial monitor.
Printing the state of a PIR sensor to the Arduino serial monitor can be done in two main ways: by continuously printing the current state of the sensor or by printing only when there’s a change in the state of the sensor. Both methods have their applications and offer insights into the sensor’s behavior, but they serve different purposes depending on what aspect of the sensor’s output you are monitoring.
1. Arduino Code for Printing the Current State of the PIR Sensor
This method involves continuously reading the output pin of the PIR sensor in the main loop of your Arduino sketch and then printing the current state (HIGH for motion detected, LOW for no motion) to the Serial Monitor at regular intervals.
If your PIR sensor is wired up correctly to the Arduino, then your serial monitor should look similar to this. The Arduino reads the state of the PIR sensor over and over again multiple times per second, printing the result each time. It’s so fast that the results just fly by. In order to slow down the readings you can use an optional delay at the end of the loop () function.

This approach is useful for debugging or when you need to continuously monitor the sensor’s output. It gives you a real-time view of what the sensor is detecting but can lead to a cluttered serial monitor if the state changes frequently.
2. Arduino Code for Printing the State Change of the PIR Sensor
This method involves detecting a change in the state of the PIR sensor from its previous state before printing to the serial monitor. It requires storing the last state of the sensor and comparing it with the current state on each loop iteration. If a change is detected, the new state is printed, and the last state is updated.
Now, the serial monitor only prints the result when the state of the PIR changes rather than the result for every reading interval.

This approach is particularly useful for scenarios where you need to trigger an action on state change or when you want to reduce serial output to only when changes occur, making it easier to observe the PIR sensor’s behavior over time without the clutter of continuous readings.
Continuous State Printing vs State Change Printing: Which One Should I choose?
Choosing between these methods depends on the specific needs of your project, whether that’s detailed monitoring of the sensor’s output or efficient detection and notification of changes in sensor state.
- Continuous State Printing is best used for real-time monitoring or debugging purposes when you need to see exactly what the sensor is detecting at any given moment. It’s straightforward but can generate a lot of serial output.
- State Change Printing is more efficient for logging and responding to actual events of interest, such as triggering actions only when motion is detected or ceases. It reduces serial clutter and focuses on the transitions, which are often the most critical moments to capture in many applications.
PIR Motion-Activated LED with Arduino Code
Using the serial monitor built into the Arduino IDE is an easy way to test whether or not your PIR sensor and Arduino circuit is working as intended. But it’s not always convenient to use long-term or if your project can’t always be near the computer.
A great option to visually monitor the state of the PIR sensor is to either use the Arduino’s built-in LED or wire a separate LED to the Arduino board so that it turns on every time the sensor detects motion.
Here’s an Arduino sketch that will turn on the Arduino’s built-in LED (connected to pin 13) when motion is detected and turn it off when no motion is detected.

You can use this exact same Arduino sketch to make an LED light up, flash, blink and fade according to the state of the PIR sensor. Just remember to change the pin number at the top of the Arduino code to the one you have your LED connected to.
The Journey Continues: Dive Deeper into Arduino and PIR Sensors
With a basic understanding of how to connect and code PIR sensors with Arduino, you’ve unlocked a treasure trove of creative possibilities. Remember, this is just the beginning. Experiment with different wiring configurations, sensors, and code examples to bring your unique vision to life. Don’t be afraid to tinker, modify, and personalize your projects – the world of motion-activated props, animatronics, and exhibits awaits your innovative touch! Share your creations and code in our community, and let’s inspire each other to build even more interactive wonders with the power of PIR sensors and Arduino. Remember, the only limit is your imagination!
