Smart doorbell notifier ・ 门铃通知
PIRセンサーで来客を検知し、ブザーを鳴らしてスマホに通知します。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack Core2 | Controller with Wi-Fi | grove_i2c, grove_analog, grove_uart, mbus | official page — $46.9 |
| M5Stack Unit PIR | Motion sensor (PIR) | grove_i2c | official page — $5.5 |
| Unit Buzzer | Buzzer | grove_analog | official page — $4.5 |
M5Stack Core2とPIRユニット、ブザーユニットで作る、来訪者を検知してスマートフォンに通知を送るスマートドアベルです。PIRセンサーが人の動きを検知するとブザーが鳴り、Wi-Fi経由でスマホにプッシュ通知が届きます。
# M5Stack Core2 + PIR Unit + Buzzer Unit - Smart Doorbell
# Wiring: PIR Unit -> Core2 red Port.A (I2C)
# Buzzer Unit -> Core2 black Port.B (analog/GPIO)
import time
import network
import urequests
from machine import Pin, PWM
from m5stack import lcd
# Wi-Fi settings
SSID = 'your_SSID'
PASSWORD = 'your_PASSWORD'
# Webhook URL for push notification (e.g., IFTTT, Pushbullet)
WEBHOOK_URL = 'https://maker.ifttt.com/trigger/doorbell/with/key/YOUR_KEY'
# PIR I2C address (default 0x64)
PIR_ADDR = 0x64
# Buzzer on Port.B -> GPIO 36 (analog input) but we use PWM on GPIO 26? Actually Port.B on Core2 uses GPIO 36 for analog input and GPIO 26 for digital output.
# For buzzer, we need PWM output. Use GPIO 26 (Port.B digital pin).
buzzer = PWM(Pin(26), freq=4000, duty=512) # 4kHz, 50% duty
# I2C for PIR
from machine import I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000) # Port.A I2C pins
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)
while not wlan.isconnected():
time.sleep(1)
lcd.clear()
lcd.print('WiFi connected', 10, 20)
lcd.print(wlan.ifconfig()[0], 10, 50)
def send_notification():
try:
response = urequests.post(WEBHOOK_URL, json={'value1': 'Doorbell'})
response.close()
except Exception as e:
lcd.print('Notification failed', 10, 110)
def read_pir():
# Read PIR status from I2C register 0x01 (motion flag)
try:
data = i2c.readfrom_mem(PIR_ADDR, 0x01, 1)
return data[0] & 0x01
except:
return 0
# Main
connect_wifi()
last_motion = False
while True:
motion = read_pir()
if motion and not last_motion:
lcd.clear()
lcd.print('Motion detected!', 10, 20)
buzzer.duty(512) # turn on buzzer
time.sleep(1)
buzzer.duty(0) # turn off buzzer
send_notification()
last_motion = motion
time.sleep(0.5)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。