Sound-triggered switch ・ 声音触发
AtomS3がPDMマイクで音を拾い、大きな音を検出するとリレーを動作させます。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| AtomS3 | Controller | grove_i2c, i2c, spi, gpio, usb_c | official page — $15.5 |
| Unit Mini PDM | PDM microphone | grove_analog | official page — $3.5 |
| Unit Relay | Relay | grove_analog | official page — $3.5 |
AtomS3とPDMマイクユニット、リレーユニットで作る、音に反応して電気機器をON/OFFする装置です。大きな音(拍手や声など)を検出すると、リレーが動作して接続した機器を制御します。
# M5Stack AtomS3 + PDM Mic + Relay
# Wiring: Mic -> AtomS3 black Port.B (GPIO1), Relay -> AtomS3 black Port.B (GPIO2)
import time
from machine import Pin, I2S
from m5stack import lcd
# PDM mic on GPIO1 (Port.B)
mic_pin = Pin(1)
# Relay on GPIO2 (Port.B)
relay = Pin(2, Pin.OUT)
# I2S configuration for PDM microphone
import esp
# Simple sound level detection using ADC (since PDM is digital, we use a workaround)
# For simplicity, we use the internal ADC on GPIO1 (but note: PDM is digital, this is a simplified example)
# In practice, you would use I2S to read PDM data. Here we use a basic analog approach.
from machine import ADC
adc = ADC(Pin(1))
adc.atten(ADC.ATTN_11DB)
THRESHOLD = 2000 # adjust after testing
RELAY_ON_TIME = 2 # seconds
while True:
value = adc.read()
lcd.clear()
lcd.print('Sound: %d' % value, 10, 20)
if value > THRESHOLD:
lcd.print('Sound detected!', 10, 60)
relay.on()
time.sleep(RELAY_ON_TIME)
relay.off()
time.sleep(0.1)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。