Control an LED with a PIR Motion Sensor on Raspberry Pi
This guide demonstrates how to use Raspberry Pi hardware to read a Passive Infrared (PIR) motion sensor and control an external LED. The example is built within Simulink®, enabling you to create and run models directly on the Pi.
Introduction
The Raspberry Pi target for Simulink® provides a library of blocks that configure and access Pi peripherals. In this example, you’ll learn how to read motion events from a PIR sensor and trigger an LED in response.
Prerequisites
- Complete the “Getting Started with Raspberry Pi® Hardware” tutorial first.
Required Hardware
- Raspberry Pi board
- Parallax PIR motion sensor
- 1.8 mm red LED
- 270 Ω resistor
- Optional: Breadboard and jumper wires (recommended)
- Optional: Speakers or headphones (Task 3)
- Optional: USB webcam (Task 4)
Task 1 – Wiring the PIR Sensor and LED
The PIR sensor has three pins: VCC, GND, and OUT. Connect VCC to the 3.3 V rail, GND to ground, and OUT to a GPIO pin on the Pi. The LED circuit is connected to the same GPIO pin. Because the Pi’s GPIO operates at 3.3 V, use a 1.8 V red LED and a 270 Ω resistor to limit current.
- Wire the PIR sensor as shown in the schematic.
- Connect the red LED and resistor to the indicated GPIO pin.
Note: If a PIR sensor is unavailable, a momentary push‑button can substitute the OUT pin for testing.
For more detail: Motion Sensor
Manufacturing process
- TMP006 Infrared Temperature Sensor with Raspberry Pi: Python Library & Setup Guide
- Build a Remote Temperature Sensor with Raspberry Pi and Python – Step‑by‑Step Guide
- Secure Home Monitoring with Home Assistant on Raspberry Pi: Motion, Alarm, and Video Capture
- Build a DIY Infrared Motion Sensor for Raspberry Pi – Step‑by‑Step Guide
- Build a Low‑Cost Raspberry Pi Soil Moisture Sensor for Smart Irrigation
- Build a Raspberry Pi Home Temperature Monitor with MCP9808, InfluxDB & Grafana
- Master Raspberry Pi GPIO: Interfacing a PIR Motion Sensor on B+/Model 2
- Integrating the Acconeer A111 Pulsed Radar with a Raspberry Pi: A Practical Guide
- How to Connect, Calibrate, and Program the HC‑SR501 PIR Motion Sensor with a Raspberry Pi
- Infrared Eye‑Motion Tracking with Arduino Pro Mini – LED Control Demo