Introduction: Smart Outlet
Disclaimer: This project is intended to show how you can prototype with an SV2 PCB printer. It is not a product that you should use as an everyday item. It was neither designed nor tested to comply with appropriate safety standards. You are liable for any risk you take when using this design.
A smart outlet is an IOT device which allows control over any connected device using a web server through any browser. The web server we programmed here allows us to decide which connected devices would turn on and off, essentially allowing virtual “plugging” and “unplugging” at the press of a button on a phone or a click on a computer.
Quantity x Item (Digikey Part Number)
- 1 x NEMA5-15P Male Plug and Wiring (Q108-ND)
- 3 x Female Receptacle NEMA5-15R (Q227-ND)
- 1 x Wifi Module ESP32-WROOM-32D (1904-1023-1-ND)
- 3 x Solid State Relay (255-3922-1-ND)
- 1 x Voltage Regulator 3.3V (AZ1117EH-3.3TRG1DIDKR-ND)
- 3 x NFET (DMN2056U-7DICT-ND)
- 9 x Resistor 100 ohm (311-100LRCT-ND)
- 4 x Resistor 10k ohm (311-10KGRCT-ND)
- 2 x Capacitor 1uF (399-4873-1-ND)
- 1 x Capacitor 10uF (399-4925-1-ND)
- 2 x Capacitor 0.1uF (399-1043-1-ND)
- 3 x LEDs (C503B-BCS-CV0Z0461-ND)
- 1 x Edge Connector (S3306-ND)
- 1 x 5V 1A AC-DC Converter (945-3181-ND)
Other Components/Materials Used:
- Heat Shrink Tubing, 8 inches
- Low Temperature Solder Paste
Tools and Equipment:
- SV2 PCB Printer
- 3D Printer
- Soldering Iron
- Reflow Gun
- DC Power Supply
- Screwdriver (3mm Hex)
- Super Glue
- USB Serial Programmer
Step 1: Print the PCB Design
Depending on how you create your own device, these steps may vary. To make this specific device, we created a PCB design and printed it using the SV2 PCB Printer. Since we used a PCB and not a proto-board or breadboard, most of our components are surface mount, such as the micro-controller, which was a ESP32-WROOM-32D module, and the relays, which we chose to be high power solid state relays. The specific components we used, along with their Digi-Key part numbers, are given above in the materials, but you can change the components to customize it to your specific design. The capacitor values should remain relatively the same if you do intend on using the same components. The values for the current limiting resistors may change based on which color LED you use, as the forward voltage and current may be different! This calculator will let you put in the parameters of your design and calculate the resistor values for you. We used blue LEDs, which are known to have a higher voltage drop than that of the red variants. Ensure your components which will interact with Mains Power (the solid state relays, the connectors, and the plug receptacles) are rated for AC mains voltage and sufficient current (120V 60Hz in the United States, around 10-15 Watts). The schematic and PCB design used to create our smart outlet can be found on the BotFactory website and you can read more about them on our blog article, titled Creating a Smart Outlet.
Step 2: Add the Components
The next step was to add all of the components onto the printed board. There are two ways to do this, you can either use the pick-and-place capability of the SV2 if you're using one, or you can hand solder each component to board one by one. Since this was the first prototype and we wanted to ensure each part worked with one another, we placed each component by hand and ensured continuity between components by using a multi-meter. We used thermally stable low temperature solder paste to secure the components to the PCB. Some of the external connections, such as connections to the plug receptacles and connections to the AC-DC converter, were done using an edge connector. Due to this, all that was needed was to print the gold fingers onto the PCB, and plug it in to provide a circuit connection. Once everything was on the board, it was supplied power from a variable voltage and current power supply, which has current limiting functionality in order to prevent the magic smoke from escaping upon a short circuit. If all is well (no magic smoke, no overheating components, no explosions) you can proceed to uploading the code to the ESP32.
Step 3: Upload Your Code
The ESP32 was connected to a computer using the TXD, RXD, and GND pins, using a USB to serial cable. Remember that the TXD on your cable connects to the RXD pin on the micro-controller and vice versa. Using the Arduino IDE, the boards for the ESP32 variants were loaded and the “FireBeetle-ESP32” board was selected as this had native support for the bare ESP32 chip we used. The code that was used essentially connects the micro-controller to your Wi-Fi router and opens a connection at port 80. Once that port is open, it supplies a webpage to any device connecting to it and can toggle GPIO pins between high and low based on button inputs on the webpage. Additionally, specific URLs can be used to turn a device on or off. Make sure you change the included code to include the Wi-Fi SSID and password for the network you want to connect the smart outlet to. The network we connected it to was secured with WPA2, but it may or may not work with unsecured networks.
Step 4: Test!
Using the proper tools and connections, test that all the connections and components on your almost completed device works! Test the AC components (the AC-DC converter and NEMA5 Plug) separately and handle them properly, they are for high voltage! Using an external DC power supply, power up your circuit and test that you can switch the transistors on and off by using the web interface, which should in turn operate the corresponding LEDs and allow current to flow through the solid state relays.
Step 5: Print the Enclosure
Depending on what components you chose and how you arrange them, your enclosure may be shaped differently. Here, we used a rectangular enclosure that houses the AC-DC converter, the PCB, the edge connector, and has profiles for the NEMA5-15R receptacles. We designed it using Fusion 360 and it printed it using a 3D printer, and attached the top face plate using 3mm heat-set inserts and 3mm hex screws. Glue works just as well if heat-set inserts are not available to you. If you do use heat-set inserts, the holes in the included STL files are 4mm wide, and you will need a soldering iron at 250C. Using the actual components, a test fit was then done to ensure that each part fit properly inside the enclosure.
Step 6: Assemble!
Finally, the permanent connections were soldered and components were put into the enclosure. Here, we followed the schematic for the correct connections between the PCB, the plug receptacles, the AC-DC converter, and the male plug. All the components were then once again tested to see if there were any problems when working together. Be sure to practice extra caution when working with AC circuitry! Do not touch the board or the wires when the circuit is powered from the wall. Ensure you unplug it before soldering, moving wires, or fixing loose connections. If all is well, you are now ready to close up the housing using four M3 screws and use your new smart outlet!