CYTHEIA AIOpen the editor

PIR Motion Detector

Light an LED whenever motion is detected.

Open this circuit and run it

Opens in your browser with the parts, wiring and code already in place. Press Run to watch it work, then change anything you like.

How it works

A PIR (passive infrared) sensor detects the heat given off by moving people and animals. Its output goes high while it senses motion and low when the scene is still. Here the output is wired to pin 7, and an LED with a resistor sits on pin 13.

loop() reads pin 7 twice a second. High means motion: the LED switches on and “Motion detected” is printed. Low switches the LED off and prints “No motion”. Select the sensor in the editor and toggle its motion to try both cases. Real PIR sensors usually hold their output high for a few seconds after movement, and need about a minute to settle after power-up.

Parts

Wiring

Arduino code

// PIR Motion Detector
void setup() {
  pinMode(7, INPUT);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int motion = digitalRead(7);
  if (motion == HIGH) {
    digitalWrite(13, HIGH);
    Serial.println("Motion detected");
  } else {
    digitalWrite(13, LOW);
    Serial.println("No motion");
  }
  delay(500);
}

Try changing it

Open this circuit and run it

Next challenge

More projects in Sensors