HomeKit Smart Home Using Wifi Modules and Arduino

by NikiTricky in Circuits > Apple

1072 Views, 5 Favorites, 0 Comments

HomeKit Smart Home Using Wifi Modules and Arduino

thumb.png

In this tutorial, I will show you how to make your own Homekit smart home using WiFi modules and a bit of code.

Supplies

  • Any module with WiFi support (I will use the NodeMCU v3)
  • 3.3V LED and 220 Ohm resistor
  • Temperature sensor

Optional

  • Any supported Apple Homekit hub (HomePod, Apple TV, or iPad with iOS 13 or later)

Installing the Correct Software

If you are using a NodeMCU, ESP8266, or any similar device, Arduino does not natively support them. First, you need to install the CH34x driver. You can download it here: https://sparks.gogo.co.nz/ch340.html.

Next, you need to open your Arduino preferences (File>Preferences) and add http://arduino.esp8266.com/stable/package_esp8266com_index.json.

Next, go to Tools>Board>Boards Manager and search for esp8266, then install it.

Select your board model under Tools>Board.

Finally, we need to install the library Arduino-HomeKit-ESP8266. So download the GitHub repository at https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP8266. Then in Arduino go to Sketch>Include libraries>Add .ZIP Library and select the downloaded library.

Making a Smart LED: Circuit

Screenshot 2022-11-07 201615.png
IMG_1821.jpg

The circuit here is easy, all we need to do is wire a LED to the pin of your choosing. In this case, I will wire it to D0 with a resistor.

Making a Smart LED: Code

Screenshot 2022-11-07 203330.png

So we don't write all the code, just select Examples>Arduino-HomeKit-ESP8266>Example02_Switch. Add your WiFi credentials in wifi_info.h and change PIN_SWITCH to your pin of choice (D0 is pin 16). Now compile it and send it to the board. Open your Serial port.

Pairing With a Device

IMG_1822.jpg
IMG_1823.jpg
IMG_1824.jpg
WhatsApp Image 2022-11-07 at 9.15.33 PM.jpeg

Check if your device has paired to the network and connect your iPad/iPhone to the same network. Then click the plus in the top right corner, select "Add device" and then "More options". Now you should see your custom device as "Switch". Click the device and it should connect in a few minutes. If not, check the Serial port for more info. When prompted for a password, enter "1111-1111" or any other 8-character password you have entered in device_info.h.


Tips

  • If the LED state is inverted (On is Off and Off is On), in cha_switch_on_setter swap the HIGH and LOW values in the last line of the function.
  • If you want to make a new device using the same module uncomment homekit_storeage_reset() in Setup.

Making a Smart Temperature Sensor

This time we will use Example01_TemperatureSensor. Add your WiFi credentials and add code for the reading of your sensor. I will be using a DHT11 sensor. Change the code as the comments describe. In device_info.h you can uncomment some lines to add humidity to the sensor.

Creating a Casing

IMG_3093.jpeg

It doesn't matter what material you make it from. In this case, I'm going to make it out of paper. While this step may be optional, it is always recommended to protect your circuits.

Using a Home Hub

If you want remote control and automation, you need a home hub. The Apple supported home hub devices are:

  • HomePod or HomePod mini
  • iPad with iOS 13 or later
  • Apple TV 3rd generation or later

See this article on how to set up the devices as a hub.