Introduction: Automatic Light Switch

You’ve tried everything. You’ve tried throwing socks, you’ve tried reaching extra far, you’ve even tried activating your latent psychic powers, yet the light switch refuses to budge. Of course, you could just get up off your bed and walk all the way across the room, but that would be too much effort for a feeble college student such as yourself. No, what we need right now is a convoluted contraption to turn the switch off from across the room, and with a little bit of coding, you can finally turn that switch on and off from your bed.

What we have come up with here is a mechanical switch that is easy to put together, easily removed, and does not require any modification of the wiring of the actual light switch, which makes it perfect for a college dorm room. Additionally, it can be made partially from parts found on eBay, and parts found in a typical dorm room. This means it does not require any additional tools such as a 3D printer or laser cutter, and therefore requires even less effort on your part! Although this may seem like it requires actual time and effort to put the whole contraption together, this will totally be totally worth it when with the push of a button or the flick of a switch, you can turn your lights off from across the room.

Materials

We were able to rent all of the electronic parts we needed for free from our university, but if you were to buy the exact parts we used in order to replicate this design, it would be quite expensive. There are much cheaper alternatives available for the cost-conscious college student. The prices listed are the average prices found after some online research.

Electronic Parts:

Arduino

We used the Arduino Uno, which can be bought online for around $25. While there are cheaper Arduino boards available, such as the Pro mini for $10, the Uno is recommended as the best board for beginners with electronics and coding. If you decide to try a different board, keep in mind that they will likely have a different programming interface, instead of the standard USB connection.

Servo

We used the Hitec HS-645MG Servo which costs about $30. There are a wide range of servos available at a much cheaper price that will do the same job as the one we used. A couple of good websites to browse servos are hobbyking and servocity. You can find a similarly sized servo from Hitec for $8 (HS-311). The third picture above depicts a servo motor from four angles so you can see approximately what the motor you get should look like.

Motor Shield (Not required, Cost: $20)

The Motor Shield made it easy for us to safely connect the servo to the Arduino without any extra wiring. The Arduino Uno has a 5V regulator, so you can connect the servo directly to the Arduino as long as 5V is within the servo's operating range. If you choose not to buy the motor shield, you will need some jumper wires which can be bought in large packs for a couple of dollars. You can find many guides on how to connect a servo to an arduino with a quick google search.

Long USB cable ($4) and USB Type A to Type B adapter ($2)

This is what will be used to program and control the Arduino from your computer. The USB cable should be long enough to reach from your bed to the light switch.

Other Materials:

  • Any kind of tape
  • Two-sided adhesive stickers
  • A popsicle stick
  • A computer

A rough estimate of the cost for this project would be $40. This includes the Arduino Uno because it is the easiest to work with, but does not include the motor shield. The cost for the other materials was not included because many students likely already have these materials around their dorm. While the cost for this project may seem high, keep in mind that you can re-purpose all of the electronic parts for use in future projects once you no longer need them for this light switching device. Cost was a factor in every part of this design, as we wanted to make a DIY that was accessible to many college students.

Step 1: Downloading the Arduino Program and Library to Your Computer

The first thing you must do is download the Arduino program to your computer from here. The program is completely free as well as the code, which is why we chose to use the Arduino. It is very easy to learn how to use as there are many online resources available.

Secondly, download the servo library from here. This library has to be put in a very specific place so that the Arduino program can locate it on your computer.

  • On an Apple or Windows computer
    • Go to Documents > Arduino > Libraries
    • If there is no Libraries folder, Right click > New Folder > Name folder “Libraries”
    • Libraries > Place the unzipped downloaded file in here, and rename it “Adafruit_MotorShield”
  • On a Linux computer
    • Go to /home/
    • Sketchbook > Libraries
    • If there is no Libraries folder, right click > New Folder > Name Folder "Libraries"
    • Libraries > Place the unzipped downloaded file in here, and rename it “Adafruit_MotorShield”

Step 2: Assembling and Programming Your Arduino

Assembling the brains of the project, the Arduino and motor, is the first and most crucial step. As shown above, attach the motor shield to the Arduino. This will arrange all of the circuitry for you, in terms of powering your motor. Next, attach your servo motor to the Servo 2 pins on the corner of your motor shield, as shown in the second picture.

Now, plug your Arduino into your computer using the cable provided. Next up is the coding aspect of this project, but don't fear, we've figured all the code out for you! (It's written in C++ if you are curious.) Before you can begin to code,you will be required to upload a program to your arduino that will cause the motor to turn a certain number of degrees every time you enter “1” into the console. Copy and paste this code into the Arduino window:

#include <AFMotor.h>
#include<Servo.h>

Servo light; int angle = 0; int onoff = 0; void setup() { Serial.begin (9600); Serial.println ("Enter 1 to toggle on/off"); light.attach (9); delay (1000); }

void loop() { if (angle <= 0) { angle = Serial.read(); } else { angle=0; if(onoff%2==0){ light.write (0); Serial.println ("off"); onoff++; } else { light.write (35); // this 35 value represents the angle the motor will turn, so you can change this Serial.println ("on"); onoff--; } } }

Step 3: Assembling Your Light Switcher

Now that you have finished setting up the Arduino, you may be relieved to find out that setting up this device is pretty simple! You have created the code to make the motor spin, all you need to do is make something that will hit your light switch. In order to do this, you simply need to extend the linear motor attachment you have been given, by taping half a popsicle stick to it. This ensures that the motor attachment will be able to push the switch in. Make sure you leave the hole in the middle of the motor attachment free of any tape so you can connect this piece to the servo. Connect the motor attachment to the servo motor as shown.

Step 4: Attaching Your Set-up to the Wall

For the push switch, you now need to attach both the servo motor and arduino board to the wall. We used these sticky strips to put each piece of equipment on the wall. There are several kinds of adhesive that you can use (two varieties are shown in the top picture). It doesn’t really matter where the arduino goes, as long as it’s close enough for the cord connecting it to the servo motor to reach. The servo, however, must be attached right next to the light switch so that the motor attachment lies directly overtop of the switch. In the bottom picture, we showed where we placed our sticky strips with respect to the light switch.

Step 5: Putting It All Together

Before you put the servo motor on the wall, make sure to run the code through it once, ensuring that your device has been set up properly and the popsicle stick is in the correct orientation. Finally, stick both your arduino and servo motor to the wall. One trick that helped us one was to put two little erasers in the space between the servo and the wall, to help counteract the force that the light switch exerts on the motor when it is being pressed down by the motor attachment. Any small object lying around your room will work here.

Next, run your USB extender cord all the way around your room. In order to avoid the cord causing any problems, you could use hooks and two-sided adhesive, to run the cord along your walls to the switch, or you could run the cord along the floor around the outside of your room. Keeping your computer close to your bed, you can now control the device using the code for the Arduino to rotate the motor, turning the lights on and off. Now, anytime you want to turn the lights off from your bed, simply send the code from your computer and voilà!

Step 6: Further Design Options

Depending on the setup of your dorm room and how comfortable you are with programming and technology, there are other options for how you can control the light switch from your bed.

One option is using a smartphone app called “Blynk” which controls the servo motor through your phone. Having and app on your phone means that you are not restricted to using the light switching device from your bed. As long as your phone is nearby and you are within range of the Arduino, you will be able to control the lights in your room. This option can be extremely convenient although it can take some time to set up, especially if you are unfamiliar with coding or with how Blynk works. Using Blynk requires an ethernet shield (similar in shape to the motor shield) to be plugged into the Arduino, allowing it to connect to the internet. This ethernet shield can cost somewhere around $20, so we decided against choosing this as our main option as it is less accessible. However, using Blynk eliminates the need for having wires running throughout your room, something that we think can be well worth the extra time it takes to set up the app on your phone. To guide you through this somewhat complicated task, there are many tutorials online, explaining how to use Blynk. A good one to follow is http://docs.blynk.cc which will walk you through all the steps.

Another way to modify this device is to repurpose a remote to control the Arduino and turn the motor. One of the advantages of this method is that it is less expensive and easier to set up than the app. Although using this method would also require programming and wiring to ensure the remote is connected to the Arduino properly. This method makes it easy to control the light switch from anywhere in the room by pushing the buttons on the remote, however, it requires extra parts for your Arduino such as the Raspberry Pi Infrared Remote Control Ir Receiver Module DIY Kit, which can be found on Amazon for about $9. It also requires a bit more circuitry, but again, since the Arduino is so commonly used, there are plenty of other tutorials to be found online.

We hope this tutorial was helpful, and that you learned a little bit from it as well. Although setting up this device can take a little bit of time and money, just think of how nice it will be to turn off the lights from the comfort of your own bed. Happy light switching!

Dorm Hacks Contest 2016

Participated in the
Dorm Hacks Contest 2016