Motion sensor alarm ・ 人体感应报警
PIRセンサーで人の動きを検知し、ブザーで警報、画面表示、Wi-Fi通知を行います。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack Core2 | Controller with screen | grove_i2c, grove_analog, grove_uart, mbus | official page — $46.9 |
| M5Stack Unit PIR | PIR motion sensor | grove_i2c | official page — $5.5 |
| Unit Buzzer | Buzzer alarm | grove_analog | official page — $4.5 |
M5Stack Core2とPIRユニット、ブザーユニットで作る、動体検知アラーム&通知装置です。PIRセンサーが人の動きを検知すると、ブザーが鳴り、Core2の画面にステータスを表示し、Wi-Fi経由で通知を送信します。
# M5Stack Core2 + PIR Unit (I2C) + Buzzer Unit (Port.B)
# Wiring: PIR Unit -> Core2 red Port.A (I2C)
# Buzzer Unit -> Core2 black Port.B (analog/GPIO)
import time
from machine import Pin, I2C
from m5stack import lcd
# I2C for PIR (Port.A)
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000)
PIR_ADDR = 0x64 # typical PIR unit I2C address
# Buzzer on Port.B (GPIO 36 is analog input, but we use a digital output pin)
# Port.B uses GPIO 36 (input only) and GPIO 26 (output). We'll use GPIO 26.
buzzer = Pin(26, Pin.OUT)
# PIR register to read motion status (0x01 = status register)
PIR_STATUS_REG = 0x01
def read_pir():
try:
data = i2c.readfrom_mem(PIR_ADDR, PIR_STATUS_REG, 1)
return data[0] & 0x01 # bit 0 indicates motion
except:
return 0
while True:
motion = read_pir()
lcd.clear()
if motion:
lcd.print('Motion Detected!', 10, 20)
buzzer.on()
time.sleep(0.5)
buzzer.off()
else:
lcd.print('No Motion', 10, 20)
time.sleep(1)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。