3.3V to 5V
3.3V to 5V
1mA (typical)
Up to 3 meters
120
Adjustable via potentiometer
Digital (HIGH/LOW)
-20C to 80C
25mm x 25mm
Applications
| The M5 Stack PIR Motion Unit (AS312) is suitable for a wide range of IoT applications, including |
Home automation systems
Security systems
Smart lighting control
Occupancy detection
Smart sensing devices
Resources
For more information and resources related to the M5 Stack PIR Motion Unit (AS312), including datasheets, user manuals, and sample codes, please refer to the M5Stack official documentation and community resources.
M5 Stack PIR Motion Unit (AS312) DocumentationOverviewThe M5 Stack PIR Motion Unit (AS312) is a Passive Infrared (PIR) motion sensor module designed for use with the M5 Stack ecosystem. This module is based on the AS312 PIR sensor, which detects changes in infrared radiation levels caused by movement within its detection range. The module is compact, low-power, and easy to use, making it suitable for various IoT and automation applications.Hardware SpecificationsPIR Sensor: AS312
Detection Range: Up to 3 meters
Sensitivity: Adjustable
Power Supply: 3.3V to 5V
Communication Interface: I2C
Dimensions: 24 x 24 x 10 mmPinoutsGND: Ground
VCC: Power Supply (3.3V to 5V)
SCL: I2C Clock
SDA: I2C Data
OUT: Motion Detection OutputSoftware RequirementsM5 Stack Core/ATOM/CORE2 boards
UIFlow or MicroPython firmwareExample Code 1: Basic Motion Detection using UIFlowThis example demonstrates how to use the M5 Stack PIR Motion Unit (AS312) with the UIFlow firmware to detect motion and trigger an event.```blocks
from m5stack import
from m5stack_ui importpowerOn()# Initialize PIR Motion Unit
pir = unit.get(unit.AS312, unit.PORTA)# Create a label for the motion detection status
label0 = M5TextBox(0, 10, "Motion:", lcd.FONT_Default, 0x000000)while True:
# Read motion detection output
motion_detected = pir.get()if motion_detected:
label0.setText("Motion: DETECTED!")
else:
label0.setText("Motion: NOT DETECTED")wait(0.1)
```Example Code 2: Motion-Controlled LED using MicroPythonThis example shows how to use the M5 Stack PIR Motion Unit (AS312) with MicroPython to control an LED based on motion detection.```python
import machine
import time# Initialize PIR Motion Unit
pir = machine.I2C(0, freq=400000)
pir.init(machine.Pin(26), machine.Pin(25))# Initialize LED
led = machine.Pin(2, machine.Pin.OUT)while True:
# Read motion detection output
motion_detected = pir.read_u8(0x00)if motion_detected:
led.value(1) # Turn on LED when motion is detected
else:
led.value(0) # Turn off LED when no motion is detectedtime.sleep(0.1)
```Additional resourcesUIFlow documentation: <https://docs.m5stack.com/en/uiflow/>
MicroPython documentation: <https://docs.micropython.org/en/latest/>
M5 Stack API documentation: <https://docs.m5stack.com/en/api/>