A Mini PIR (passive infrared) motion sensor detects changes in infrared radiation caused by nearby movement. It is powered from VCC (2.7V to 12V) with GND connected to system ground, and provides a single OUT signal line (about 3V level) that you can read as a digital input on Arduino/ESP32.
| Pin | Signal | Description |
|---|---|---|
VCC |
2.7V - 12V power | |
OUT |
3V signal | |
GND |
ground |
| From | To | Wire |
|---|---|---|
board:5V |
x1:VCC |
red |
board:GND |
x1:GND |
black |
board:D2 |
x1:OUT |
green |
This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.
const int pirPin = 2;
void setup() {
pinMode(pirPin, INPUT);
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Mini PIR sensor example");
Serial.println("Warming up the PIR sensor for calibration...");
delay(30000);
Serial.println("Ready. Move in front of the sensor.");
}
void loop() {
int motionState = digitalRead(pirPin);
if (motionState == HIGH) {
Serial.println("Motion detected");
} else {
Serial.println("No motion");
}
delay(500);
}
Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.
Start for free