Introduction: Switchifi : Wifi Enabled Switch Under $20

About: I am a 21 year old DIY ist and Tinkerer with a deep interest in the field of robotics, electronic and cooking. I am skilled in wood and metal work as well. I work in my basement workshop and i am mostly scratc…

Welcome all to my 30th instructable. I am so happy to have come this far. As some of you might know I am in Case Western Reserve University now. I am learning new things every day and making projects frequently. This is something I have been working on using some of the new skills I have learned.

So I think a little bit of back story is important for you guys to understand this project. My roommate and I live in the college dorm and one problem we face is turning the lights off at night when both of us are in our comfy beds and neither wants to get out. Me being the to-be engineer wanted to solve the problem using some device that lets us control the lights remotely and allows us to become even more lazy because lets admit it, that is an engineers job description. Secondly we all know that college is expensive so I wasn't ready to put in $40+ for a ready made device. Lastly I LOVE MAKING so I decided to make a device that controls the lights remotely over Wifi and can be controlled by a smartphone. I call it 'Switchifi' and it will cost less than $20.

Please support me by subscribing and voting for me in the contests. It would really encourage me to keep bringing more creative ibles. Thanks.

Step 1: Design Overview

The design of Switchifi is inspired by the company that makes similar devices called Switchmate. Switchifi works by sticking onto the existing switch panel and using a sliding piece moved using a servo to physically switch the light lever but they don't have a Wifi controlled product yet and their products are expensive. Another option is to use a relay. I agree it would be easier just to hard wire into the panel using a relay and it would spare me from all the elaborate design but I wasn't allowed to hack into the light panel. Plus this makes my device easily transferable and more safe to make for makers who are inexperienced with mains voltage or are living in a dorm or rental space. Switchifi also has a physical switch on it to control the light directly. I will explain each part of the design in detail in the following steps.

Step 2: Parts Needed

You will need the following parts:

  1. 3D Printed Body $10
  2. Arduino Nano $2.5
  3. Micro USB 18650 Charger $0.5
  4. ESP8266 Wifi Module $2
  5. 18650 Battery $2
  6. DC-DC Step Up Power Module $0.5
  7. 9G Servo $1.5
  8. Resistors (10k, 2k, 1k)
  9. Hookup Wire
  10. Toggle Switch
  11. 3.3v Voltage Regulator

Total ~ $20

You will need the following tools:

  1. 3D Printer
  2. Soldering Iron
  3. Wire Cutter
  4. Screw Driver

Step 3: 3D Modeling

This was the most time consuming step for me as I was learning to use the CAD software while making the body. I used Solid Works for the entire design. I spent a lot of time making sure the components would fit perfectly. My goal was the design to be so perfect that I didn't have to sand down anything and it would all just fit together. If you are replicating my design exactly then you wont need to delve into the design since I have attached the 3D printable file but if you want to modify my design to fit your own needs, I have also attached the solid works part files.

The body is basically designed to have everything fit in with minimal screws or glue. Its divided into three parts. The main body piece is which houses all of the components. The slider piece is what slides to switch the lever. And the back panel encloses every thing.

The main body has compartment for the battery. It has small protrusions to secure the servo and electrical boards. It has guide rails in which the slide piece slides. The back panel is secured using four screws.

This was my first print so I did make some minor errors in few of the dimensions but I will be fixing that for you guys. Overall I was very happy with how well everything assembled and fit together. The long hours spent on designing were worth it when it came together smoothly.

Step 4: 3D Printing

This step was pretty straight forward. I used a Makerbot Replicator 2 to print out all the body parts. It took me about 3 hours to print all three. I wont be going into detail about 3D printing since there are plenty other ibles that explain the process. I used the basic settings and it turned out pretty well. I had a honeycomb infill of 10%.

This is the link to the instructables class for 3D Printing. If you don't know the how to of 3D printing, you can take this class. Its free and great way to master the art.

I wanted a smooth outer surface so i sanded the exterior faces. I started with 120 grit and then moved up to 220 grit. I finished off with a wet abrasive sponge. It didn't turn out perfect but I was satisfied and it looks way better. You might also need to drill into the four holes for your sized screws.

Step 5: Circuit Schematic

The schematic is pretty straight forward. If you just follow it exactly, you should be good to go. But I will still explain it briefly so that you guys don't have any problems.

The battery is attached to the charging circuit and the input of the power module. There is a switch on the negative line to the power module to turn the device on and off. Positive line from the battery is also connected to the arduino's A0 for battery measurement. The output of the power module is connected to the arduino's power in, servo, toggle switch and the 3.3v regulator. The output of the 3.3v regulator is connected to the power of the ESP8266. The data lines of the ESP8266 are connected to the D10 and D11 of arduino using a resistor voltage divider for data going into the ESP8266. The toggle switch is connected to D2 and grounded using a resistor. The servo's data line is is connected to D9.

Now that I have spilled so much random information you might feel like this is too complex but if you look at the schematic, you will notice that its not complicated at all.

The ESP8266 works on 3.3v hence the regulator. The arduino cant supply enough power on its 3.3v out hence a separate regulator is required. A voltage divider is needed to reduce the data logic level from 5 to 3.3v. We only one since the arduino can detect logic input of 3.3v.

Step 6: Building the Circuit

This took me a while to get right. Its not that hard but you have to follow the schematic exactly. Just keep a track of your connections. In all honesty, I had to this twice since I used low quality wires on my first attempt and made haphazard connections. So the pictures are of my first attempt. I didn't take pictures on my second attempt.

Start with all the power wires. When you wire all the power lines, test to see if everything turns on as expected. Important: Before connecting the power out to any component, use a multi-meter to check the voltage out of the power module and adjust it to almost 5.5v. I did this while connected to the arduino and accidentally fried it. The pot is not linear so its varies a lot with slight movements around a certain resistance. Then wire the wires from the servo, ESP8266 and the toggle switch. Lastly make the connections to the arduino. Check each module to see if you connected it right using examples from Arduino IDE.

Step 7: Merging the Body and the Circuit

This is the most fun step as things finally start to come together in this step. Its pretty straight forward. You just have to put in all the part in their desired places.

Start with the batteries. I wrapped it with electrical tape to fit in just right. Then hot glue the charging board followed by the power module. I used tape on the back of the board in case I had to remove it. Hot glue the 3.3v regulator and arduino. Insert the ESP8266 in its slot.

For the servo you would have to modify its arm. Cut the arm short so that is doesn't collide with the back panel. Then sand it thin so that it can turn at a greater angle inside the slot of the slider piece. Move the servo to the center position. You can see this by observing the notch on the largest gear inside the gearbox. Mount the arm so that its in the center when placed side ways. Glue the servo in and lastly mount the toggle switch.

I had a bit trouble due to some minor sanding I had to do but I will fix that for you guys so you dont have to worry. Things will fit just right for you guys.

Step 8: Servo Position Testing

Before we can get into coding, we have to determine the angle of the servo to use. It might require some trial and error but its not too hard to do. Just use the simple servo code attached to figure out what two values you need to make the slider piece be in an 'on' or 'off' position. For me the values were 140 and 60 but they may vary for you so I wont hard code it.

Step 9: Coding

I think this is the right time to tell you that I will be using the Blynk platform to connect with my phone. Blynk is an app that makes it very easy to control IoT. They have a set of stable libraries supporting a wide array of developmental platforms.

My code is mostly the Blynk library with some additions for control. I wont be explaining my code here as I have explained it in the code file itself.

But just some notes. I am using the Blynk library as the main controlling structure. The communication with ESP8266 is being done with software serial. The servo is being run using pwmservo library as the normal servo library interfered with the software serial. The inputs are being handles using interrupts. Debouncing for the toggle switch is also incorporated.

Step 10: Blynk Setup

Just follow the steps and you will be good to go.

  1. Download and install Blynk on your smartphone
  2. Create an account and login.
  3. Create a new project and select Arduino Nano as the board.
  4. Copy your token into your code.
  5. Add widgets by tapping anywhere on the screen
  6. Add the widgets as shown.
  7. Connect and enjoy

Step 11: Working

When you have everything done you should be able to connect you board to your local wifi. Once its connected you can connect Blynk on your smartphone. If all goes well, you should have control over the device. Tapping the button will change the position of the servo from on to off or vice versa. Toggling the momentary toggle switch will result in the same outcome. You can monitor the battery voltage from your app and charge it when it goes below 3.2 volts. Although the circuit is designed to run even if it goes down to 2.5 volts.

Step 12: Troubleshooting

Now there is a likely hood that your device will give you some troubles as it did give me lots of issues. Although I told you guys more or less everything I learned, I still know that these things dont work on the first try. This is not a simple project so there are many things that can go wrong. Go through the following steps to ensure everything is right.

  1. Double check all your connections and wiring against the schematic.
  2. Make sure the arduino, ESP8266 and servo are getting power and that the voltage is right.
  3. Check to see if you connected the tx rx of the ESP8266 correctly.
  4. Use the attached test code to see if the ESP8266 is responding. I not then there is something wrong with the ESP8266.

If you are still not able to figure out the problem then send me a message and I willl be more than happy to help you out.

Step 13: Stickers

Just because every thing is prettier with stickers, I printed out the logo and some labels to stick onto Switchifi. It just makes it look more professional and good looking.

Step 14: Conclusion and Credits

This was a very engaging project for me as it took me so much time to get it just right. After many failures came success and I am very happy with what I was able to accomplish. This is not the end though. I will keep working on improvements on the code and the design. I hope to perfect this device so that it can become as practical as possible.

This project would not have been possible without think[box]. Their facilities including the 3D printer and electrical equipment helped me build my circuits and photograph the process.

I hope you guys enjoyed my build. As always comments and improvements are always welcomed. If you guys have any questions of problems, please let me know and I will help you to the best of my abilities.

If you think I did a good job, please vote for me. It will encourage me to keep working to bring more interesting and innovative ibles.

Dorm Hacks Contest 2016

First Prize in the
Dorm Hacks Contest 2016

IoT Builders Contest

Third Prize in the
IoT Builders Contest

Circuits Contest 2016

Runner Up in the
Circuits Contest 2016