You can then add the smart motion sensor in the Apple Home app or Eve for HomeKit app and set up automation to trigger a smart light switch or receive notifications on Apple devices, such as an iPhone.

Things You Will Need

We will build a DIY motion sensor for Apple HomeKit which is recognized as an 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

Flash the Firmware

For the D1 Mini board, we are going to use firmware by HomeKid. Also, you will need a Windows or macOS system and a micro USB cable.

Connect the D1 Mini board to the system using the micro USB cable and then follow these instructions to flash the firmware.

On Windows:

Download and extract the Espressif Flash Download Tools. Open the extracted folder and launch the flash_download_tool_xx. exe program. In Chip Type, choose ESP8266 and click OK. Check the first three checkboxes as shown in the below image and then, Type 0x0000 and click three dots to choose the rboot. bin file. Type 0x1000 and choose the blank_config. bin file. Type 0x2000 and choose the main. bin file. 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 the COM port on which the D1 Mini is connected and click Start. This may take up to two minutes to finish.

On macOS:

Download and launch the NodeMCU-PyFlasher. dmg on your macOS system. Connect the D1 Mini to your Mac system and then choose the Serial port. Click Browse and select the main. bin file. In Baud Rate, choose 115200. Choose Quad I/O (QIO). Select Erase Flash and yes, wipes all data. Click Flash NodeMCU. After the NodeMCU is flashed, reconnect it to restart and then follow the next instructions.

Once the firmware is flashed successfully, you need to connect the device to your Wi-Fi network.

Connect to Wi-Fi Network

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. Connect to the Homekid-XXXX Wi-Fi AP using the password 12345678. A login window will appear on your device. Tap on your Wi-Fi network and enter the password. 2 Images Close Tap Join. The device will disconnect from your smartphone and connect to the Wi-Fi network using the password provided.

If the password entered was wrong, the device will start AP after some time. You can then again connect 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 the D1 Mini or NodeMCU board.

Add Accessory to the Home App

On your iOS device, or macOS device such as 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 work similarly to an official Elgato Eve motion sensor for Apple HomeKit.

In the Home app, tap on the + icon and choose Add Accessory. Tap More Actions… and then tap on the Motion-XXXX accessory. 3 Images Close Tap Add Anyway and then enter the code 1180-3193. Tap Continue. Choose the location where you will be installing the motion sensor and tap Continue. 4 Images Close Edit or change the name of the motion sensor. This is important for keeping track of multiple motion sensors. Tap Continue > Done. You can now see the motion sensor as an accessory under the room name. If you tap on the accessory, it opens a control panel where you can edit the properties of the sensor. 3 Images Close

You can also install the Eve for HomeKit app for more options and control on the DIY motion sensor. This app provides a more intuitive UI, making it easier for you to manage your official and unofficial DIY HomeKit accessories, such as a DIY HomeKit WS2812B NeoPixel RGB strip.

Troubleshooting

You will need to re-flash the firmware in the case of 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 re-flashing the microcontroller board, make sure you erase the memory using the Erase button and then click Start to flash the microcontroller board with the firmware.

Automate Lights and Switches

You can use this cheap DIY HomeKit-enabled motion sensor for security or to automate lights, switches, or any other smart device in your home. For instance, you can set up automation in the Home app to trigger a smart switch or smart light when motion is detected in a particular area, such as a staircase or hallway.

You may also set up an automation to receive notifications on your iPhone whenever motion is detected. However, you will need an Apple HomePod or Apple TV (4th-gen or later) installed on your network or premises to create the automation. Otherwise, you can only use the sensor for motion detection.