DIY PIR Sensor Motion Recorder Using Arduino featuring a PIR motion sensor, Arduino board, SD card module, and laptop recording detected movement. Learn how to build a smart motion detection and activity recording system with Arduino.

DIY PIR Sensor Motion Recorder Using Arduino - Advanced STEM Project for Kids Aged 8+

This article titled "DIY PIR Sensor Motion Recorder Using Arduino - Advanced STEM Project for Kids Aged 8+" is part of the "Learn Robotics with CYFI" knowledge series by NESTA TOYS.

Article summary: What if your Arduino could not just detect movement but actually record exactly when it happened and when it stopped? The CYFI PIR Motion Recorder logs every movement with a timestamp, prints a live security log on your laptop screen, and even waits to confirm the motion is truly over before closing the entry. It is the most advanced project in the CYFI series and the most impressive one to bring to a school science fair.

This educational content focuses on coding, robotics, computational thinking, STEM learning, and technology education for students, parents, educators, and schools.

CYFI by NESTA TOYS is a structured learning platform that combines block-based programming, robotics simulations, hands-on activities, and a gradual transition to text-based coding using Python and C++.

What if Your Arduino Could Record Every Movement in a Room?

You know how security cameras do not just detect motion but also log exactly when someone walked in and when they left? That is not magic. That is a PIR sensor connected to a timer. And with this CYFI project, your child can build exactly that kind of movement recording system at home.

PIR stands for Passive Infrared. Unlike the IR sensor project which bounces light off objects, a PIR sensor detects the heat that living bodies naturally emit. When a person or animal moves into its field of view, the sensor picks up the change in infrared heat and fires. What makes this project special is that the Arduino does not just detect the movement. It records when it started and when it ended, printed with timestamps on your laptop screen.

Walk in front of the sensor and the Serial Monitor prints motion detected at 45 sec. Walk away and stay still for five seconds, and it prints motion ended at 52 sec. A full movement log, built from scratch, running on a chip the size of your palm.

Get your CYFI PIR sensor module and full kit at cyfi.nestatoys.com and follow this guide step by step.

For parents: This is the most advanced project in the CYFI beginner series. The code introduces timing, state tracking, and event logging. These are concepts used in real security systems, visitor counters, and IoT data loggers. If your child has already built the rain sensor or ultrasonic sensor project, this is a brilliant next step.

What STEM Skills Does Your Child Build by Making a PIR Motion Recorder?

Every project in this series adds something new. The PIR motion recorder adds several things at once, which is why it is the most educational build in the kit.

Your child learns the difference between a PIR sensor and an IR sensor and why PIR is specifically designed to detect living bodies. They learn how the millis() function tracks time without freezing the program the way delay() does. They learn what calibration means and why a sensor needs 30 seconds to settle before it works reliably. And they learn how state flags like lockLow work to prevent the same event being logged twice.

That last concept is important. Preventing duplicate entries in a log is something every software developer, data engineer, and security system designer deals with every day. Your child is solving that problem with a boolean variable in a ten-line loop.

  • How a PIR sensor detects body heat and human movement
  • How millis() tracks elapsed time without stopping the program
  • How calibration works and why sensors need time to settle
  • How state flags prevent duplicate triggers in event logging
  • How to read and interpret a timestamped event log
  • How real security systems and visitor counters work at a fundamental level

Parent note  The 30 second calibration at startup is a real engineering concept. PIR sensors need time to learn the baseline infrared level of the room before they can detect changes accurately. Rushing past this step is the most common reason the project does not work as expected. Tell your child to wait for SENSOR ACTIVE to appear on screen before testing.

What Components Do You Need to Build a PIR Motion Recorder With Arduino?

This is one of the cleanest builds in the series. No breadboard, no complicated wiring. Just three wires connecting the PIR sensor directly to the Arduino. Everything you need is available in the 

Everything is in the CYFI kit from cyfi.nestatoys.com. Beginner safe, low voltage, designed for kids age 10 and above.

PIR sensor module

The white dome you see in the circuit image. It detects infrared radiation emitted by warm bodies. It has three pins: VCC for power, GND for ground, and OUT for the signal. It has a wide detection angle and can sense movement from several metres away.

Arduino Uno

Reads the PIR signal on pin 3, controls the LED on pin 13, tracks time using millis(), and logs motion events with timestamps to the Serial Monitor. All the intelligence of the project lives in the code you upload.

Blue LED on pin 13

Lights up when motion is detected and turns off when motion ends. It gives you a visual confirmation that the sensor has triggered while the Serial Monitor handles the logging.

Jumper wires, 3 wires

Red for VCC to 5V, green for GND to GND, and orange for OUT to pin 3. That is the entire wiring for this project. Three wires, direct connection, no breadboard needed.

Laptop and USB cable

Powers the board and runs the Serial Monitor where all the motion timestamps and logs appear. Keep the Serial Monitor open the whole time the project is running so you can see the log building up in real time.

Fun fact: PIR sensors are inside almost every automatic light switch, security camera trigger, and burglar alarm you have ever encountered. The white dome shape is not decorative. It is a Fresnel lens that focuses infrared radiation from a wide area onto the tiny sensor underneath, giving it a much wider detection range than the sensor could achieve on its own.

How Do You Connect a PIR Sensor to Arduino? Step by Step Wiring Guide

Look at the circuit diagram image carefully before you start. The PIR sensor has three pins labelled GND, OUT, and VCC from top to bottom on the right side of the module.

Match each one to the correct Arduino pin using the table below.

From (PIR Sensor)

To (Arduino)

Wire Colour

In plain English

VCC

5V pin

Red

Powers the PIR sensor

GND

GND pin

Green

Completes the circuit

OUT

Pin D3

Orange

Sends motion signal to Arduino

LED (long leg)

Pin D13

Blue

Visual indicator, on when motion detected

LED (short leg)

GND

Blue

Negative leg of LED to ground

Before you power on. Make sure the PIR sensor dome is facing outward into the open room, not towards a wall. The sensor detects movement across its field of view, so it needs clear space in front of it. Once powered, do not move in front of it for 30 seconds while it calibrates.

Quick tip: The PIR sensor has two small orange dials on the back of the module. One adjusts sensitivity and the other adjusts the delay time after motion stops. Leave both in their default middle position for the first test. Once everything is working you can experiment with turning them to see what changes.

How Does a PIR Motion Recorder Work? The Science and Code Explained Simply

This is the most interesting section in the whole project because the code does something none of the previous projects did. It does not just react to a sensor. It keeps track of what happened and when. Here is how it all works.

The sensor needs 30 seconds to wake up

When you first power the Arduino, the setup() function runs a calibration loop for 30 seconds. During this time the PIR sensor is measuring the baseline infrared levels of the room. It prints a dot to the Serial Monitor every second so you know it is working. Once it finishes it prints SENSOR ACTIVE and the project is ready to use. This calibration is not optional. Skip it and the sensor will give false triggers for the first minute or two.

HIGH means someone is there

When the PIR sensor detects movement from a warm body, the OUT pin goes HIGH. The Arduino reads this on pin 3 and immediately turns the blue LED on. It also checks a flag called lockLow. If lockLow is true it means this is the start of a new motion event, so it prints motion detected at X sec using millis() divided by 1000 to get the time in seconds. Then it sets lockLow to false so the same event does not get logged again even if the sensor stays HIGH.

LOW means the person has gone

When the person moves away, the PIR OUT pin goes LOW and the LED turns off. The code notes the exact time this happened using lowIn. But it does not immediately log motion ended. It waits for 5000 milliseconds, which is 5 seconds, to make sure the motion is truly over and not just a brief gap between movements. This waiting period is controlled by the pause variable. After 5 seconds of continuous LOW, it prints motion ended at X sec and resets the flags ready for the next event.

The Serial Monitor becomes a movement log

Every time someone walks past the sensor, two lines get added to the Serial Monitor log. One for when the motion started and one for when it ended. Over time this builds up into a genuine record of all movement detected since the Arduino was powered on. You can use this log as evidence in your school project report.
Here is the complete code with comments explaining every important section.

cpp
int calibrationTime = 30;        
long unsigned int lowIn;         
long unsigned int pause = 5000;  
boolean lockLow = true;
boolean takeLowTime;  
int pirPin = 3;    
int ledPin = 13;

void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);
  Serial.print("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
    delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
}

void loop(){
  if(digitalRead(pirPin) == HIGH){
    digitalWrite(ledPin, HIGH);  
    if(lockLow){  
      lockLow = false;            
      Serial.println("---");
      Serial.print("motion detected at ");
      Serial.print(millis()/1000);
      Serial.println(" sec"); 
      delay(50);
    }         
    takeLowTime = true;
  }
  if(digitalRead(pirPin) == LOW){       
    digitalWrite(ledPin, LOW);  
    if(takeLowTime){
      lowIn = millis();          
      takeLowTime = false;       
    }
    if(!lockLow && millis() - lowIn > pause){  
      lockLow = true;                        
      Serial.print("motion ended at ");      
      Serial.print((millis() - pause)/1000);
      Serial.println(" sec");
      delay(50);
    }
  }
}

The millis() function is what makes this code special. Unlike delay() which stops the whole program, millis() just returns how many milliseconds have passed since the Arduino was switched on. The program keeps running while time is being tracked. That is a genuinely important concept in programming and this project makes it concrete and visible.

Think about this: The lockLow flag is a boolean, which means it can only be true or false. It acts like a door latch. Once motion starts and lockLow flips to false, no more motion detected messages can be logged until the motion fully ends and lockLow resets to true. This prevents the log from being spammed with hundreds of identical entries every second. It is simple, elegant, and used in real software systems every day.

How to Use This PIR Motion Recorder for a School Science Project or STEM Exhibition?

A security logger that prints timestamped movement records to a screen is one of the most impressive things you can bring to a school science fair. It looks professional, it is interactive, and it connects directly to real-world technology that everyone uses. Here is how to present it well.

Uploading the code and testing

Download Arduino IDE from arduino.cc. Paste in the code from Section 5. Connect the Arduino via USB, select Tools then Board then Arduino Uno and the correct COM port, and click upload. Open the Serial Monitor at 9600 baud immediately. You will see the calibration dots printing for 30 seconds. Do not move in front of the sensor during this time. When SENSOR ACTIVE appears, walk in front of the sensor and check that motion detected at X sec appears.

Running a live demo at your exhibition stall

Keep the Serial Monitor open on your laptop at the stall. Ask each visitor to walk past the sensor one at a time. Show them the timestamps printing as they walk in and as they stop moving. After a few visitors you will have a running log on screen with multiple motion events recorded. That live log building up in real time is what makes people stop and ask questions.

Writing your project report

This project gives you more to write about than almost any other in the series. Cover these points:

  • What a PIR sensor is and how it detects body heat rather than reflected light
  • What calibration is and why the sensor needs 30 seconds before it works
  • How millis() tracks time without freezing the program
  • How the lockLow flag prevents duplicate log entries
  • Your test results showing actual timestamps from a session of testing
  • Real-world applications including security systems, automatic lights, and visitor counters

5 Ways to Take This PIR Motion Recorder Project Further

  1. Add a buzzer that beeps once when motion starts and twice when it ends for an audio alarm
  2. Add a counter variable that increments each time a new motion event starts and displays the total number of movements detected
  3. Connect an LCD screen that shows the last motion timestamp so you do not need the laptop open
  4. Add a second PIR sensor on a different pin to cover two rooms or entry points simultaneously
  5. Save the motion log to an SD card module so the data is stored permanently even after the Arduino is powered off

From CYFI: If your child can explain what millis() does, why calibration matters, and what lockLow prevents, they are demonstrating knowledge that goes well beyond a typical school electronics project. Those three concepts together cover real-time programming, sensor physics, and software logic. That is an impressive combination at any age.

Frequently Asked Questions About the PIR Motion Recorder Arduino Project

Why does the sensor give false triggers right after I power it on?

The PIR sensor needs 30 seconds to calibrate and learn the baseline infrared levels of the room. Any movement or heat changes during this period will cause false triggers. Wait for SENSOR ACTIVE to appear on the Serial Monitor before testing.

Why does motion ended print 5 seconds after I stop moving?

This is intentional. The pause variable is set to 5000 milliseconds which is 5 seconds. The code waits this long after the sensor goes LOW before logging the end of a motion event. This prevents a slow-moving person being logged as multiple separate events. You can change 5000 to a smaller number if you want faster response.

What is the difference between a PIR sensor and the IR sensor in the previous project?

The IR sensor detects objects by bouncing infrared light off them and works best at close range of 2 to 30 centimetres. The PIR sensor detects the infrared heat naturally emitted by warm-blooded bodies and can detect movement from several metres away. They both use infrared but for completely different purposes.

Can the PIR sensor detect animals as well as people?

Yes. The PIR sensor detects any warm-blooded creature that moves through its field of view including pets and birds. If you are using this as a people-only counter you will need to think about how to position the sensor to avoid picking up animals.

Is this project suitable for a school science fair?

It is one of the strongest projects in the CYFI series for a science fair because it produces a live data log that visitors can see building up in real time. The combination of timestamped motion records, a working LED indicator, and the connection to real security technology makes it stand out from projects that just light up an LED.

Back to blog

Leave a comment