Plug It - Open Source Smart Plug

37,415

302

23

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

    • Fruits and Veggies Speed Challenge

      Fruits and Veggies Speed Challenge
    • Digital Fabrication Student Design Challenge

      Digital Fabrication Student Design Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest

    23 Comments

    0
    nqtronix
    nqtronix

    18 hours 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

    2 days ago

    Briljant ontwerp! applaus!

    0
    AndrewHoover
    AndrewHoover

    3 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

    5 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 3 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 3 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 4 days ago

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

    0
    antonio00121
    antonio00121

    4 days ago

    Well done, This is an amazing project!

    0
    MichaelKlos
    MichaelKlos

    Question 10 days ago on Step 14

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

    0
    Razanur
    Razanur

    Reply 4 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

    5 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 5 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 4 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 4 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

    4 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

    5 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 5 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
    0
    mopowah.
    mopowah.

    5 days ago on Step 13

    The project is very ambitious I respect that even though it is overly excessive for a smart plug in the amount of hardware being used. A simple ESP32 would accomplish all of what you are doing no need for a raspberry pi heck I've done the same with the first iteration of the esp8266 nodemcu however there was the issue of NO HTTPS which is why I suggest the esp32. ESPBASIC and ANNEX were fun ways to handle these types of things I didn't quite like LUA as much as you couldn't fully utilize things in the same manner giving incorrect results sometimes with really no workaround. May have changed with LUA however I stopped using non UL certified devices mainly due to insurance reasons the most I will use the cheap plugs for is a lamp or something along that line due to the nature of the fact I know that they are unsafe for most appliances. And the materials used are often not safe either.

    Don't take this the wrong way I love the project I would make it myself and have years ago but with the proper protections in place such as a 8A Push button breaker to be sure power does not exceed 8A for my 10A application this way people don't use it on their space heater etc. As it simply trips if you try to hook up Air Conditioners or Space heaters to it.

    I had purchased and used some dangerous dimmer variations that got far far too hot without proper heat relief as well. LED lights came out at about that time many of them were not dimmable. Oddly there were a couple of lights that could handle the dimming just fine even though they were not dimmable I learned but I also learned it drastically shorted the life of the LED light. Which leads me to a conclusion about LED lights even if you don't plan on dimming lights use dimmable lights they seem to hold up better in my experience.

    The design is neat but a sure fire hazard. The Case is built from non fire retardant plastic and it is 3D printed. The plug is not suitable for main applications people would use it for which would be heating and cooling. There is not thick enough traces or holes where there need to be holes etc in the PCB but even more important you have a relay that is cheaply made and will stick and catch fire with a rating of only 10A of power. What you have built is good for a homework exercise or a beta version to only use under supervision. What you will soon learn is the limits of this device and the fire hazard you are subjecting yourself to. Also an ESP32 can already do all of this don't understand the reasoning for the raspberry pi it just makes this device more expensive. SONOFF and many other plugs are fire hazards just like this plug people will not use these plugs as intended because most people do not understand power and limitations of electrical devices. Look to UL and ETL products for some pointers about the only NON-UL Certified equipment I've seen that is safe for consumption was NEXTEVO. But he had a well designed dimmer used specifically as a separate device. Use some of his designs possibly for PCB and circuits etc... ALWAYS use an expensive relay capable of 15A minimum but if you can use one that supports 20A for window AC UNITS as it is one of the most common applications people want to use smart plugs for!

    0
    Thomas Huyghebaert
    Thomas Huyghebaert

    Reply 5 days ago

    I agree that the Raspberry Pi is somewhat unnesessary but this was a school project, and I was obligated to make use of a Raspberry Pi as a database server and webserver. The project was supposed to be a proof of concept. Most students even connected their sensors directly to the Raspberry Pi, so my ESP32 was an extra feature on my end just to make everything fit in a small housing. All my smart plugs (ESP32's) connect to the Raspberry Pi via Bluetooth.

    Most cheap dimmers are built around a TRIAC, those are leading edge dimmers with a small dimming range and very steep rising signal edges. That can generate all kinds of interference and can in fact shorten the lifespan of your devices. My smart plug however, has a trailing edge dimmer that consists of two MOSFETs. This type of dimmer has a way bigger dimming range and no steep rising edges, wich in return extends the lifespan of your devices. To be honest, in my experience my dimmer still generates a lot of interference but it was worth the try I guess. Both the MOSFETs have a heatsink attached to them to make sure they don't overheat.

    I am aware that everything would break if you would attach a huge load like a heater to the smart plug. The "weakest link" is the current sensor, wich is limited to 5A. This equates to 1150W max. (ignoring phase shift, distortion, etc.) and I have put in the description that the smart plug is limited to 1000W just to be "on the safe side". (I tested the smart plug with a 750W load multiple times and everything seemed fine.)

    I had to create this instructable as a school assignment and I didn't expect it to blow up like this. It's certainly not my intention to endanger people with my project, so I put some extra safety warnings in the description. Anyway, thanks for your feedback I really appreciate it!
    MINI-T-LED-125W-02.JPG