loading

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.

<p>Nice.<br>I wonder if you could design something that eliminates the mechanical and can be wired into the light circuit. I know that you may not have access to the breaker switch in a dorm (which, if you're careful, and a little daring is not insurmountable).<br><br></p>
<p>Congratulations on winning first prize! This is really cool instructable! Well Deserved!</p>
<p>This Instructable is fantastic! Hope you do well in the Dorm Hacks contest, from a fellow student (and her boyfriend, who says this is &quot;lit, fam&quot;).</p>
<p>I am a troop leader for a local girl scout troop (15 8-10 year old). Would it be possible to order kits of this project (maybe 20 or so)? </p>
<p>It will be possible but I feel like this is a bit complex of a project for 8-10 age group. Although it depends on their skills since it involves soldering , programming etc. </p>
<p> we have worked on coding with them previously. The soldering would be new, but one of our goals is to constantly expose them to things they thought were out of their :)</p><p>You have already done the leg work on programming it would be an exercise in following your model more than figuring the coding on their own. Great project. Let know on the kits.</p>
<p>In that case this could be an interesting project. How about I work on making it a bit easier and child friendly as well as a better functioning device. And get back to you. Is there a time constraint for your requirement? </p>
<p>Very clever Anthony. It's enjoyable to read your articles even if I don't build the particular item.</p><p>Kevin in CT</p>
<p>Reading the comments below Babbage quote comes to mind :&quot;Propose to an Englishman any principle, or any instrument, however admirable, and you will observe that the whole effort of the English mind is directed to find a difficulty, a defect, or an impossibility in it. If you speak to him of a machine for peeling a potato, he will pronounce it impossible: if you peel a potato with it before his eyes, he will declare it useless, because it will not slice a pineapple. Impart the same principle or show the same machine to an American or to one of our Colonists, and you will observe that the whole effort of his mind is to find some new application of the principle, some new use for the instrument.&quot;</p><p>As for your efforts you get a A plus .... and&quot; dont go gentle into the good night &quot;</p><p>Leave the naysayers behind and carry on making </p>
<p>Projects on the net are co-operative. It would be one thing if the commenter was obnoxious, but the it is the right thing to do if an improvement or a danger is seen. Projects are displayed for kudos, pride, but most of all to bring together the workings of many minds to provide improvements to the original. </p><p><em>Criticism</em> is the practice of judging the merits and faults of something. Sometimes castigation is camouflaged as criticism, but it is almost always easy to spot. The falsity does rebound. </p>
<p>I'm wondering way you need a Arduino board - you can archive the same functionality only with ESP8266 board. </p><p>Maybe I'm miss somthing.</p>
Exactly. And... the ESP can be programmed in python as well :)
<p>I'm wondering the same thing.</p>
<p>Nice work, if you want this as start for more. For only on/off you can get </p><p><a href="https://www.itead.cc/sonoff-wifi-wireless-switch.html" rel="nofollow">https://www.itead.cc/sonoff-wifi-wireless-switch.h...</a></p>
<p>Hey I love your enthusiasm. Keep it going.</p><p>The design is great, like everything there is always room for improvement.</p><p>I think what you have created is perfect for the scenario you have designed it for...</p>
How long does the battery last?
<p>Currently at about three days but working on power efficiency. </p>
<p>3 days with some usage, I assume. How long just on standby? </p>
How about solar-powered rechargeable batteries like the one in your smartphone Or Solar battery pack.
<p>Not a bad idea. I am trying to reduce power consumption right now but i can look into the idea of solar power. Thanks</p>
<p>A couple ideas you might want to play with, add a solar panel to recharge the battery, you can find small 5 volt cells that probably wouldn't ever get enough power to over charge your battery. And the other idea, write a program that would turn the light on when you get home, and turn it off when you go out of range. Great project, I enjoyed reading it, and will think about building something like that. Never would have thought of using a servo to flip the light switch! Well Done :) </p>
<p>Thanks. I am working on that. Will keep posting updates. </p>
<p>Hi, can you elaborate how to open those CAD files with SketchUp?</p>
<p>I am not if they can but you can use solidworks to modify the files and any stl viewer to view the 3d files. </p>
<p>I do like the idea of building this project to get more experience with (really basic) IoT stuff, but I do also subscribe to the KISS method and in that light, this seems way too expensive and complicated for a light switch. </p><p>I completely understand using a motor/servo to flip your switch. I also understand wanting a wireless application. However... WIFI? I don't even like the idea of Bluetooth for something like this. I really feel like a wireless light switch could be done much more simply with an infrared remote.</p><p>... unless of course you were intending to do more with say a smartphone app or something. Hook it to a smartphone alarm so that the light switches on in the morning or something. </p><p>I guess what I'm trying to say is I don't see a justification for a full fledged WIFI interface here. I think it's a good idea to have strong supporting arguments for using your components. By what you wrote above, I don't see that you *need* WIFI. We had to justify every component we put into our senior projects in college.</p>
<p>I guess I'm kind of thinking why not two (2) PICAXE 08M2, (1) IR emitter, (1) IR receiver, and (1) servo and you're done.</p>
<p>Because I am trying to build an interconnected home automation system. This was my first attempt at a single node of that system. It will be improved. Thanks for you comments, You guys keep me thinking. :P</p>
<p>I am working on a BLE v2. I understand that Wifi is not vital. :P</p>
<p>Excellent solutions given your constraints. Clapper and other remote controllers wouldn't work in these circumstances.Plus the possibility of extensions...</p>
<p>Thanks. My goal is to build an entire home automation system. And this is the first part of that. </p>
<p>Why go all through this to turn off a light switch...there is a gadget that they sell just by clapping your hands, the light goes off...and its cheaper than $20.</p>
<p>Well first because this is my first device in what will become a network of interconnected devices in a home automation network. Clapp switch wont work with that. Secondly it also acts as a basis for other devices. I can use the same circuit for other sensors. Hence the knowledge gained on this can be applied to other devices. Lastly our dorms are loud. Clap switch would go crazy. Regard less i appreciate your comments. You guys keep me thinking that is what i am doing the best way to do it. </p>
The part that Anthony needs answered is that it is a switch operator. It goes over an existing light switch (they're not going to be allowed to electrically modify the building).
Oh, and this is a mechanical actuator. The Clapper, I assume, plugs into an outlet, and the electrical device plugs into the Clapper.
<p>This project may just be a light switch but what else can you do with this?</p><p>What else can you extrapolate this to.</p><p>light switch today, tomorrow set the stove temperature with little modification!</p>
<p>Exactly. I am trying to build a home automation system in the long run. This is the first step so I am experimenting with different communication methods. I am trying to keep it simple yet open to future expansions. </p>
<p>He's triggering the switch with his phone so he can turn something on and off from a distance not in the same room. Porch light, pet feeder ...</p>
<p>you dont understand the whole purpose of 'Instructables.com' do you? You can BUY anything or you can learn to build it yourself.</p>
<p>I concur</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/Ny8-G8EoWOw" width="500"></iframe></p>
<p>This is really quite cool! I'm going to add this to my list of todo's :-)</p>
<p>Thank you :P</p>
<p>Awesome case design! Nice project, you will make a great engineer.</p><p>Build_it_Bob</p>
<p>Thank you so much. Appreciate it. :P</p>
<p>Switchmate's are terribly expensive in Canada for what they do. This is awesome!</p><p>My gas fireplace is controlled by a switch; and the remote control packages for that are like $120+, and they're only IR controlled. There is no power at the switch, so using one of the other cheaper IR things isn't possible either. I like wifi, even if it uses more power. But I don't have a 3d printer, nor do I want one (yet?), so how can I can I buy or get a body printed? I can buy the rest of the stuff off of eBay, right?</p>
<p>You could probably buy a plastic project box and modify it (cut out a slot for the switch lever) that would as well as the 3D printed one.</p>
<p>I have some suggestions, because this is amazing that you've put this much time into it. Can you 3D design a plate that replaces home light switch covers (using the standard screw location (or will the weight not hold if done that way)? Also, I search for &quot;18650 Battery&quot; and I can't find a $2 version anywhere ... batteries are usually the most expensive (I did read why you couldn't tap into the power in the outlet, but can you make a design that can use the power from the 12v light switch ... meaning let me know how many resistors, capacitors, etc to wire together ... and maybe the best method), so I can tap into that power supply? If so, please please respond to this message so I receive an email. Thank you so much for pursuing your idea (it's amazing), keep up the great work Bjkayani. :)</p>
<p>Keeping this design you can just keep it plugged into a charger but you can replace the battery with a 5v adapter</p>
<p>Oh ya, that sounds perfect ... thanks :)</p>
<p>You lost me after the second sentence...</p>
thats impressive. good job

About This Instructable

93,143views

537favorites

License:

Bio: I am an 19 year old DIY ist and Tinkerer with a deep interest in the field of robotics, electronic and cooking. I am skilled ... More »
More by bjkayani:Bed Table from a Pallet Laser Cut Door Mat  Switchifi : Wifi Enabled Switch under $20 
Add instructable to: