IoT devices are rapidly becoming more and more popular, so why don't you learn and create your own IoT devices out of cheap materials and hard work to do things you couldn't before?
My names Szehuai and I always find myself about to fall asleep, but waking up because my lights are still on. Of course, I could get out of bed, stand up, release all of the warmth I’ve accumulated, exercise my legs, and turn the light off, but that’s too difficult. Thus, I created this guide to help you design a mount capable of fitting over your existing light switch to do the pressing for you. Since no one ever leaves their phones nowadays, whats better than being able to control your IoT device with a free app? This mount will forever change your life by allowing you to turn your lights on and off with your phone, taking your home one step to being smarter.
This is my very first legitamate instructable as well as my first legitamate instructable contest submission so it would mean a great deal if you voted for me if you thought this was an insanely cool project. (If someone can tell me how to delete the bottle spinner thing I randomly submitted for fun years ago, that would be great)
Lets get started!
Step 1: Specific Challenges and Safety Issues
This project is pretty much plug and go. I’ll be providing step by step instructions from 0-100%. The only difficulties that exist would be the acquisition of materials and components which I've provided alternative methods for incase you don't have access to them. Other than that, it’s just like Lego, just piece it all together.
Step 2: Components Required
All of these are purchasable online
· NodeMCU ESP8266-12E V1.0
· Servo SG90
· Microusb cable
-Optional, you can definitely run this off a wall socket buy plugging the micro-usb cable into an adapter
· Acrylic 3mm
-The thickness only matters when you're designing your acrylic mount and you need to add the thickness of the acrylic to certain dimensions, I personally think 3mm is perfect as its not too thick/thin and white looks the cleanest
· Arduino IDE
· Blynk app
· Adobe Illustrator
· Laser cutter (If you do not have access to a laser cutter, you could find local FabLabs or Makerspaces and ask them to do it for you)
· Screwdriver (For the screw to secure the servo arm to the servo)
· Flathead screwdriver (For lifting the plastic clip that holds the female servo pins in their plastic housing)
Step 3: Measuring Dimensions for Acrylic Mount
Now we need to tailor an acrylic cover over our existing light switch so it can house the servos that would turn our light on and off.
· Take the plastic shell panel of the light switch off
· Trace the outside of plastic case and fit a box over it, if the edges of the shell are curved (like mine)
· Obtain the Width(x) Depth(y) and Height(z)
· Depending on the thickness of your material, add the thickness (mine was 0.3cm) to all 3 values.
· The height of the box is tricky, you need measure the distance like I did in the side view picture I’ve attached and make sure that the servo is close as possible without obstructing the switch itself from turning on and off.
· The height of the servo, according to my measurement is 1.2cm, you would add this value to the Height of your box dimension
· THE WIDTH DEPTH HEIGHT OF THE BOX IS THE OUTER DIMENSION
· Go to (https://boxdesigner.connectionlab.org/) and create a box using the X,Y,Z values you obtained
· Under advanced option, adjust the notch length depending on the thickness of your material, may take a couple of tries but I set mine as 0.75 which is a pretty tight fit which required a hammer to knock the pieces into place
· Also select “No, don’t include a cover piece”
· Open this pdf in Adobe Illustrator
· Open the Light Switch file I’ve attached and fit the outlines for the hole and servo placement for your own acrylic cover, I’ve also provided the one I used.
The hole that supposed to allow the wires to come out became a gap when I pressed too hard and the thin acrylic snapped, honestly I think this might be much better cause then it makes it easier to fit the acrylic pieces together as well. But the bar was only thin because the height of my cover was quite short.
It might take a couple of tries to get the cover to snap together perfectly but remember its WORTH IT!
Step 4: Installing Arduino IDE and ESP8266 Library
First, you need to download the Arduino IDE(https://www.arduino.cc/en/Main/Software). Arduino is completely free as well as the code, which is why we chose to use the Arduino. It is very easy to learn as there are many online resources available.
Second, you need to download the drivers for the ESP8266.
After downloading the Arduino IDE navigate to
1. File tab and then click on Preferences.
2. In the additional Boards Manager URLs add the following link (http://arduino.esp8266.com/stable/package_esp8266com_index.json)
3. Click OK and then navigate to
4. Tools - Board - Boards Manager
5. In the search field type esp8266 > click the esp8266 by ESP8266 Community - Click Install
6. Go back to Tools – Board then select NodeMCU ESP8266-12E V1.0
Now you have setup the Arduino IDE to work along with the NodeMCU.
Step 5: Wiring
Because I wanted to eliminate the need for a bread board as well as extra wires, I directly altered the order of the female pins housed in the servo pin casing by using the flathead screw driver to lift the flap open and rearranging the wires
If you labelled your servos like how I labelled them(Left and Right)
You need to modify the Left servo by changing its
COMMAND,POWER,GND ---> COMMAND,GND,POWER
Orange, Red, Brown ---> Orange, Brown, Red
Now connect your servos, the sg90 are
Orange - Red - Brown servos:
Orange wire connects to Digital pin D4(Right servo) OR TX(Left servo) refer to picture (Command)
Red wire connects to 3V pin (Power)
Brown wire connects to G pin (GND)
Step 6: BLYNK App Setup on Phone
Search Blynk in your app store
· Open the app and click create a New Project and select NodeMCU on the dropdown.
· An AUTH token will be sent to your registered email, note this down, you will need to copy and paste the token into the Arduino code.
· Tap on the blank screen and add a SLIDER widget on the screen.
· Tap on the Widget, select Virtual PIN 1(Or the pin you want, it doesn’t matter, what matters is it corresponds to your code) and Start value must be 0 and End Value must be 180 (Depending on the servo, a value of 0 might make the servo grind and break, tweak it until it doesn’t, mine was 10-180)
· Tap on the screen and add a BUTTON widget on the screen.
· Tap on the Widget, ALSO select Virtual PIN 1(make sure the button corresponds with the pin the slider has been set to as well) and ALSO CHANGE THE MODE TO SWITCH(IMPORTANT)
· YOU WILL MAKE 2 SLIDER AND 2 BUTTON WIDGETS, ONE OF EACH FOR EACH SERVO
Revisit HERE once you've assembled the entire device
Once you’ve assembled the entire mount, adjust the slider to find the position values that presses hard enough so the light gets clicked, these will be the values you will put into your Button widget
Step 7: Uploading Final Code
We only need to add our AUTH ID(noted above), Wifi SSID and Password in the code and upload it to NodeMCU using Arduino IDE. Download the "Light_Switch_Code" and open it using Arduino IDE, it will ask if you create a folder it so just click ok.
For the code, I've included an explanation of each line in the comments, if you do happen to have any more tips or questions, please feel free to ask.
Make sure to select the correct port when you're uploading your code if you're getting
"error: espcomm_open failed"
Once you're done, you can check to see if its connected by looking at Blynk's status(board icon). It will tell you whether its online or offline.
Step 8: Fixing the Servo Arm in Place
After your code has been uploaded and the board is online, the code will run and the servos will both be set to a position of 90, you will need to use the screwdriver and secure the servo arms like in the picture, parallel with the body of the servo. Doing this will allow you to monitor your values and tweak accordingly.
Step 9: Assembling the Components
Assembling the entire thing:
· Once you've laser cut your acrylic, assemble it so it resembles a cover, pretty straight forward right!
· Follow the engraved lines and make sure you orient your servos correctly so the sides of the servo aligns with the engraved lines.
· Get 6 "droplets" of blu tack and follow the images, make sure to rip off the stickers "Tower Pro"
· You can also use blu tack or cable ties or any method of cable manage to sort your cables out, it really doesn't matter as long as it doesn't obstruct the servo.
· Apply 2 lines of blu tack on either sides so it sticks to the wall and the actual light switch to enhance the grip
The images I've attached show how I chose to do mine.
FOR POWER, I don't reckon this taking up too much power at all as I've included detach functions so the servos aren't always trying to maintain their positions. You can plug your micro-usb cable either into a wall socket adapter OR powerbank.
Step 10: Reflection
This project taught me a lot about the capability of the ESP8266 NodeMCU or just wifi capable boards in order to create IoT devices. The skills I’ve learnt dealing with this lends itself into other IoT projects I wish to pursue(hydration tracker, stay tuned). I’ve learned Arduino before with the Arduino Uno but the ability to control my device with an app over wifi on my phone?!?!?! Huge upgrade. It’s amazing that this project seemed so simple in the end, it brings me a great deal of pride to provide a short cut for all of you.
Something that was surprisingly challenging for me was creating the acrylic cover… Yes I know, incompetent. At first, I was trying to measure the distances and dimensions and didn’t realize I could just pop the cover off until one day I popped it off by accident. I also spent a great deal of time trying to CREATE the notches that would allow my acrylic cover to INTERLOCK. It was a stupidly tedious process I was already invested in until I found out about online box designers that just do all the work for you (thank me later). I realized that someone made the box designer to eliminate the tedious work for others and I was just too stubborn to accept the fact that I was taking the long way. I was just so close… Eventually, I used the box designer, did a couple of tries, added elements, took elements and boom, it looked worked like a charm.
Even though I’ve achieved the intended purpose for my device, if I were to do this project differently, actually expand on this project, I would like to explore ways reorient servo positions to accommodate different types of switches. Switches with 1 big button, switches with 3 slim buttons, switches with different button tilts etc. But, I just wished I found out about the box designer sooner and spent the 5 minutes to figure out how it worked.
Participated in the
Arduino Contest 2019