DIY WiFi Lights Switch | IoT
by diego.avellaneda1733 in Circuits > Electronics
513 Views, 6 Favorites, 0 Comments
DIY WiFi Lights Switch | IoT
Hey, here you will see step by step how to develop a wifi switch from scratch, the design of the system, the PCB and the assembly. This Switch gives you the option to continue turning on the light manually with a touch panel, also to turn it on through the Internet, and to know the current status of the lights in your house (if you only want to know the status).
Blocks Diagram
As seen in the introduction, two microcontrollers will be used to allow it to continue to be handled manually and with the characteristics of WiFi. We do not want the device to be unable to turn the light on or off in a WiFi reconnection state.
The Microcontrollers that will be used will be the well-known ATMEGA328P and ESP32.
These communicate through UART and the ATMEGA 328P takes care of the main process, leaving the ESP32 with only communication tasks.
SCHEMATICS
Let's talk a little about the circuit, the schematic is developed in EasyEDA (if you don't know it, it is an excellent tool with which you can have your circuits in the cloud and make modifications from any device).
In the first circuit, you can see the necessary connections to operate the ATMEGA328P, with an 8MHZ crystal so that we can handle it at 3.3V (this to maintain the logical levels of communication with the ESP32).
We have as inputs the touchpad managed by a TTP223 and ISP pins to load the firmware from Microchip Studio.
Communication via UART with the ESP32, which also has the outputs as input.
The ESP32 outputs an RGB LED to indicate the status of the connection, whether it is as a client or as an AP.
The design is modular, that is why you see two schematics, the second is responsible for feeding the circuit from 110 VAC - 220 VAC and turning on the relays.
PCBs Design
In this step, we see the design of the PCB, as I told you before, the design is modular and the idea is that you can replace it with your old and boring manual switch. This has the measurements of the standard switch box and with that design, you will have no problem locating it.
Firmware
In the following repository
you will see the code of the ATMEGA328P and ESP32 both in Arduino.
The ATMEGA328P has a very basic state machine that manages both manual and ESP32 inputs.
The ESP32 for its part is responsible for connecting to an MQTT broker, (the market offers many free options such as CloudMQTT and MAQUIATTO) and subscribing to a topic, it comes to your creativity if you want to turn it on by voice with Alexa or Google Home , through chat. To test the Switch I recommend using MQTT LENS which is a Chrome extension to see the traffic of an MQTT broker.
Assembly Part 1
First remember that this device is designed for standard switch boxes.
Assembly Part 2
I'll leave the STL files for you in the project's repository folder, they are just two print files and a polarized acrylic display that must be laser cut.