An open API service indexing awesome lists of open source software.

https://github.com/andrewl/motion-detector

Motion detection and Slack notification for Arduino/ESP8266
https://github.com/andrewl/motion-detector

arduino esp8266 iot motion-detection slack

Last synced: 2 months ago
JSON representation

Motion detection and Slack notification for Arduino/ESP8266

Awesome Lists containing this project

README

          

Motion Sensor to Slack Notification
==

What is this?
--
This shows you how to hook up some low-cost hardware to periodically send a message to Slack if motion was detected recently.

Why?
--
We have an elderly relative who recently had a fall necessitating hospital treatment. This is a simple solution to help assure us that they're still moving around - but without being as intrusive as a camera might be.

Couldn't you buy something to do this?
--
I did. A D-Link or TP-Link something or other with [IFTTT](https://www.ifttt.com) integration through the vendors app.

But the manufacturer withdrew support after 18 months though and now it's just more [e-waste](https://en.wikipedia.org/wiki/Electronic_waste)

OK, How do I build one?
--
*Hardware*

You'll need

- a [Wemos D1](https://www.wemos.cc/en/latest/d1/d1_mini_lite.html) or similar board (there are plenty of clones available)
- a PIR sensor, such as https://shop.rasp.io/products/pir-motion-sensor-2

It's a really simple build, you don't even need a breadboard or resistors.

1. Attach the PIR sensor to the board as per the schematic below.. You just need to connect the 5v, ground and a digital pin that has no internal pull-up (so that by default if reads LOW - D0 on a Wemos D1 is a good choice).

2. Set the delay setting on the sensor to minimum (consult your sensor's documentation - but with these sensors there's often a screw-type adjustment on them to alter delay and sensitivity.)

![Schematic](./motion-detector.png)

*Software*

1. Install the [Arduino IDE](https://www.arduino.cc/en/software) with the ESP8266 board package.

2. Copy secrets.EXAMPLE.h to secrets.h and fill in your WiFi credentials and Slack webhook URL. These are the **initial** defaults — all settings can be changed later via the web UI without reflashing.

3. Compile and upload the sketch to your board.

Running
--
After powering on the device it will connect to WiFi and start a web server, then wait 1 minute for the sensor to warm up. During warmup the web UI is already accessible.

It then polls the sensor every 5 seconds — if motion is detected it lights the internal LED and notes that motion has occurred.

At the end of each notification interval (default: 1 hour) it sends a message to the webhook reporting whether motion was detected. The number prefixed to each message is the uptime in seconds, useful for remote debugging.

![Slack Screenshot](./screenshot.jpg)

Web UI
--
The device runs a small web server on port 80. Find its IP address in the Arduino IDE Serial Monitor at startup, then open it in a browser.

**Status page** (`http:///`) — auto-refreshes every 10 seconds and shows:
- Whether motion is being detected right now
- Whether motion has been detected since the last notification
- Time until the next notification
- Uptime, WiFi network, and IP address
- Number of messages pending in the outbox queue

**Config page** (`http:///config`) — lets you change all settings without reflashing:
- Primary and secondary WiFi credentials
- Webhook host, endpoint path, and API key
- Notification interval (in minutes)

Saving the config page restarts the device and applies the new settings immediately. Settings are stored in EEPROM and survive power cycles; secrets.h is only used as the initial default on a fresh flash.