PIR Arduino wiring illustration; consult pin connection table for verified wiring

Want to try a small electronics project without complicated circuits? In this beginner tutorial, we’ll build detect motion using arduino and pir sensor. You’ll connect one sensor, upload a short Arduino IDE sketch, and see the result. No Wi-Fi account or cloud service is required.

Wiring illustration for Arduino PIR; use the wiring table for verified connections

What does it do?

A passive infrared (PIR) sensor responds to changes in infrared radiation. When it detects movement, its output goes HIGH and Arduino turns on an LED.

Parts you’ll need

Arduino Uno, HC-SR501 PIR motion sensor, LED, 220-ohm resistor, jumper wires. You will also need a computer with the free Arduino IDE installed.

Wiring connections

Disconnect USB power before moving any wires. Make these connections carefully:

Sensor / component pinConnect to
PIR VCC5V
PIR GNDGND
PIR OUTD2
D8220-ohm resistor → LED anode
LED cathodeGND

Important: ESP32 GPIO pins work at 3.3V. Do not connect a 5V output directly to an ESP32 input. Board and sensor-module pin labels vary, so double-check the markings on your hardware.

Arduino IDE code

Select the correct board and USB port in Arduino IDE, paste the complete sketch below, and click Upload.

const int pirPin = 2;
const int ledPin = 8;
void setup() {
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.println("Allow PIR sensor to stabilize...");
  delay(30000);
}
void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  digitalWrite(ledPin, motion ? HIGH : LOW);
  Serial.println(motion ? "Motion detected" : "No motion");
  delay(300);
}

Expected result

Move in front of the sensor: Motion detected appears and the LED turns on. Open Tools → Serial Monitor and set the baud rate shown in Serial.begin() in the sketch.

Troubleshooting

Most HC-SR501 modules need about 30–60 seconds to settle after power-up. Adjust the module’s sensitivity and delay controls if needed.

If nothing appears, first check the USB cable, correct board and port, sensor power and ground, and the Serial Monitor baud rate. Recheck every wire against the connection table before changing code.

What to try next

Once this simple example works, try changing the measurement interval or using the sensor reading to control an LED. This is an easy way to learn inputs, outputs, and basic programming.

For more hands-on electronics tutorials, explore CircuitMagic. If you later want to control Arduino or ESP32 projects from a phone over Bluetooth, see our BLE Controller app tutorial. This project itself does not need Bluetooth.

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

or

Log in with your credentials

Forgot your details?