Motion sensor notifier

人感センサー通知 ・ 人体感应通知

Detect motion with a PIR sensor on a tiny AtomS3 controller.

人や動物の動きを検知。小型のAtomS3で省スペース。畑の獣害チェックにも。

用 PIR 传感器检测人或动物的移动,小巧的 AtomS3 省空间,也可用于田间防兽害。

Parts (BOM)

PartRolePortsLinks
AtomS3 Controller (compact) grove_i2c, i2c, spi, gpio, usb_c official page
M5Stack Unit PIR Motion sensor grove_i2c official page

Wiring

How to build

Build a tiny motion alarm for your garden or doorway. An M5Stack AtomS3 watches the PIR (motion) sensor and, whenever something moves nearby, lights up its screen red and prints an alert. Great for spotting animals visiting your plants or knowing when someone walks past. No soldering and no engineering knowledge needed - just two parts and one Grove cable.

  1. Unbox and check parts — Lay out the two parts: the AtomS3 controller (the small cube with a screen) and the Unit PIR motion sensor. You also need the white 4-pin Grove cable that came with the PIR, and a USB-C cable to connect the AtomS3 to your computer.
  2. Connect the PIR with the Grove cable — Plug one end of the Grove cable into the PIR sensor and the other end into the Grove port on the bottom of the AtomS3. The connector only fits one way, so push gently until it clicks. The AtomS3's Grove port is its I2C/digital port - the right home for this sensor.
  3. Plug AtomS3 into your computer — Connect the AtomS3 to your computer with the USB-C cable. The screen should light up, showing it has power. If nothing happens, try a different USB cable - some cables only carry power and not data.
  4. Install MicroPython firmware — The easiest path: open the M5Burner app (free from m5stack.com), find the UIFlow2 / MicroPython firmware for AtomS3, and click Burn to flash it. Pick the COM port that appears when the AtomS3 is plugged in. This only needs to be done once.
  5. Load the alert program — Open Thonny (a free, beginner-friendly editor), select the AtomS3 as the connected device, paste the code below, and save it onto the board as main.py. Saving as main.py makes it run automatically every time the AtomS3 powers on.
  6. Test it — Wave your hand in front of the PIR sensor. Within a second the screen should turn red and show 'MOTION'. When you stay still, it returns to a calm green 'Watching' screen. Note: PIR sensors need about 30-60 seconds to settle after power-on, so give it a moment before trusting the first readings.

Sample code (micropython)

# Motion alert for M5Stack AtomS3 + Unit PIR
# PIR signal arrives on the Grove port. On AtomS3 that pin is GPIO 8.
from machine import Pin
import time

try:
    import M5
    from M5 import Lcd
    M5.begin()
    HAS_SCREEN = True
except Exception:
    HAS_SCREEN = False  # still works without the screen lib

# PIR output: HIGH (1) when motion is detected, LOW (0) when quiet
pir = Pin(8, Pin.IN)

def show(text, color):
    if HAS_SCREEN:
        Lcd.clear(color)
        Lcd.setCursor(10, 50)
        Lcd.setTextColor(0xFFFFFF, color)
        Lcd.print(text)
    print(text)

show("Watching", 0x00AA00)  # calm green = no motion
last = 0
while True:
    moved = pir.value()
    if moved != last:        # only redraw when state changes
        if moved:
            show("MOTION", 0xFF0000)   # red = motion!
        else:
            show("Watching", 0x00AA00)
        last = moved
    time.sleep(0.1)

Tips & safety

Open the interactive diagram →

UnitKit — describe what you want to build, get a parts list and wiring diagram.