Introduction: Customizable 5 Buttons WiFi Smart Home Switch (Arduino Compatible + Open Source!)

About: Master student in Computer Science & Information Engineering, one of the developer of ArOZ Online Project. I love making something no one has thought of. If you like making things that seems not possible, send…

Recently I am renovating my room and I start looking into IoT / smart home devices. However, I am not the kind of person that willing to handle complex setup process and linking multiple device to a bunch of hubs just to make them turn on a light or another electronic devices. Besides, I am both a hardware and software developer, designing & manufacturing a new device is not that difficult. That is why I decided to make myself one which has the following properties

  • Privacy (Do not send your data over the internet)
  • Robust (Able to handle network architectural change with no / easy to update device settings)
  • No hub required (as my room is just too small to put a hub)

After considerations, I settle on WiFi as my primary way to connect the smart devices in my room. I do worry about power consumption. However, as I am renovating my room anyway and I can easily pull power cables all over my room during the renovation, it is a no brainier to using power saving protocols like Bluetooth or Zigbee which require an extra hub to work with my already setup homelab servers.



Supplies

As I am designing this board with parts that is available on most of the PCB manufacturer, you just need the followings to make your own

  • A computer with Arduino IDE (with ESP8266 installed in the board manager)
  • A PCBA manufacturer like NextPCB to manufacture the switch for you
  • A 3D Printer
  • Soldering iron (if you plan to build it yourself)
  • SMD components (See the attached diagram)
  • 4 x M3 x 5 screws
  • The other things you want to control which accept RESTFUL API (e.g. the relay module I am using, I will show you in later steps)

Step 1: Send the Switch PCB to Print

If you are good at soldering, you can print the PCB using any PCB manufacturer you like. However, as I am busy renovating my room, I don't have time to work on SMT soldering. Recently NextPCB approach me and ask if I am interested to accept a sponsorship from them and try their services. So I ask them if they could make the switch for me with their PCBA service.

The PCB gerber files can be found on my Git server over here.

https://git.imuslab.com/TC/HomeDynamicv3/src/master/hardware/hds_5-way-switch/pcb


Why NextPCB?

I personally do recommend their service as they do really have a great team of engineer to handle problems for you. If you are first time PCB maker and want to try all sorts of interesting design while making sure it is possible to produce, you can ask their engineer directly and they will give you recommendations on how to make it cheaper like sourcing alternative parts from China or how to pick another chip so it is generally faster to build.

They also help me to get this UR Mark that is really helpful if you are building commercial products.

Manufacturing

By uploading the Gerber file on NextPCB Gerber viewer, you'll able to see all the errors in order to make sure your design is ready for manufacturing. Feel free to try that out!

https://www.nextpcb.com/free-online-gerber-viewer.html

I ordered 5 pieces for my room which should be able to cover all my room's lighting and automation devices. After the boards arrive, you can start the 3D printing process and programming!

Step 2: 3D Printing & Installing Switch Panel

The step is quite straight forward. I designed a flexible PLA pieces that can be screw on top of the PCB to act as a front cover while provide enough flexibility so you can press the pieces and activate the SMD button below.

There are also tiny holes next to each of the switch so you can know if the press is registered or not. You can also program them to show the status of the device being controlled.

Step 3: Programming

Programming for IoT

This is the tricky part. If you already have Arduino programming experience, here is the code I am using.

https://git.imuslab.com/TC/HomeDynamicv3/src/master/hardware/hds_5-way-switch/firmware/5xswitches

In my code, I am resolving the target device using mDNS address, which you can see from this line of the .ino file.

//Modify these two control other devices
#define TARGET_DEVICE "hds_4xRelay_48-3F-DA-67-3D-BD.local"


The device name can also be changed in hdsv3.ino file in the following line

 MDNS.addDynamicServiceTxt(p_hService, "name", (String(DEVICE_NAME) + "_" + deviceUUID).c_str());


I design it like this so if there are an update in router or wifi hardware, and the IP address has been updated, the device can still connect to each other by resolving the mDNS domain instead of IP address.

Alternatively, you can also use painlessMesh or similar for a complete off-grid system. But in my case, I want it to be controllable by my homelab server which is in the same subnet using TCP/IP. That is why I keep them like this.

Programming for physical RESTFUL API switch

However, this switch can also make standard RESTFUL API request to a web server anywhere connected to the internet. HTTP Client examples are also included in my code above, so feel free to take a look and figure out the rest of it yourself.

Step 4: Programming the Target Device

As I am gonna use my switch to control my LED strips, I need a relay to handle the switching. That is why I go online and found this WiFi relay module from Aliexpress. Most of them are similar and provide a programming interface where you can modify its code to make it compatible with our mDNS resolving mechanism.

For my relay, the code is available here for reference.

After programming it, I get an off-the-shelf rail mount case for the relay module and screw it in. That way, I can install it on one of the wall I plan to use for automation equipment.

Step 5: Quick Test

After everything is done and firmware has been flashed, give it a quick test by powering both device. If both device are working, you shd see the switching motions of the device is pretty much instant with little to no delay as all communication are done within the same local area network.

Step 6: Installation

There are two pads on the bottom of the PCB here where you can power it either via the micro USB port or the pads. I personally don't mind using the mini USB port as I am planning to stick it under the table, but if you are embedding it into your table or wall, you can also use those two pads for powering.

If you want to go truly wireless, you can even attach a thin power bank at the back and cut a USB A cable for power. The method of powering it is up to you :)

Step 7: Your Smart Home Wall Switch Is Now Completed!

Finally, your smart home wall switch is done! I am currently in the progress of programming each of them to do different things. I will keep my repo updated once I have new devices release with similar functionality so you can check back frequently to see if anything interested to you pops up!

See you in the next instructable~