PIR Sensor
Overview
Based on pyroelectric infrared sensor, it can detect infrared rays emitted by human or animal bodies and output electrical signals.
Technical Specifications
Operating voltage: VCC 3.3V -5V
Module dimensions: 24*48mm
Mounting: 2 plastic building block compatible through-holes
Data type: Triggered–1 Not triggered–0
Pin Definition
Pin |
Definition |
|---|---|
GND |
Ground |
VCC |
Power |
DO |
Digital output |
NC |
Not connected |
Example Code
When someone approaches and triggers the PIR sensor, the mPython Board RGB LED lights up.
from mpython import *
p0 = MPythonPin(0, PinMode.IN)
import time
def boolean_P0():
return p0.read_digital() == 1
while True:
if boolean_P0():
rgb.fill((int(255), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
time.sleep(1)
else:
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)