Plug It - Open Source Smart Plug
by Thomas Huyghebaert in Circuits > Gadgets
54252 Views, 402 Favorites, 0 Comments
Plug It - Open Source Smart Plug

Plug It is a compact, dimmable smart plug with energy monitoring. Not only can you control it remotely using the web-app, it can also be operated entirely physical using the knob and integrated OLED screen. The Plug It smart plug can measure up to 1kW in switch-mode and up to 200W in dimmer-mode. The smart plug can also operate automatically by configuring a timescheme in the web-app. As an extra feature, it can operate based on a light measurement. This is very useful to automate lights.
The web-app runs on a Raspberry Pi, this way you can access the website via your local network or apply port forwarding to your router to access your plugs from anywhere. The Raspberry Pi also functions as a central connection point for the plugs since all your plugs connect to it via Bluetooth Low Energy.
(This is actually a school project which had some basic requirements like designing a responsive web application, create a database model and writing server software to run on a Raspberry Pi.)
IMPORTANT: Build this at your own risk, this is a DIY smart plug that doesn't follow official safety standards.
Supplies

- Soldering iron
- Screwdrivers
- USB UART cable or module
- Crimping tool
- Superglue
- Two component glue (optional)
Order All the Components and PCBs(+3D Printing)

This smart plug requires a lot of components and soldering. All the components are readily available.
The total cost of one smart plug (shipping not included) is about 28 euros.
You will also need to order some custom PCB's and have some parts 3D-printed. Most big PCB manufacturers also offer a 3D-printing service nowadays.
If you are interested in the electrical schematic, I included a PDF in the files below.
Solder All the Components


.jpg)
Having a decent soldering iron or even a soldering station is recommended here.
Start with the ESP32 since this is the only SMD-component on the PCB. It's pins are tiny and really close together so take your time and use a lot of flux. Tape it on the board zo it doesn't move around while soldering. If you have some thermal paste laying around you can put some on the thermal pad before placing the ESP32 on the board.
The rest are all THT components, solder these starting with the shortest ones and working your way up.
Add Threaded Inserts to the Case

To make sure the casing of the smart plug and the Raspberry Pi is sturdy we will use threaded inserts and small screws to hold everything together.
Take a threaded insert and place it in one of the holes in the case. Next, grab a soldering iron and insert it's tip into the threaded insert. Gently push down untill it's flat with the case. Repeat this for all of them.
Glue the Female Socket Sliding Mechanism


The female socket consists of 2 parts: a sliding mechanism and the socket itself.
Apply some superglue on the botton of the sliding mechanism, and place it on the backside of the casing's female socket. (All the holes should perfectly align with eachother.)
Take your soldering iron again and melt the little plastic holders on the sides flat. This should really bond the casing to the socket even more.
Mount the Female Socket



Grab your cables and cut about 10cm of a live, neutral and ground wire.
Use a knife or a pair of stripping pliers to remove 1cm of the insulation on both ends.
Insert the cables into the socket and screw them really tight. The ground connection is labeled on the socket.
Place the socket on top of the sliding mechanism inside the case, and insert a 20mm screw from the other side.
Prepare Cables for the Male Socket


Grab a live and neutral wire and cut them to a length of about 10cm.
Remove about 5mm of insulation on one end and put a cable lug on each cable.
Next, use a crimping tool to tighten the cables. (Check the color markings on the crimping tool.)
Use a knife or a pair of stripping pliers to remove 1cm of the insulation on the other side of the cables.
Insert the ends with the exposed copper into the male socket and screw them tight.
Glue the Male Socket to the Case
To glue the male socket to the case we can use regular superglue or two component glue (epoxy). Epoxy glue will most likely be stronger in the long run, so this is my recommendation.
Mix the two components of the glue and apply it quickly to the borders of the socket.
Mounting the OLED Display

Make sure the OLED display has 90° pins on the back. If not, desolder the regular ones and replace them with 90° pins.
Check the display's pinout because you won't be able to read the top silkscreen anymore when it's mounted.
Drop the display in it's designated hole, the pins should be on the top side.
Flatten the corner pieces by using a soldering iron like you did before with the slide mechanism of the female socket.
Inserting the First PCB


Insert four 6mm standoffs into the lower threaded inserts.
Grab the PCB that contains the ESP chip and rotary encoder.
Connect the OLED display to the I2C interface on the PCB with some jumper cables, all pins are marked with a name.
Also attach jumper cables on the bottom pins of the PCB, this is for connecting the two PCB's to eachother.
Lay the PCB on top of the standoffs so that the holes in the PCB perfectly align with them.
Inserting the Second PCB


Grab the lid of the case (the one with the male socket glued to it).
Screw 30mm standoffs (or a combination of 20mm and 10mm) into the holes of the PCB, but in the top-right corner you have to put the cable lugs (from the male socket) in between.
Next, grab the second PCB and face it down like the other one. Insert the live and neutral wires from the female socket into the screw terminal and screw them tight. Also connect both PCB's to eachother by plugging in the jumper cables (the ones in the bottom cavity).
Lay the PCB on the standoffs and align it's holes with them.
Insert two 5mm screws in the top right holes of the PCB (the ones where the cable lugs are mounted beneath aswell).
Closing Up the Smart Plug
.jpg)
Push the lid down and try to align the holes.
Insert four 5mm screws into the lid.
Push the knob on the rotary encoder on the front side to finish the build of the smart plug.
Mounting the OLED Display for the Raspberry Pi

Make sure the OLED display has 90° pins on the back. If not, desolder the regular ones and replace them with 90° pins.
Check the display's pinout because you won't be able to read the top silkscreen anymore when it's mounted. Drop the display in it's designated hole. Flatten the corner pieces by using a soldering iron like you did before with the slide mechanism of the female socket.
Place the Raspberry Pi in the bottom part of the case.
Closing Up the Raspberry Pi Case


Connect the display to the I2C interface of the Raspberry Pi and put the bottom half and top half of the case together. Insert four 5mm screws in the corners to finish the Raspberry Pi case.
Running the Server Software on the Raspberry Pi

The backend and frontend code is available at: https://github.com/howest-mct/2021-2022-projecton...
I included an image of the database structure in the files above.