Sensor

๐Ÿ‘ค PIR Human Body Sensor

๐Ÿ“Œ Description

A PIR (Passive Infrared) sensor detects movement from people or animals by sensing changes in infrared radiation (heat). When someone passes in front of it, the sensor notices the change and sends a signal.

๐ŸŽฏ Use

In our projects, PIR sensors are used to:

  • Detect when a person enters a room.
  • Trigger lights or alarms when movement is detected.
  • Make robots react to human presence.

๐Ÿ‘‰ Think of the PIR sensor as the robotโ€™s motion detector โ€” it wakes up when someone moves nearby.

ย Module parameters

Pin name Description
G GND (Power Input Negative)
V VCC (Power Input Cathode)
S Digital signal pins
  • Supply voltage: 3.3V/5V
  • Connection: PH2.0 terminal wire
  • Installation method: double screw fixing

๐Ÿ–ฅ๏ธ Code Explanation

import machine

pin25 = machine.Pin(25, machine.Pin.IN)    # PIR sensor input
pin26 = machine.Pin(26, machine.Pin.OUT)   # LED output

while True:
    if pin25.value() == 1:                 # If motion is detected
        pin26.value(1)                     # Turn LED ON
    else:
        pin26.value(0)                     # Turn LED OFF

Step by Step

  1. import machine โ†’ Tools to control pins.
  2. pin25 = machine.Pin(25, machine.Pin.IN) โ†’ Pin 25 reads the PIR sensorโ€™s signal (input).
  3. pin26 = machine.Pin(26, machine.Pin.OUT) โ†’ Pin 26 controls the LED (output).
  4. while True: โ†’ Loop that repeats forever.
  5. if pin25.value() == 1: โ†’ Checks if the sensor detects movement.
  6. pin26.value(1) โ†’ Turns the LED on when motion is detected.
  7. else: โ†’ If no movementโ€ฆ
  8. pin26.value(0) โ†’ Turns the LED off.

๐Ÿ‘‰ Together, this program makes the LED light up when the sensor detects motion.


โœ… Conclusion of the Test

  • If the LED turns on when someone moves in front of the sensor, the program is working correctly.
  • This test shows how the robot can sense human presence and react with an output (LED).
  • Later, instead of just turning on a light, the PIR sensor could trigger alarms, start motors, or activate other modules when motion is detected.
On this page