TINKER PiEDESIGN IN INDIA

Motion alarm with a PIR sensorTinkerPieCircuit tutorial 22 of 24 · Intermediate · 20 minutes

Sound an alarm and flash an LED when a PIR sensor sees movement.

Open this circuit in TinkerPieCircuit (free, runs in your browser)

What you will learn

Parts

TinkerPie V1 board1 PIR motion sensor1 LED1 resistor, 220 Ω

Steps

  1. Wire the PIR

    VCC → 3V3, GND → GND, OUT → P10.

  2. Wire the LED

    S1 → resistor → LED (+), LED (−) → GND.

  3. Read it

    A PIR sensor gives HIGH while it sees motion.

  4. Make a siren

    Switch between 1200 Hz and 800 Hz with tone() and short delays.

  5. Test

    Press ▶ Start and click the MOTION switch on the sensor.

The code

function setup() {
  pinMode(P10, INPUT);
  pinMode(S1, OUTPUT);
}

function loop() {
  if (digitalRead(P10) == HIGH) {
    digitalWrite(S1, HIGH);
    tone(BUZZER, 1200);
    delay(150);
    tone(BUZZER, 800);
    delay(150);
  } else {
    digitalWrite(S1, LOW);
    noTone(BUZZER);
  }
  delay(20);
}

Copy this into the Code tab. It is Arduino-style JavaScript. The real board uses the same pin names (S1, P10…) in TinkerPie Studio.

How it works

A PIR (passive infrared) sensor notices changes in heat from a moving person or animal. It does not send anything out, which is why it is called passive.

Challenge: Keep the alarm going for 5 seconds after the last movement.

← Automatic door with IR and a servo · All 24 circuit tutorials · Thermometer and fever light →