Plug It - Open Source Smart Plug

39,910

320

25

Introduction: Plug It - Open Source Smart Plug

About: My name is Thomas Huyghebaert. I'm 18 years old and I study Multimedia & Creative Technologies at Howest in Kortrijk, Belgium. I love programming and I want to become an AI engineer in the future. I also h…

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)

Step 1: 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.

Step 2: Solder All the Components

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.

Step 3: 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.

Step 4: 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.

Step 5: 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.

Step 6: 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.

Step 7: 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.

Step 8: 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.

Step 9: 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.

Step 10: 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).

Step 11: Closing Up the Smart Plug

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.

Step 12: 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.

Step 13: 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.

Step 14: 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.

Be the First to Share

    Recommendations

    • Stone Concrete Cement Contest

      Stone Concrete Cement Contest
    • Build a Tool Contest

      Build a Tool Contest
    • Hot Glue Speed Challenge

      Hot Glue Speed Challenge

    25 Comments

    0
    hougaarden
    hougaarden

    16 hours ago

    Beste Thomas,
    Laat je niet ontmoedigen door de negatieve commentaren. Natuurlijk hebben ze gelijk op het gebied van de veiligheid, maar ik beschouw dit als een leerrijk project waarvan het resultaat een prototype is dat niet geschikt is om door een leek in deze vorm gebruikt te worden. Projecten op laagspanning zijn meer geschikt om via het internet te verspreiden, niet iedereen is zich 100% bewust van de gevaren van elektriciteit ;)
    Uw leraar mag tevreden zijn met uw inspanning.
    Van mij krijg je in ieder geval een voldoende:
    Originaliteit: 7/10
    Ontwerp: 8/10
    Uitvoering: 9/10
    Documentatie en beschrijving: 10/10

    0
    panic mode
    panic mode

    3 days ago

    congratulation, beautifully done and a great milestone but as others have mentioned working with mains is ambitious and therefore a lot of caution is required.
    there are plenty of good comments and tips on safety so perhaps i could offer couple of details that may be useful.

    the AC supply is isolating DC output from mains (double insulated) which is good.
    zero cross detection is also insulated thanks to optcoupler.
    current measurement with ACS712 is also isolated.
    relay contact is also isolated from coil circuit...

    so far so good...

    but the problem is that galvanic isolation from mains is lost due to dimmer circuit. this part of circuit connects to both AC and DC without isolation. and this could be modified to be isolated as well using triac and random firing optocoupler (MOC3031 for example with larger triac as a switch) instead of those mosfets. with this change low voltage control circuit would be completely isolated from mains and therefore much safer to use (debugging and program changes for example).
    something like this https://www.sonelec-musique.com/images2/electroni...
    note: that example shows zero zrossing opto but that is not what you want for a dimmer. dimmers require random phase version.

    also valid points on PCB trace width and spacing between them.
    traces need to be sufficiently wide and thick to cary large current. but they also need to be far apart to safely handle the voltage. there are several ways to deal with so called creep current - increase space between tracks, add strategic cuts/slots in PCB, use potting or at least conformal coating (not just solder mask but coating everything - including solder points).

    also move load switching circuit from the neutral to the phase. in current design fault to ground would keep load powered and that is not good. if your circuit is designed to handle limited current (less than source can supply) you should always add local fuse.

    and do not let comments deter you. use the feedback to improve...

    0
    nqtronix
    nqtronix

    4 days ago

    Before attempting this, you should know that this is a potentially life threatening device. And yes, I really mean it unfortunately. A few things that are bothering me:

    - The case looks like a PLA print - if it indeed is, it is not suitable for anything high voltage. It is easily flammable and does not provide sufficient protection.
    - The PCB does not have primary/secondary separation, which means you have to consider the entire board "live".
    - Because the board is "live" all standoffs must be considered live too, and the plastic case may not provide adequate insulation.
    - Even if the board had primary/secondary separation, the gaps are way to small, for homemade stuff it should be 6mm or more.
    - Standoff are mechanical part and should not carry power. If you do use them that way, you must ensure the connection is reliable.
    - Your socket features a earth terminal, but you never show or mention that you connect it. It must be connected, because devices that have a mains earth terminal need it for safety reasons.

    I'm not saying you have to take it down, but you should make your note on the first page BOLD. Otherwise it's nice project with a good overall design, so you got that part right at least.

    0
    me-chiel
    me-chiel

    5 days ago

    Briljant ontwerp! applaus!

    0
    AndrewHoover
    AndrewHoover

    7 days ago

    I like your project and your building techniques are robust. The one downside I see is in the mains power board - for additional protection, it would be a good idea to airgap the mains lines or the 240 side from the low voltage DC side of the board. Just a small suggestion.

    0
    elmo40
    elmo40

    9 days ago

    This should be removed. No one should create a home made line voltage device. There are reasons electrical code exist. One faulty solder joint or loose screw and your house can burn down!

    0
    AndrewHoover
    AndrewHoover

    Reply 7 days ago

    You clearly haven't bought any cheap smart switches off of amazon. None of them have been certified in the US and likely wouldn't pass UL certification.

    0
    MacM54
    MacM54

    Reply 7 days ago

    If you house will burndown by one wrong faulty solder joint or loose screw, you better moveout, because the only thing that will happen is to blowout a fuss or an earthswitch.

    0
    jdaruda
    jdaruda

    Reply 7 days ago

    I think he covered that with the important warning at the bottom of the introduction.

    0
    antonio00121
    antonio00121

    7 days ago

    Well done, This is an amazing project!

    0
    MichaelKlos
    MichaelKlos

    Question 14 days ago on Step 14

    Where is the software? The GitHub link produces a 404.

    0
    Razanur
    Razanur

    Reply 7 days ago

    Yup, checked all repos of that owner (howest-mct). I guess it is the school's github and they purge once in a while. @Thomas, can you maybe upload on a private github again?

    0
    alfon1917
    alfon1917

    9 days ago

    It would be nice to have more info on how this works, what each part does, what the role or the Raspi is etc. And, of course, a working github link

    0
    Thomas Huyghebaert
    Thomas Huyghebaert

    Reply 9 days ago

    Hi, I updated the description a bit to make the use of a Raspberry Pi more clear. This was a school project, for the software I used a github repository that my teachers provided for me. It seems that I'm the only one who can view the repository, I will try to fix this as soon as possible! Thanks for your feedback.

    0
    alfon1917
    alfon1917

    Reply 8 days ago

    Dear Thomas,

    This is an impressive build, especially for a school project. I see you have received lots of criticism, most of it constructive. Try to not be overwhelmed by it. You built something impressive, which however needs improvements. If you decide to become an engineer, you 'll see that most projects are like this: You start with a set of specs, build something, then the customer sees that it doesn't fit their needs (although it DOES fit the specs they supplied!), so you build a second version that does fit their needs but they remember that they have other needs too, you build the third or fourth version which covers all their needs. By this time you have learned their needs well enough that you know you can make further improvements/additions in order to cover needs they didn't know they had, or they didn't know it was possible to cover those needs.

    At first sight, it would seem a bad idea for your school to have you post a description of your project here, especially in view of the risks associated (high voltage, fire hazard etc). On the other hand, this forced you to deal with the feedback, which is an entirely different lesson.

    Having read all the comments, I would suggest you enlarge the disclaimer, explaining that the risks are very real and that this is a proof-of-concept project which should only be built by people knowledgeable in the field, who would probably make improvements. Explain what the risks and limitations are, what people should NOT do with this project and what they should improve if they want to use this in a "production" environment.

    If you feel like devoting more time to this instructable, it would be nice to include the "why" beside the "how": details such as those you placed in your replies (why you chose the dual MOSFET design instead of the triac, a little backround or links to resources etc.) An instructable in the spirit of "Why I did it like this" is always more useful and interesting than one in the spirit of "How I did it".

    I am a software engineer with more than 35 years' professional experience. I also have a good amateur grasp of Electrical Engineering. Based on what I saw here, I believe you have what it takes to follow a career in engineering.

    0
    MattD99
    MattD99

    Question 8 days ago on Introduction

    Well done - I wish you success in your chosen career.
    I can't see reference to the male and female connectors in the parts list - where did you get them please

    0
    BG_INS
    BG_INS

    8 days ago

    Thomas, and you are only 18, very well done. Yes the device is maybe not safe enough but you have shown the world what you can. I am sure there is a company nearby who will be very interested in a guy like you.
    Study my friend and you will have a bright future. Hardware, software and electronics engineering.

    0
    kresp
    kresp

    9 days ago

    Glad to see this kind of open source project since I was also working on a similar project and can see some parallels.

    One remark though: Please do not advice people to build a circuit connected to mains voltage on a breadboard!
    Breadboards are neither rated for high DC voltage nor for the relatively high currents that might flow when connecting mains devices. Not to speak of the missing of any insulation for parts that carry mains voltage!

    One question in regard to the general circuit:
    What are the reasons for you to switch the N line in the dimmer circuit part rather than the L line?
    Doesn’t it mean you always have a live wire at the outlet side even if the device should be in off state? Switching L seems to be the saver option to me.

    0
    Thomas Huyghebaert
    Thomas Huyghebaert

    Reply 9 days ago

    Thanks for the feedback!
    I had to create a breadboard version of the smart plug in Fritzing and include it in my instructable for a school assignment. But since this project got way more views than expected, I removed the breadboard schematic because that would indeed be quite dangerous. Thanks for pointing that out.
    Regarding your question, when I was designing the circuit I did some research on dimmer circuits using MOSFETs and I noticed you have to connect ground in between the two MOSFETs. I didn't really understand at the time how this could possibly work and I guess I chose to connect the N line through the MOSFETs instead of the L line because of this. (I added some images to make myself clear)
    I get your point though, and a solution could be to just reverse the wires inside the smart plug. The colors of the wires on my schematic are "imaginairy" you could connect the actual physical wires to the input connector however you would like.

    7x7sj.png0noJE.pngp157-f1.gif