Mailbox notifier ・ 信箱通知
PIR人感センサーで郵便物の投函を検知し、Core2の画面とWi-Fiで通知します。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack Core2 | Controller | grove_i2c, grove_analog, grove_uart, mbus | official page — $46.9 |
| M5Stack Unit PIR | Motion sensor | grove_i2c | official page — $5.5 |
M5Stack Core2とPIRユニットで作る、郵便受けの投函お知らせ装置です。PIRセンサーが人の動き(郵便配達)を検知すると、Core2の画面にメッセージを表示し、Wi-Fi経由で通知を送ります。
# M5Stack Core2 + PIR Unit (mailbox notification)
# Wiring: PIR Unit -> Core2 red Port.A (I2C)
import time
import network
import urequests
from machine import Pin, I2C
from m5stack import lcd
# Wi-Fi settings (change to your network)
SSID = "your_SSID"
PASSWORD = "your_PASSWORD"
# IFTTT Webhook URL (optional, for push notification)
WEBHOOK_URL = "https://maker.ifttt.com/trigger/mail_delivered/with/key/YOUR_KEY"
# PIR sensor I2C address (default 0x64)
PIR_ADDR = 0x64
# Initialize I2C on Port.A (Core2: sda=21, scl=22)
i2c = I2C(0, sda=Pin(21), scl=Pin(22), freq=100000)
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
lcd.print('Connecting to WiFi...', 10, 20)
wlan.connect(SSID, PASSWORD)
timeout = 10
while not wlan.isconnected() and timeout > 0:
time.sleep(1)
timeout -= 1
if wlan.isconnected():
lcd.print('WiFi connected', 10, 40)
else:
lcd.print('WiFi failed', 10, 40)
def read_pir():
# Read PIR status from I2C register 0x01
try:
data = i2c.readfrom_mem(PIR_ADDR, 0x01, 1)
return data[0] & 0x01
except:
return 0
def send_notification():
try:
response = urequests.post(WEBHOOK_URL)
response.close()
except:
pass
# Main
connect_wifi()
lcd.clear()
lcd.print('Mailbox Monitor', 10, 60)
last_state = 0
while True:
current = read_pir()
if current == 1 and last_state == 0:
lcd.clear()
lcd.print('Mail delivered!', 10, 20)
send_notification()
time.sleep(5)
lcd.clear()
lcd.print('Mailbox Monitor', 10, 60)
last_state = current
time.sleep(0.5)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。