By adding your own motion sensor to your Apple HomeKit network, you can detect intruders or activate lights when motion is detected.
Smart home devices compatible with Apple HomeKit are often quite expensive. However, you can build your own casual smart home sensors, such as one that detects motion, using an inexpensive ESP8266-based board such as the D1 Mini along with a PIR or microwave radar-based motion sensor for less than $5—no soldering required.
You can then add the smart motion sensor in the Apple Home app or the Eve for HomeKit app and set up automations to turn on a smart light switch or receive notifications on Apple devices, like the iPhone.
The things you will need
We are going to build a DIY motion sensor for Apple HomeKit Which is known as the Elgato Eve motion sensor. To build a smart motion sensor for HomeKit, you will need the following components:
- D1 Mini or NodeMCU board
- HC-SR501 or SR602 infrared PIR, or RCWL-0516 microwave based radar motion sensor
- Some jumper wires
- PC or laptop
- Micro USB cable
- 5V Micro USB power supply
The PIR motion sensor has a limited detection area that requires a clear line of sight: it cannot detect movement behind objects. The microwave radar motion sensor can sense movement through objects or a solid wall and provides greater coverage. Also, the microwave radar sensor is more sensitive than the PIR-based passive motion sensor.
For the D1 Mini board, we will use the firmware by HomeKid. You’ll also need Windows or macOS and a micro USB cable.
Connect the D1 Mini board to the system with a micro USB cable, then follow these instructions to flash the firmware.
- Download and extract Espressif Flash Download Tools.
- Open the extracted folder and run the file flash_download_tool_xx.exe program.
- in a chip typeChoose ESP8266 and click yes.
- Tick the first three checkboxes as shown in the image below and then,
- Choose the following options in the ESP8266 Flash Download Tools window.
- Baud rate: 115200.
- Flash size: 4MB.
- Flash mode: DIO or QIO.
- SPI speed: 40MHz.
- Select a file COM The port the D1 Mini is connected to and click on it Start. This may take up to two minutes to complete.
- Download and run the file NodeMCU-PyFlasher. dmg on your macOS.
- Connect the D1 Mini to your Mac and choose File serial port.
- click browse and select a file main. bin a file.
- In Baud rate, choose 115200.
- Choose Quad Input/Output (QIO).
- Choose erase flash And the Yes, it wipes all data.
- click Flash NodeMCU.
- After flashing the NodeMCU, plug it back in to reboot and then follow the instructions below.
Once the firmware has been successfully flashed, you need to connect the device to your Wi-Fi network.
Connect to Wi-Fi
close the Espressif Flash Download Tools windows and reconnect the D1 Mini to your system.
- Take out your iPhone or other iOS device and open the Wi-Fi settings.
- Contact Homekid-XXXX Wi-Fi AP using password 12345678.
- The login window will appear on your device. Tap on your Wi-Fi and enter the password.
- handle joins. The device will disconnect from your smartphone and connect to Wi-Fi using the provided password.
If the entered password is wrong, the device will start the access point after some time. You can then connect back to the AP and enter the correct password.
Connect the components
Refer to the wiring diagram below to connect the HC-SR501 PIR motion sensor to a D1 Mini or NodeMCU board.
If you will be using an SR602 PIR or RCWL-0516 microwave radar motion sensor, connect the Output pin to pin D6, the Vin to pin 5V, and the Ground pin to pin G on the D1 Mini or NodeMCU.
Add an extension to the home app
On an iOS device or a macOS device like a MacBook, open the Home app and then follow these steps to add the motion sensor we made as an accessory. The device will be added as an unofficial accessory, but will function similarly to the official Elgato Eve motion sensor for Apple HomeKit.
- In the Home app, tap + Code and choose Add an attachment.
- handle More actions… Then press Motion- XXXX Appendix.
- handle add anyway Then enter the code 1180 – 3193. handle Complete.
- Choose the location where you will install the motion sensor and press Complete.
- Edit or change the name of the motion sensor. This is important for tracking multiple motion sensors. handle Complete > Finished.
- You can now see the motion sensor as an accessory under the room name. If you click on the extension, it opens a control panel where you can edit the sensor properties.
You can also install the Eve for HomeKit app for more options and DIY motion sensor control. This app provides a more intuitive user interface, making it easier for you to manage both official and unofficial DIY HomeKit accessories, such as DIY HomeKit WS2812B NeoPixel RGB Strip.
find the mistakes and resolve it
You will need to re-flash the firmware if the following issues:
- If the wireless AP is not visible in your smartphone’s Wi-Fi settings.
- If the device is not visible in the Apple HomeKit app.
Before reflashing the microcontroller board, be sure to clear the memory with a file erase button then click Start Flashing the microcontroller board with firmware.
Automation of lamps and switches
You can use the DIY HomeKit motion sensor for security or to automate lights, switches, or any other smart device in your home. For example, you can set up automation at home The app to turn on a smart switch or smart light when motion is detected in a specific area, such as a stairwell or hallway.
You can also set up automations to receive notifications on your iPhone whenever motion is detected. However, you’ll need to have an Apple HomePod or Apple TV (4th generation or later) installed on your network or workplace to create the automation. Otherwise, you can just use the sensor to detect motion.
#DIY #motion #sensor #Apple #HomeKit