Skip to main content

14. PIR Motion Sensor

The AM312 PIR (Passive Infrared) motion sensor is a compact and efficient module used to detect motion in a specific area. It operates by sensing infrared radiation emitted by moving objects, typically humans or animals, making it ideal for a wide range of applications, including security systems, automated lighting, and presence detection.

Materials

ComponentImage
Breadboard
Jumper wires
Arduino Uno R4 Minima
LED (white, red, blue, or green)
AM312 PIR Motion Sensor

Instructions

  1. Make the following connections using the breadboard and jumper wires.

Connections

  • Gnd to GND
  • Signal to pin 2
  • Vcc to 3.3V
  1. Paste the following code into your main Arduino sketch:

Code

int ledPin = 13;  // LED on Pin 13 of Arduino
int pirPin = 2; // Input for AM312 motion sensor

int pirValue; // Place to store read PIR Value

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
digitalWrite(ledPin, LOW);
delay(10000); // 10 second delay after powering on
}

void loop() {
pirValue = digitalRead(pirPin);
// Serial.println(pirValue); // You can print out the pirValue to ensure its working properly. 0 = no movement, 1 = movement detected
digitalWrite(ledPin, !pirValue);
delay(1000); // add a short delay to avoid reading the sensor too quickly
}
  1. Connect your Arduino to your laptop using a USB-C cable and upload the code to the arduino.

  2. Test! Move your hands around the sensor and observe the LED turns on.

PrevNext
13. GY-521 Module15. Water Level Detection Sensor