**A Tale of Two Outlets: A DIY Smart Outlet Project**
As I embarked on a journey to create my own smart outlet, I couldn't help but wonder if I could make it better than the ones I've bought before. After all, who doesn't love tinkering with electronics and trying to push the boundaries of what's possible? In this article, I'll take you through the highs and lows of creating a DIY smart outlet, from the initial design to the final product.
**The Problem with AC Voltage and Current Measurement**
One of the biggest challenges I faced was how to measure the AC voltage and current safely. While it's possible to use a voltage divider and current shunt, this approach is not exactly safe as you could easily get shocked. To avoid that risk, I opted for a more traditional method using a voltage transformer and current transformer, which are galvanically isolated from the mains voltage.
**The Voltage Transformer: A Slightly Unconventional Choice**
I must admit that I was initially drawn to using a super small transformer that can produce a suitable lowered mains voltage for my IC. By attaching suitable resistors to its input and output side, as recommended in the datasheet, it became a viable option. On the other hand, the current transformer was relatively simple to use by hooking up one resistor across which I could measure the lowered AC current flowing through the wire.
**Adding a Resistor and Capacitor Network: A Necessary Evil**
At this point, I also added a rather complicated resistor and capacitor network to the voltage and current input of my IC as recommended in the datasheet. This was necessary to prevent value surges and get rid of unwanted frequencies. With this step complete, all that remained was programming my ESP through Home Assistant, which proved to be surprisingly easy.
**Fine-Tuning the Voltage and Current Gain Values**
The final step involved fine-tuning the voltage and current gain values in the code by comparing what values a cheap power meter spits out and what my ESP is producing. Once this was done, I was satisfied that the power measuring functionality seemed to work.
**A Word of Caution: Mains Voltage Safety**
I want to emphasize that we are dealing with mains voltage here, so if you're interested in replicating this project, please do so at your own risk.
**Why Not Test the Relay Functionality and 5V Power Supply?**
To be honest, I didn't test the relay functionality as well as the 5V power supply with my ESP because the complimentary components and circuits were relatively simple and straightforward. I decided to skip them and jump straight into Altium Designer Software to create the schematic.
**Creating a Schematic: The Easy Part**
Using the Library Loader add-on in Altium Designer Software made creating the schematic an absolute breeze. This allowed me to focus on designing a functional smart outlet without worrying about finding suitable components.
**Designing a PCB: A Bit of a Challenge**
After completing the schematic, I used the software to create a PCB design whose outline needed to be as wide as the buy socket but slightly longer due to more components. The reason for this was that I wanted to reuse the actual socket part of the buy version, which is something I couldn't make on my own.
**PCB Design Completion: A Satisfying Feeling**
After around 4 hours of working on the PCB design, I was pretty happy with it. Even the 3D model looked promising, which is why I continued by uploading my Gerber files to JLCPCB who offered me a fantastic price for the PCBs.
**The Prototype: A Few Design Mistakes**
Unfortunately, my first prototype had a few design mistakes. The footprint of the transformer was incorrect, and I messed up the orientation for the choke. Worst of all, I wired up the SPI pins of the power IC to the wrong pins on the ESP because I couldn't resist wiring up to the SPI terms.
**Fixing Design Mistakes: A Second Chance**
Despite these errors, my prototype still worked when it comes to the relay switching and partly the power measurement. I fixed those mentioned errors in the schematic and PCB design and got myself another round of PCBs.
**The Final Product: An Improved Smart Outlet**
After soldering all the SMD and THT components in place and uploading the final code, my smart outlet worked fine as well as the complete power measurement. The final touch involved designing an enclosure for my outlet, 3D printing it, securing the PCB with screws in there, mounting the socket with hot glue, soldering on all the wires, and finally closing it all up.
**A DIY or Buy Comparison**
To answer my DIY or Buy question, I created a little chart comparing both solutions. For me, DIY is the clear winner here, but then again, I can't tell you for sure how much better more pricey smart outlets would perform.
**Conclusion: A Smart Outlet Project Well Done**
And that's it! I made my own improved smart outlet that will hopefully last for a long time. It's been an enlightening experience to design and build something from scratch, and I'm proud of the final product. Who knows? Maybe you'll be inspired to create your own DIY project too!