What you're actually building
A motion detector with Arduino is a circuit that uses a sensor to notice when something moves, then tells your Arduino board to do something in response — turn on a light, send you a message, trigger an alarm, or log the time. The Arduino is the small computer that makes decisions. The sensor (usually a passive infrared sensor, or PIR) detects heat from moving objects. You wire them together, write a short program, and the Arduino watches the sensor and acts when motion appears.
This is different from a security system's motion detector, which is a finished product you buy and install. What you're building here is the thinking part — you decide what happens when motion is detected, and you can change it whenever you want by rewriting the program.
Key Takeaways
- A PIR sensor detects infrared heat from moving people or animals, and the Arduino reads that signal and responds according to your program.
- You need an Arduino board (the Uno is cheapest and most common), a PIR sensor module, jumper wires, and a power source — total cost is usually under $30.
- Wiring takes five minutes: power and ground from the Arduino to the sensor, and one signal wire from the sensor to a digital input pin on the Arduino.
- The program is straightforward — it reads the sensor pin constantly and triggers an action (like lighting an LED) when motion is detected.
- PIR sensors need 30 to 60 seconds to stabilize when first powered on, so your detector won't work when ready after you plug it in.
The parts you need and what they cost
An Arduino Uno is the standard board for beginners. It's a small circuit board with a processor, memory, and pins you connect wires to. You can buy one for $20 to $30 from electronics retailers like Adafruit, SparkFun, or Amazon. Cheaper clones exist but often have reliability issues.
A PIR motion sensor module costs $5 to $15. The module is a small board with the actual sensor already mounted and ready to use — much easier than buying the raw sensor. Look for one labeled "HC-SR501" or similar; they're all very similar and work the same way.
You'll need jumper wires (about $5 for a pack of 40) to connect everything. You also need a way to power the Arduino — either a USB cable connected to a computer or a separate power adapter (9 to 12 volts). If you want to see the motion detector do something visible, add an LED ($1) and a resistor ($1). Total for a working system: $30 to $50.
Wiring the sensor to the Arduino
The PIR sensor module has three pins: power (labeled VCC), ground (GND), and signal (OUT). The Arduino Uno has power pins, ground pins, and digital input pins along its edges.
Connect the sensor's VCC pin to the Arduino's 5V power pin using a jumper wire. Connect the sensor's GND pin to any Arduino GND pin. Connect the sensor's OUT pin to a digital input pin on the Arduino — pin 2 or pin 3 are common choices. That's it. The sensor now has power and can send a signal to the Arduino.
If you're adding an LED to see when motion is detected, connect the LED's positive leg (the longer one) through a 220-ohm resistor to a digital output pin like pin 13, and connect the LED's negative leg to ground. The resistor protects the LED from burning out.
Writing and uploading the program
You write the program on your computer using the Arduino IDE (Integrated Development Environment), which is free software you read from arduino.cc. Plug your Arduino into your computer with a USB cable, open the IDE, and paste this basic program:
int sensorPin = 2; int ledPin = 13; void setup() { pinMode(sensorPin, INPUT); pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { int motion = digitalRead(sensorPin); if (motion == HIGH) { digitalWrite(ledPin, HIGH); Serial.println("Motion detected!"); } else { digitalWrite(ledPin, LOW); } }
This program tells the Arduino to read pin 2 (where the sensor is connected) constantly. When the sensor detects motion, it sends a HIGH signal, and the Arduino turns on the LED on pin 13 and prints "Motion detected!" to the computer. When motion stops, the LED turns off.
In the IDE, click the upload button (the arrow icon). The software compiles your program and sends it to the Arduino. You'll see a progress bar. Once it finishes, your motion detector is running.
Why your detector might not work at first
PIR sensors need time to adjust to the room's temperature when you first power them on. For the first 30 to 60 seconds, they're calibrating and will give false readings. Wait a minute before testing.
If the sensor never detects motion, check that the wires are firmly connected and that you used the correct pin numbers in your program. If the sensor detects motion constantly (the LED stays on), it may be too close to a heat source like a radiator or sunlight. Move it away or adjust the sensor's sensitivity dial if it has one.
If the program won't upload, make sure you selected the correct board type (Arduino Uno) and the correct COM port in the IDE's Tools menu. The port is where your USB cable connects.
What you can do next
Once the basic detector works, you can modify the program to do more. Add a delay so the LED stays on for a few seconds even after motion stops. Add a buzzer that beeps when motion is detected. Log the time of each motion event to track when activity happens. Connect the Arduino to the internet using a WiFi shield and send yourself a notification when motion is detected.
You can also experiment with the sensor itself. Most PIR modules have two adjustment dials — one for sensitivity and one for the time the output stays HIGH after motion is detected. Turning the sensitivity dial down makes it less likely to trigger on small movements. Turning the time dial up makes the LED stay on longer after motion stops.
Frequently Asked Questions
Can I use a different type of sensor instead of PIR?
Yes. An ultrasonic sensor detects objects by bouncing sound waves, and an infrared distance sensor detects how close something is. Both work with Arduino the same way — they send a signal to a pin, and your program reads it. PIR is cheapest and most common for motion detection because it uses very little power and doesn't need adjustment.
How far away can the sensor detect motion?
Most PIR modules detect motion up to 20 to 25 feet away, but the range depends on the room temperature, the size of the moving object, and the sensor's sensitivity setting. A person walking across a room will trigger it reliably. A small animal or a hand moving slowly might not.
Can I power the Arduino with batteries instead of USB?
Yes. Connect a 9-volt battery to the power jack on the Arduino (or solder wires directly to the Vin and GND pins). The Arduino will run until the battery dies. For a motion detector that runs all the time, a USB power adapter plugged into an outlet is more practical than replacing batteries constantly.
What happens if I connect the wires wrong?
If you swap power and ground, you'll likely damage the sensor or the Arduino. If you connect the signal wire to the wrong pin, the program won't see the motion because it's reading a different pin. Always double-check the three connections before powering on.
Can I make the detector send me a text message when motion is detected?
Yes, but it requires extra hardware. You need a WiFi shield or a cellular module that connects to the Arduino, plus a service like IFTTT or Twilio that can send messages. The basic motion detection part stays the same — the Arduino just sends the signal to the internet instead of (or in addition to) turning on an LED.