HomeKit Knock-Knock Sensor

by TL1KM6Zqf1 in Circuits > Arduino

1441 Views, 26 Favorites, 0 Comments

HomeKit Knock-Knock Sensor

Screenshot 2023-04-28 at 9.14.48 AM.png
Screenshot 2023-04-28 at 9.37.22 AM.png

This project will go into detail on how to setup a sensor in HomeKit that will respond to knocking in 3 different patterns.

  • The first pattern is two quick knocks with a pause before the 3rd.
  • The second pattern is one knock with a pause before a quick 2nd and 3rd.
  • The third pattern is three equally spaced knocks.

Each of these different knock patterns can be configured to control different HomeKit accesories. For this example, I will use it to control a lamp and turn the light on and off.

Supplies

IMG_4145.jpeg

To start this project, you will need:

Getting the Software Ready

Screenshot 2023-04-28 at 10.24.50 AM.png
Untitled_2.jpg

After downloading and installing the Arduino IDE, download this GitHub Repository and unzip the file. Then, open the file HomeKit_knock.ino file in the Arduino IDE. Once in the Arudino IDE, open up the Library Manager and search for "HomeKit-ESP8266" by Mixiaoxiao and install that library, as well as "WiFiManager" by tzapu.

Almost there! The next library that is needed is the PeakDetection library from GitHub. Once downloaded, unzip this file as well and place it into the "libraries" folder in your Arduino folder (located in your Documents folder). Your Arduino folder should appear like the screenshot above with the libraries in the correct locations.

Flash the Software

Screenshot 2023-04-28 at 10.40.44 AM.png

To flash the software to your ESP-8266, simply plug in the device with a micro-usb cable, and choose the "Upload" button in the Arduino IDE. The software will take a few seconds to compile and upload to the ESP-8266. Once this is done, you have the software on your ESP to connect it to the Home app on your phone, as well as control other devices.

Soldering the Piezo-electric Sensor

Screenshot 2023-04-28 at 11.18.54 AM.png
IMG_4148.jpeg
IMG_4150.jpeg
IMG_4149.jpeg

After flashing the firmware to the ESP, the next step is to unplug the ESP and solder on the piezo-electric sensor. This piezo-electric sensor is a device that can detect vibrations, which is exactly what we need to detect knocking. Simply solder the red cable to the analog pinout on the ESP, (usually indicated with "A0") and solder the black wire to the ground pin-out as shown in the diagram above.

Once that's done, simply insert the ESP and the piezo-electric sensor into a 3D printed case. I have linked one above that you can use, but any 3D printed case that fits a ESP-8266 should work. I also added some nuts and bolts into the pace under the ESP to give it some extra weight since without it the device would be lifted up by its cable as a plastic case and a circuit-board don't weight much.

Hooking It Up to HomeKit

Screenshot 2023-04-27 at 7.11.24 PM.png
Untitled.jpg

After soldering on the wires and plugging your device into a power outlet with a micro-usb cable, simply open up your Home app on the iPhone and choose the plus button to add a new device. The device should be connected to the WiFi and show up as a Stateless Programmable Switch. The HomeKit setup code for the device is defined in the arduino code from earlier, but assuming you didn't change it the code should be all 1's like so: 111-11-111.

Once the switch is added to your Home app, simply open up the switch to configure the different knock actions and what you want them to control. For example, it could be configured as follows:

  • Single Press (turn on a lamp)
  • Double Press (turn off a lamp)
  • Long Press (unlock the front door)

You're done! You now have a piezo-electric knock-knock sensor that can control any other HomeKit accesory you have in your home.